Advertisement
Guest User

Untitled

a guest
Sep 24th, 2017
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Enumeration
  2.   #Flake
  3.   #WinHeight = 600
  4.   #WinWidth = 800
  5.   #Number_of_flakes = 500 ;actually 501
  6.   #SpriteSize = 32
  7. EndEnumeration
  8.  
  9. Structure SnowPosition
  10.   X.i ;X position of the flake
  11.   Y.i ;Y position of the flake
  12.   V.i ;Velocity
  13.   W.i ;Wind
  14. EndStructure
  15.  
  16. Dim Snow.SnowPosition(#Number_of_flakes)
  17. For i=0 To #Number_of_flakes ; Set a random coordinate on the screen each time the array is called
  18.   Snow(i)\X = Random(#WinWidth)
  19.   Snow(i)\Y = Random(#WinHeight) - #WinHeight
  20.   Snow(i)\V = (Random(5000)/1000)+1 ; Velocity
  21.   Snow(i)\W = (Random(5000)/1000)+1 ; Used to give a random xy (diagonal) speed for the effect of wind
  22. Next
  23.  
  24. UsePNGImageDecoder()
  25. InitKeyboard()
  26. InitSprite()
  27.  
  28.  
  29. OpenWindow(0, 0, 0, 800, 600, "Static Sprite Test", #PB_Window_SystemMenu|#PB_Window_ScreenCentered)
  30. OpenWindowedScreen(WindowID(0), 0, 0, 800, 600, 0, 0, 0) ;Set the window parameters
  31. Global Quit.b = #False
  32. LoadSprite(#Flake, "flake.png", #PB_Sprite_Texture | #PB_Sprite_AlphaBlending)
  33.  
  34. Repeat
  35.  
  36.   Repeat
  37.     Event = WindowEvent()
  38.     If Event = #PB_Event_CloseWindow : Quit = #True : EndIf
  39.   Until Event = 0
  40.   FlipBuffers()
  41.   ClearScreen(0)
  42.   Gosub Snowflake
  43.   ExamineKeyboard()
  44.   Delay(5)
  45. Until KeyboardPushed(#PB_Key_Escape) Or Quit
  46. End  
  47.  
  48. Snowflake:
  49. For count=0 To #Number_of_flakes
  50.   DisplayTransparentSprite(#Flake, Snow(count)\X, Snow(count)\Y) ;Grab the coordinates for 10 flakes from the array and display them
  51.   If Snow(count)\y>=#WinHeight ;Check if the sprite drops to or beyond the edge of the screen
  52.     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
  53.   EndIf
  54.   If Snow(count)\x>=#WinWidth ;Check if the sprite drops to or beyond the right side of the screen
  55.     Snow(count)\x = #Spritesize * -1
  56.   EndIf
  57.   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.
  58.   Snow(count)\x + Snow(count)\w ;Move the sprite diagonally down, giving the effect of wind
  59. Next count
  60. Return
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement