; include the frame sheet animation library #Include "FrameSheetAnims" ; The file name of the example frame sheet we're going ; to load Filename$=ProgramDir$()+"Help/Commands/Media/Animations/explosions.png" ; Load the Frame sheet FrameSheet=LoadFrameSheet(Filename$,64,64,RGB(0,0,0)) ; Declare a type to hold the info about our game object Type Gameobject x#,y# ; Screen Position Angle# ; Direct it's moving in Speed# ; Speed it's move at Animation ; it's using EndType Dim Obj As GameObject List ; Limit the programs speed to 60 fps (or there abouts) SetFPS 60 ; Run This section of code, until a key is pressed Repeat ; Clear The Screen Cls RGB(0,0,0) ; Randomly add new objects to the scene If Rnd(1000)>950 Obj = New GameObject Obj.x =Rnd(GetScreenWidth()) Obj.y =Rnd(GetScreenHeight()) Obj.Angle# =Rnd(360) Obj.Speed# =RndRange(1,5) Obj.Animation =NewAnim(FrameSheet,Rnd(10)) EndIf For Each Obj() ; Get this objects movement direct and speed Angle#=Obj.angle# Speed#=Obj.speed# ; Calc the position where this object is moving to x#=Obj.x#+CosRadius(angle#,speed#) y#=Obj.y#+SinRadius(angle#,speed#) ; Draw the current state of this animation. DrawAnim Obj.Animation,x#,y#,true ; store it's new position after moving Obj.x#=x# Obj.y#=y# ; check of the object has left the screen ? If PointInBox(X#,y#,0,0,GetScreenWidth(),GetScreenHeight())=false ; delete the animation this object was using DeleteAnim Obj.Animation ; remove this object from the list Obj=null ; continue FOR each list Continue EndIf Next ; show the screen to the user and wait for a key press Sync ; If no key is pressed, jump back to the repeat ; run this section of code again. Until ScanCode()<>0 ; End This program End |