Advertisement
Guest User

Untitled

a guest
Sep 25th, 2017
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ;-Sprite Constants and Variables
  2. Enumeration
  3.   #Flake
  4.   #Flake3D
  5.   #Number_of_flakes = 499 ;actually 501
  6.   #SpriteSize = 32
  7. EndEnumeration
  8.  
  9. ;-Window Constants and Variables
  10. Enumeration
  11.   #WinHeight = 600
  12.   #WinWidth = 800
  13. EndEnumeration
  14.  
  15. ;-Sound Constants/Variables
  16. Enumeration
  17.   #Sound1
  18. EndEnumeration
  19.  
  20. Structure SnowPosition
  21.   X.i ;X position of the flake
  22.   Y.i ;Y position of the flake
  23.   V.i ;Velocity
  24.   W.i ;Wind
  25. EndStructure
  26.  
  27. Dim Snow.SnowPosition(#Number_of_flakes)
  28. For i=1 To #Number_of_flakes ; Set a random coordinate on the screen each time the array is called
  29.   Snow(i)\X = Random(#WinWidth)
  30.   Snow(i)\Y = Random(#WinHeight) - #WinHeight
  31.   Snow(i)\V = Random(2)+1 ; Velocity
  32.   Snow(i)\W = Random(2)+1 ; Used to give a random xy (diagonal) speed for the effect of wind
  33. Next
  34. ;-Timer Procedure(s)
  35. Procedure TimerThread(derp)
  36.   Repeat
  37.     Global StartTime = ElapsedMilliseconds()            
  38.     Delay(Random(1000)+2000)                                  
  39.     Global ElapsedTime = ElapsedMilliseconds()-StartTime
  40.   Until ElapsedTime
  41. EndProcedure
  42.  
  43. Procedure TimerThread1(derp)
  44.   Repeat
  45.     Global StartTime1 = ElapsedMilliseconds()            
  46.     Delay(Random(1000)+8000)                                  
  47.     Global ElapsedTime1 = ElapsedMilliseconds()-StartTime
  48.   Until ElapsedTime1
  49. EndProcedure
  50.  
  51.  
  52. ;- Initialisation Section
  53. UsePNGImageDecoder()
  54. UseOGGSoundDecoder()
  55. InitKeyboard()
  56. InitSprite()
  57. InitSprite3D()
  58.  
  59. ;- Window and Event handling
  60. OpenWindow(0, 0, 0, 800, 600, "Snow Based Chillout Simulator", #PB_Window_SystemMenu|#PB_Window_ScreenCentered)
  61. OpenWindowedScreen(WindowID(0), 0, 0, 800, 600, 0, 0, 0) ;Set the window parameters
  62. Global Quit.b = #False
  63. LoadSprite(#Flake, "flake.png", #PB_Sprite_Texture | #PB_Sprite_AlphaBlending)
  64. CreateSprite3D(#Flake3D, #Flake)
  65. If InitSound()
  66.   CatchSound(#Sound1, ?Sound1, ?EndSound1-?Sound1)
  67.   PlaySound (#Sound1, #PB_Sound_Loop)
  68.   CreateThread(@TimerThread(), 1)
  69.   CreateThread(@TimerThread1(), 1)
  70.   Repeat
  71.    
  72.     Repeat
  73.       Event = WindowEvent()
  74.       If Event = #PB_Event_CloseWindow : Quit = #True : EndIf
  75.     Until Event = 0
  76.    
  77.     If ElapsedTime
  78.       FlipBuffers()
  79.       ClearScreen(0)
  80.       Gosub SnowflakeReverse
  81.     EndIf
  82.    
  83.   If ElapsedTime1
  84.       FlipBuffers()
  85.       ClearScreen(0)
  86.       Gosub SnowFlakeForward
  87.  
  88.     EndIf
  89.     ExamineKeyboard()
  90.     Delay(1)
  91.   Until KeyboardPushed(#PB_Key_Escape) Or Quit
  92.  
  93. EndIf
  94.  
  95. End  
  96.  
  97. ;-Snowflake Subroutine
  98. SnowflakeForward:
  99. For count=1 To #Number_of_flakes
  100.   Start3D()
  101.   DisplaySprite3D(#Flake3D, Snow(Count)\X, Snow(Count)\Y)
  102.   ZoomSprite3D(#Flake3D, Snow(Count)\V * 9.3, Snow(Count)\V * 9.3)
  103.   RotateSprite3D(#Flake3D, 0.003 * Snow(Count)\W , #PB_Relative)
  104.   Stop3D()
  105.   If Snow(count)\Y>=#WinHeight ;Check if the sprite drops to or beyond the edge of the screen
  106.     Snow(count)\Y = 0-#SpriteSize ;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" whole
  107.   EndIf
  108.   If Snow(count)\X>=#WinWidth ;Check if the sprite drops to or beyond the right side of the screen
  109.     Snow(count)\X = 0-#SpriteSize
  110.   EndIf
  111.   Snow(count)\Y + Snow(count)\V ;Move the sprite along the Y at a random speed (V)
  112.   Snow(count)\X + Snow(count)\W ;Move the sprite diagonally across and down (some faster/greater angled than others), giving the effect of wind
  113. Next count
  114. Return
  115.  
  116. SnowflakeReverse:
  117. For count1=1 To #Number_of_flakes
  118.   Start3D()
  119.   DisplaySprite3D(#Flake3D, Snow(Count1)\X, Snow(Count1)\Y)
  120.   ZoomSprite3D(#Flake3D, Snow(Count1)\V * 9.3, Snow(Count1)\V * 9.3)
  121.   RotateSprite3D(#Flake3D, 0.003 * Snow(Count1)\W , #PB_Relative)
  122.   Stop3D()
  123.   If Snow(count1)\Y>=#WinHeight ;Check if the sprite drops to or beyond the edge of the screen
  124.     Snow(count1)\Y = 0-#SpriteSize ;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" whole
  125.   EndIf
  126.   If Snow(count1)\X<=0-#SpriteSize ;Check if the sprite drops to or beyond the right side of the screen
  127.     Snow(count1)\X = #WinWidth+#SpriteSize
  128.   EndIf
  129.   Snow(count1)\Y + Snow(count1)\V ;Move the sprite along the Y at a random speed (V)
  130.   Snow(count1)\X - Snow(count1)\W ;Move the sprite diagonally across and down (some faster/greater angled than others), giving the effect of wind
  131. Next count1
  132. Return
  133.  
  134. ;-Data Section
  135. DataSection
  136.   Sound1:
  137.   IncludeBinary "wind.ogg"
  138.   EndSound1:
  139. EndDataSection
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement