Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ; Structure for our object
- Structure AnimatedObj
- x.i ;position x
- y.i ;position y
- delay.i ;time to next frame
- delayTime.i ;save delay time
- frame.i ;frame (number from LoadSprite, not best way but easy :-P )
- EndStructure
- ; Create 5 ships with random stats
- Global Dim ship.AnimatedObj(5)
- For i = 0 To ArraySize(ship())
- ship(i)\x = (i*64)
- ship(i)\y = 0
- ship(i)\delayTime = Random(10, 4) ;Random speed
- ship(i)\delay = ship(i)\delayTime
- ship(i)\frame = Random(5, 0)
- Next
- ;Render function
- Procedure RenderFrame()
- ;Animate Ships
- For i = 0 To ArraySize(ship())
- ship(i)\delay -1
- If ship(i)\delay = 0
- ship(i)\frame + 1
- ship(i)\delay = ship(i)\delayTime
- If ship(i)\frame = 6
- ship(i)\frame = 0
- EndIf
- EndIf
- Next
- ;Display ships
- For i = 0 To ArraySize(ship())
- DisplaySprite(ship(i)\frame, ship(i)\x, ship(i)\y)
- Next
- ;Display our great game ;)
- FlipBuffers()
- EndProcedure
- ;Loading function
- Procedure Loading(Type, Filename$)
- Static NbLoadedElements
- NbLoadedElements+1
- If NbLoadedElements = 6
- FlipBuffers()
- EndIf
- EndProcedure
- ;LoadingError function
- Procedure LoadingError(Type, Filename$)
- Debug Filename$ + ": loading error"
- EndProcedure
- ; Create screen and set framerate
- OpenScreen(800, 600, 32, "Animation")
- SetFrameRate(60)
- ; Register the loading event before calling any resource load command
- BindEvent(#PB_Event_Loading, @Loading())
- BindEvent(#PB_Event_LoadingError, @LoadingError())
- BindEvent(#PB_Event_RenderFrame, @RenderFrame())
- LoadSprite(0, "data/frame1.png")
- LoadSprite(1, "data/frame2.png")
- LoadSprite(2, "data/frame3.png")
- LoadSprite(3, "data/frame4.png")
- LoadSprite(4, "data/frame5.png")
- LoadSprite(5, "data/frame6.png")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement