; Use left mouse button... note lack of frame-limiting code!
Type Timer
Field start
Field timeOut
End Type
Function SetTimer.Timer (timeOut)
t.Timer = New Timer
tstart = MilliSecs ()
t imeOut = tstart + timeOut
Return t
End Function
Function TimeOut (test.Timer)
If test <> Null
If test imeOut < MilliSecs ()
Delete test
Return 1
EndIf
EndIf
End Function
Graphics3D 640, 480
SetBuffer BackBuffer ()
SeedRnd (MilliSecs ())
Global piv = CreatePivot ()
cam = CreateCamera (piv)
PositionEntity cam, 0, 0.1, -5
PointEntity cam, piv
CameraZoom cam, 5
AmbientLight 32, 32, 32
light = CreateLight ()
PositionEntity light, -5, 0, -5
Global cube = CreateCube ()
HideEntity cube
Type cubes
Field entity
Field alpha#
Field incdec
Field kill
Field zacc#
End Type
Global spawn = 4000
Global newCube.Timer = SetTimer (spawn)
Global alpha.Timer = SetTimer (50)
Repeat
If KeyHit (17) Then w = 1 - w: WireFrame w
UpdateGame ()
UpdateWorld
RenderWorld
Flip
Until KeyHit (1)
End
Function UpdateGame ()
TurnEntity piv, 0, 0, 0.1
For a.cubes = Each cubes
TurnEntity aentity, azacc, 2, azacc
TranslateEntity aentity, 0, 0, azacc * (akill * -1)
Next
If MouseHit (1)
cubelist.cubes = New cubes
cubelistentity = CopyEntity (cube)
cubelistalpha = 0
cubelistincdec = 1
cubelistkill = -1
cubelistzacc = Rnd (0.025, 1)
EntityAlpha cubelistentity, cubelistalpha
EntityColor cubelistentity, Rnd (100, 255), Rnd (100, 255), Rnd (100, 255)
EntityShininess cubelistentity, Rnd (0.01, 1)
EndIf
If TimeOut (newCube)
cubelist.cubes = New cubes
cubelistentity = CopyEntity (cube)
cubelistalpha = 0
cubelistincdec = 1
cubelistkill = -1
cubelistzacc = Rnd (0.01, 0.5)
EntityAlpha cubelistentity, cubelistalpha
EntityColor cubelistentity, Rnd (100, 255), Rnd (100, 255), Rnd (100, 255)
EntityShininess cubelistentity, Rnd (0.01, 1)
newCube.Timer = SetTimer (spawn)
EndIf
If TimeOut (alpha)
For a.cubes = Each cubes
If aincdec
aalpha = aalpha + azacc / 10
Else
aalpha = aalpha - azacc / 10
EndIf
If aalpha => 1
aincdec = 0
akill = 1
EndIf
EntityAlpha aentity, aalpha
If aalpha <= 0
If akill = 1
FreeEntity aentity
Delete a
EndIf
EndIf
Next
alpha.Timer = SetTimer (50)
EndIf
End Function