'=========================================================================== ' Subject: INCOMING STARFIELD Date: 10-01-98 (21:46) ' Author: Leandro Pardini Code: QB, QBasic, PDS ' Origin: lpardini@cefex.com Packet: GRAPHICS.ABC '=========================================================================== '=================================================================== ' I'm working in my third game, a (some kind of) 3D shooter, and ' the first thing I completed is this starfield. It's REALLY fast, ' because I used NO FLOATING POINT OPERATIONS, just integers. The ' secret: instead of using a 320x200 field, I use a 3200x2000 field ' and then I integer-divide the number by 10 when I'm going to put ' it on screen. This will work in any screen mode, but I used ' SCREEN 7 so I can use PCOPY. For faster results, run it directly ' at DOS (Safe mode command prompt only, under Windows 95), because ' Windows slows it 10% on ALL the computers where I tested it. If ' you can improve this, or you have doubts or suggestions, please ' email me: lpardini@cefex.com. '=================================================================== '$STATIC DEFINT A-Z DECLARE SUB StarsUpdate () '==================== STARFIELD INITIALIZATION ===================== CONST StarsN = 99 DIM SHARED StarsI, StarsX(StarsN), StarsY(StarsN), StarsZ(StarsN) FOR StarsI = 0 TO StarsN StarsX(StarsI) = RND * 3200 StarsY(StarsI) = RND * 2000 NEXT StarsI '=================================================================== SCREEN 7, , 1, 0 ST# = TIMER WHILE INKEY$ = "" LINE (0, 0)-(319, 199), 0, BF CALL StarsUpdate PCOPY 1, 0 FR = FR + 1 WEND FI# = TIMER - ST# SCREEN 0 WIDTH 80 CLS PRINT "ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»" PRINT "º B E N C H M A R K º" PRINT "ÌÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ͹" PRINT USING "º Seconds elapsed: ####.# º"; FI# PRINT USING "º Frames shown: #####, º"; FR PRINT USING "º Average FPS: ###.## º"; FR / FI# PRINT "ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ" END SUB StarsUpdate FOR StarsI = 0 TO StarsN DiffsX = (StarsX(StarsI) - 1600) DiffsY = (StarsY(StarsI) - 1000) IF ABS(DiffsX) < 20 THEN DiffsX = 20 IF ABS(DiffsY) < 20 THEN DiffsY = 20 StarsX(StarsI) = StarsX(StarsI) + (DiffsX \ 20) StarsY(StarsI) = StarsY(StarsI) + (DiffsY \ 20) SELECT CASE ABS(DiffsX) + ABS(DiffsY) CASE IS < 600: StarsC = 8 CASE IS < 1200: StarsC = 7 CASE ELSE: StarsC = 15 END SELECT IF StarsX(StarsI) < 0 OR StarsX(StarsI) > 3200 OR StarsY(StarsI) < 0 OR StarsY(StarsI) > 2000 THEN StarsX(StarsI) = 1600 + (RND * 800) - 400 StarsY(StarsI) = 1000 + (RND * 800) - 400 ELSE PSET (StarsX(StarsI) \ 10, StarsY(StarsI) \ 10), StarsC END IF NEXT StarsI END SUB