REM Starfield
*ESC OFF
*FLOAT64
ON ERROR OSCLI "REFRESH ON" : ERROR 0, REPORT$+" at line "+STR$ERL
REM
REM Prevent the program window from being resized by the user
REM
SYS "GetWindowLong", @hwnd%, -16 TO S%
SYS "SetWindowLong", @hwnd%, -16, S% AND NOT &50000
SYS "SetWindowPos", @hwnd%, 0, 0, 0, 0, 0, 32+7
REM
REM Setup a 640x512 display mode, and turn OFF the flashing cursor
REM
MODE 8
OFF
REM
REM Install and initialise GFXLIB and external modules
REM
INSTALL @lib$ + "GFXLIB2.BBC"
PROCInitGFXLIB( dispVars{}, 0 )
INSTALL @lib$ + "GFXLIB_modules\PlotScaleTintBlend.BBC" : PROCInitModule
InvalidateRect% = FNSYS_NameToAddress("InvalidateRect")
GetTickCount% = FNSYS_NameToAddress("GetTickCount")
SetWindowText% = FNSYS_NameToAddress("SetWindowText")
winTitle$ = "Psuedo-3D starfield"
SYS SetWindowText%, @hwnd%, winTitle$
numStars% = 100
maxStarDist% = 1000
DIM x%( numStars%-1 ), y%( numStars%-1 ), z%( numStars%-1 ), colour%( numStars%-1 )
maxStarSize% = 64
DIM starBmAddrTbl%( maxStarSize% )
starBm% = FNLoadBMP( @dir$ + "star_64x64_24bpp.BMP", 0 )
FOR I%=0 TO numStars%-1
x%( I% ) = -320+RND(640)
y%( I% ) = -256+RND(512)
z%( I% ) = RND(maxStarDist%)
colour%( I% ) = RND(&FFFFFF)
NEXT I%
D% = dispVars{}
P% = GFXLIB_PlotScaleTintBlend%
a# = maxStarSize% / maxStarDist%
b# = 255 / maxStarDist%
frames% = 0
*REFRESH OFF
SYS GetTickCount% TO time0%
REPEAT
SYS GFXLIB_Clr%, dispVars{}, 0
FOR I%=0 TO numStars%-1
c# = 680/z%(I%)
X% = 320 - c#*x%(I%)
Y% = 256 - c#*y%(I%)
S% = a#*(maxStarDist%-z%(I%))
SYS P%, D%, starBm%, 64, 64, S%, S%, X%-S%/2, Y%-S%/2, colour%(I%), 128, b#*(maxStarDist%-z%(I%))
REM. P% = GFXLIB_PlotScaleTintBlend%
z%(I%) -= 8
IF z%(I%) <= 0 THEN
x%(I%) = -320+RND(640)
y%(I%) = -256+RND(512)
z%(I%) = maxStarDist%
colour%(I%) = RND(&FFFFFF)
ENDIF
NEXT
PROCdisplay
SYS GetTickCount% TO time1%
IF time1%-time0%>=&3E8 THEN
SYS SetWindowText%, @hwnd%, winTitle$+" | "+STR$frames%+" fps"
SYS GetTickCount% TO time0%
frames% = 0
ENDIF
frames% += 1
UNTIL FALSE