Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Enumeration
- #Flake
- #WinHeight = 600
- #WinWidth = 800
- #Number_of_flakes = 500 ;actually 501
- #SpriteSize = 32
- EndEnumeration
- Structure SnowPosition
- X.i ;X position of the flake
- Y.i ;Y position of the flake
- V.i ;Velocity
- W.i ;Wind
- EndStructure
- Dim Snow.SnowPosition(#Number_of_flakes)
- For i=0 To #Number_of_flakes ; Set a random coordinate on the screen each time the array is called
- Snow(i)\X = Random(#WinWidth)
- Snow(i)\Y = Random(#WinHeight) - #WinHeight
- Snow(i)\V = (Random(5000)/1000)+1 ; Velocity
- Snow(i)\W = (Random(5000)/1000)+1 ; Used to give a random xy (diagonal) speed for the effect of wind
- Next
- UsePNGImageDecoder()
- InitKeyboard()
- InitSprite()
- OpenWindow(0, 0, 0, 800, 600, "Static Sprite Test", #PB_Window_SystemMenu|#PB_Window_ScreenCentered)
- OpenWindowedScreen(WindowID(0), 0, 0, 800, 600, 0, 0, 0) ;Set the window parameters
- Global Quit.b = #False
- LoadSprite(#Flake, "flake.png", #PB_Sprite_Texture | #PB_Sprite_AlphaBlending)
- Repeat
- Repeat
- Event = WindowEvent()
- If Event = #PB_Event_CloseWindow : Quit = #True : EndIf
- Until Event = 0
- FlipBuffers()
- ClearScreen(0)
- Gosub Snowflake
- ExamineKeyboard()
- Delay(5)
- Until KeyboardPushed(#PB_Key_Escape) Or Quit
- End
- Snowflake:
- For count=0 To #Number_of_flakes
- DisplayTransparentSprite(#Flake, Snow(count)\X, Snow(count)\Y) ;Grab the coordinates for 10 flakes from the array and display them
- If Snow(count)\y>=#WinHeight ;Check if the sprite drops to or beyond the edge of the screen
- Snow(count)\y = #SpriteSize * -1 ;If it did, Display the sprite at the top of the screen, making sure they're rendered 32pts above, so they don't just appear
- EndIf
- If Snow(count)\x>=#WinWidth ;Check if the sprite drops to or beyond the right side of the screen
- Snow(count)\x = #Spritesize * -1
- EndIf
- Snow(count)\y + Snow(count)\V ;Move the sprite along the Y (down) axis 2 pixels a frame, checks above make sure it happens forever.
- Snow(count)\x + Snow(count)\w ;Move the sprite diagonally down, giving the effect of wind
- Next count
- Return
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement