starfield demo
Posted: Thu Apr 18, 2002 12:20 am
Code updated For 5.20+
Restored from previous forum. Originally posted by tex.
a starfiel for the fun
Restored from previous forum. Originally posted by tex.
a starfiel for the fun
Code: Select all
;-----------------------------------------
;---------- STARFIELD DEMO----------------
;-----------------------------------------
;-------- Blitz to purebasic--------------
;-----------------------------------------
MAX_STAR.w=5000
STAR_SPEED.b=6
#width=800
#height=600
Global Dim star_x.l(MAX_STAR)
Global Dim star_y.l(MAX_STAR)
Global Dim star_z.l(MAX_STAR)
If InitSprite() = 0
MessageRequester("Error", "Can't open DirectX 7 Or later", 0)
End
EndIf
If InitKeyboard() = 0
MessageRequester("Error","Can't open DirectX 7 Or later",0)
End
EndIf
If OpenScreen( #width,#height, 32, "Sprite")
Goto StartGame
Else
MessageRequester("Error", "Can't open screen !", 0)
EndIf
End
Procedure rnd(min.w,max.w)
a.w = max - Random (max-min)
ProcedureReturn a
EndProcedure
Procedure setup_stars()
For c.w=0 To 5000
star_x(c)= Rnd(-#width/2,#width/2) << 6
star_y(c)= Rnd(-#height/2,#height/2) << 6
star_z(c)=Rnd(2,255)
Next
ProcedureReturn value
EndProcedure
Procedure UpdateStar()
For c.w=0 To 5000
star_z(c)=star_z(c)- 4
If star_z(c)<=2
star_z(c)=255
EndIf
s_x.w=(star_x(c)/star_z(c))+(#width/2)
s_y.w=(star_y(c)/star_z(c))+(#height/2)
col.w=255-star_z(c)
FrontColor (RGB(col,col,col))
Box (s_x,s_y,3,3)
Next
ProcedureReturn value
EndProcedure
;-------------------------
; Game-LOOP
;-------------------------
StartGame:
setup_stars()
Repeat
FlipBuffers()
ClearScreen(RGB(0,0,0))
StartDrawing(ScreenOutput()) ; Start 2D-drawing
FrontColor(RGB(255,255,0))
updatestar()
StopDrawing() ; End 2D-Drawing
ExamineKeyboard()
If KeyboardPushed(#PB_Key_Escape) ; If ESCAPE is pressed: END
End
EndIf
ForEver