Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;-Sprite Constants and Variables
- Enumeration
- #Flake
- #Flake3D
- #Number_of_flakes = 499 ;actually 501
- #SpriteSize = 32
- EndEnumeration
- ;-Window Constants and Variables
- Enumeration
- #WinHeight = 600
- #WinWidth = 800
- EndEnumeration
- ;-Sound Constants/Variables
- Enumeration
- #Sound1
- 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=1 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(2)+1 ; Velocity
- Snow(i)\W = Random(2)+1 ; Used to give a random xy (diagonal) speed for the effect of wind
- Next
- ;-Timer Procedure(s)
- Procedure TimerThread(derp)
- Repeat
- Global StartTime = ElapsedMilliseconds()
- Delay(Random(1000)+2000)
- Global ElapsedTime = ElapsedMilliseconds()-StartTime
- Until ElapsedTime
- EndProcedure
- Procedure TimerThread1(derp)
- Repeat
- Global StartTime1 = ElapsedMilliseconds()
- Delay(Random(1000)+8000)
- Global ElapsedTime1 = ElapsedMilliseconds()-StartTime
- Until ElapsedTime1
- EndProcedure
- ;- Initialisation Section
- UsePNGImageDecoder()
- UseOGGSoundDecoder()
- InitKeyboard()
- InitSprite()
- InitSprite3D()
- ;- Window and Event handling
- OpenWindow(0, 0, 0, 800, 600, "Snow Based Chillout Simulator", #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)
- CreateSprite3D(#Flake3D, #Flake)
- If InitSound()
- CatchSound(#Sound1, ?Sound1, ?EndSound1-?Sound1)
- PlaySound (#Sound1, #PB_Sound_Loop)
- CreateThread(@TimerThread(), 1)
- CreateThread(@TimerThread1(), 1)
- Repeat
- Repeat
- Event = WindowEvent()
- If Event = #PB_Event_CloseWindow : Quit = #True : EndIf
- Until Event = 0
- If ElapsedTime
- FlipBuffers()
- ClearScreen(0)
- Gosub SnowflakeReverse
- EndIf
- If ElapsedTime1
- FlipBuffers()
- ClearScreen(0)
- Gosub SnowFlakeForward
- EndIf
- ExamineKeyboard()
- Delay(1)
- Until KeyboardPushed(#PB_Key_Escape) Or Quit
- EndIf
- End
- ;-Snowflake Subroutine
- SnowflakeForward:
- For count=1 To #Number_of_flakes
- Start3D()
- DisplaySprite3D(#Flake3D, Snow(Count)\X, Snow(Count)\Y)
- ZoomSprite3D(#Flake3D, Snow(Count)\V * 9.3, Snow(Count)\V * 9.3)
- RotateSprite3D(#Flake3D, 0.003 * Snow(Count)\W , #PB_Relative)
- Stop3D()
- If Snow(count)\Y>=#WinHeight ;Check if the sprite drops to or beyond the edge of the screen
- 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
- EndIf
- If Snow(count)\X>=#WinWidth ;Check if the sprite drops to or beyond the right side of the screen
- Snow(count)\X = 0-#SpriteSize
- EndIf
- Snow(count)\Y + Snow(count)\V ;Move the sprite along the Y at a random speed (V)
- Snow(count)\X + Snow(count)\W ;Move the sprite diagonally across and down (some faster/greater angled than others), giving the effect of wind
- Next count
- Return
- SnowflakeReverse:
- For count1=1 To #Number_of_flakes
- Start3D()
- DisplaySprite3D(#Flake3D, Snow(Count1)\X, Snow(Count1)\Y)
- ZoomSprite3D(#Flake3D, Snow(Count1)\V * 9.3, Snow(Count1)\V * 9.3)
- RotateSprite3D(#Flake3D, 0.003 * Snow(Count1)\W , #PB_Relative)
- Stop3D()
- If Snow(count1)\Y>=#WinHeight ;Check if the sprite drops to or beyond the edge of the screen
- 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
- EndIf
- If Snow(count1)\X<=0-#SpriteSize ;Check if the sprite drops to or beyond the right side of the screen
- Snow(count1)\X = #WinWidth+#SpriteSize
- EndIf
- Snow(count1)\Y + Snow(count1)\V ;Move the sprite along the Y at a random speed (V)
- Snow(count1)\X - Snow(count1)\W ;Move the sprite diagonally across and down (some faster/greater angled than others), giving the effect of wind
- Next count1
- Return
- ;-Data Section
- DataSection
- Sound1:
- IncludeBinary "wind.ogg"
- EndSound1:
- EndDataSection
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement