Advertisement
Guest User

Untitled

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