Just starting out? Need help? Post your questions and find answers here.
J. Baker
Addict
Posts: 2181 Joined: Sun Apr 27, 2003 8:12 am
Location: USA
Contact:
Post
by J. Baker » Wed Oct 27, 2010 6:02 am
I'm not sure why this will not work correctly? Any help would be great, thanks.
Code: Select all
Structure SnowCalculations
SnowX.l
SnowY.l
EndStructure
Procedure SnowFlakes(SnowSprite)
Static Dim Snow.SnowCalculations(100)
SnowCount +1
If SnowCount > 101
SnowRandom = 1
Else
SnowRandom = 0
EndIf
If SnowRandom = 1
Snow(SnowSprite)\SnowX = Random(800)
Snow(SnowSprite)\SnowY = Random(600)
EndIf
If Snow(SnowSprite)\SnowY = 600 +32
Snow(SnowSprite)\SnowY = -32
Snow(SnowSprite)\SnowX = Random(800)
Else
DisplayTransparentSprite(SnowSprite, Snow(SnowSprite)\SnowX, Snow(SnowSprite)\SnowY)
EndIf
Snow(SnowSprite)\SnowY +1
EndProcedure
InitSprite()
;InitKeyboard()
UsePNGImageDecoder()
WinWidth = 800
WinHeight = 600
OpenWindow(0,0,0,WinWidth,WinHeight,"Snow Test",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)
OpenWindowedScreen(WindowID(0),0,0,WinWidth,WinHeight,0,0,0)
For Snow = 1 To 100
CatchSprite(Snow, ?Pic0, #PB_Sprite_Texture | #PB_Sprite_AlphaBlending)
Next Snow
MaxSnow = 0
quit=0
;SnowRandom = 1
Repeat
Repeat
ev=WindowEvent()
If ev=#PB_Event_CloseWindow
quit=1
EndIf
Until ev=0
;ExamineKeyboard()
For Snow = 1 To 100
SnowFlakes(Snow)
Next Snow
FlipBuffers()
ClearScreen(0)
Until quit
DataSection
Pic0: IncludeBinary "flake.png"
EndDataSection
infratec
Always Here
Posts: 7618 Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany
Post
by infratec » Wed Oct 27, 2010 10:24 am
Hi,
first of all I think something like
is missing in the SnowFlakes() procedure.
Should be inside the else part. Else it sometimes come back to < 101
And than:
What do you want
Without an exact explanation what the result should be, no one can adjust the code.
Bernd
infratec
Always Here
Posts: 7618 Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany
Post
by infratec » Wed Oct 27, 2010 10:40 am
Maybe you want this
Code: Select all
#WinWidth = 800
#WinHeight = 600
#MaxFlakes = 100
Structure SnowCalculations
X.i
Y.i
S.i
EndStructure
Procedure SnowFlakes(SnowSprite)
Static Dim Snow.SnowCalculations(#MaxFlakes)
Static SnowCount = 0
If SnowCount < #MaxFlakes
Snow(SnowSprite)\X = Random(#WinWidth)
Snow(SnowSprite)\Y = Random(#WinHeight) - #WinHeight
Snow(SnowSprite)\S = Random(2) + 1
SnowCount + 1
EndIf
If Snow(SnowSprite)\Y > #WinHeight + 32
Snow(SnowSprite)\Y = -32
Snow(SnowSprite)\X = Random(#WinWidth)
Snow(SnowSprite)\S = Random(2) + 1
Else
DisplayTransparentSprite(SnowSprite, Snow(SnowSprite)\X, Snow(SnowSprite)\Y)
EndIf
Snow(SnowSprite)\Y + Snow(SnowSprite)\S
EndProcedure
UsePNGImageDecoder()
InitSprite()
OpenWindow(0, 0, 0,#WinWidth, #WinHeight, "Snow Test", #PB_Window_SystemMenu|#PB_Window_ScreenCentered)
OpenWindowedScreen(WindowID(0), 0, 0, #WinWidth, #WinHeight, 0, 0, 0)
For Snow = 1 To #MaxFlakes : CatchSprite(Snow, ?Pic0, #PB_Sprite_Texture | #PB_Sprite_AlphaBlending) : Next Snow
Quit = #False
Repeat
Repeat
Event = WindowEvent()
If Event = #PB_Event_CloseWindow : Quit = #True : EndIf
Until Event = 0
FlipBuffers()
ClearScreen(0)
For Snow = 1 To #MaxFlakes : SnowFlakes(Snow) : Next Snow
Delay(5)
Until Quit
DataSection
Pic0: IncludeBinary "flake.png"
EndDataSection
Best regards,
Bernd
J. Baker
Addict
Posts: 2181 Joined: Sun Apr 27, 2003 8:12 am
Location: USA
Contact:
Post
by J. Baker » Wed Oct 27, 2010 2:06 pm
Thanks infratec! Yes I was originally just trying to get them to fall properly but you also added the random speed for me. I see what I wasn't doing correctly now. Thanks again!
infratec
Always Here
Posts: 7618 Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany
Post
by infratec » Wed Oct 27, 2010 2:55 pm
Hi,
you are welcome
And only for fun I added a start/stop function (cursor up/down)
Code: Select all
#WinWidth = 800
#WinHeight = 600
#MaxFlakes = 100
#SpriteHeight = 32
Structure SnowCalculations
X.i
Y.i
V.i
S.i
EndStructure
Procedure SnowFlakes(SnowSprite, Status)
Static Dim Snow.SnowCalculations(#MaxFlakes)
If Status
If Not Snow(SnowSprite)\S
Snow(SnowSprite)\X = Random(#WinWidth)
Snow(SnowSprite)\Y = Random(#WinHeight) - #WinHeight
Snow(SnowSprite)\V = Random(2) + 1
Snow(SnowSprite)\S = #True
EndIf
Else
If Snow(SnowSprite)\Y < #SpriteHeight * -1
Snow(SnowSprite)\Y = #WinHeight + #SpriteHeight
EndIf
EndIf
If Snow(SnowSprite)\Y >= #WinHeight + #SpriteHeight
If Status
Snow(SnowSprite)\Y = #SpriteHeight * -1
Snow(SnowSprite)\X = Random(#WinWidth)
Snow(SnowSprite)\V = Random(2) + 1
Else
Snow(SnowSprite)\S = #False
EndIf
Else
DisplayTransparentSprite(SnowSprite, Snow(SnowSprite)\X, Snow(SnowSprite)\Y)
EndIf
If Snow(SnowSprite)\S : Snow(SnowSprite)\Y + Snow(SnowSprite)\V : EndIf
EndProcedure
UsePNGImageDecoder()
InitKeyboard()
InitSprite()
OpenWindow(0, 0, 0,#WinWidth, #WinHeight, "Snow Test", #PB_Window_SystemMenu|#PB_Window_ScreenCentered)
OpenWindowedScreen(WindowID(0), 0, 0, #WinWidth, #WinHeight, 0, 0, 0)
For Snow = 1 To #MaxFlakes : CatchSprite(Snow, ?Pic0, #PB_Sprite_Texture | #PB_Sprite_AlphaBlending) : Next Snow
Quit = #False
SnowStatus = #True
Repeat
Repeat
Event = WindowEvent()
If Event = #PB_Event_CloseWindow : Quit = #True : EndIf
Until Event = 0
ExamineKeyboard()
If KeyboardReleased(#PB_Key_Up) : SnowStatus = #False : EndIf
If KeyboardReleased(#PB_Key_Down) : SnowStatus = #True : EndIf
FlipBuffers()
ClearScreen(0)
For Flake = 1 To #MaxFlakes : SnowFlakes(Flake, SnowStatus) : Next Flake
Delay(5)
Until Quit
DataSection
Pic0: IncludeBinary "flake.png"
EndDataSection
Have fun,
Bernd
J. Baker
Addict
Posts: 2181 Joined: Sun Apr 27, 2003 8:12 am
Location: USA
Contact:
Post
by J. Baker » Wed Oct 27, 2010 3:10 pm
Pretty Cool!
I just need to make them Sprite3D() now. So that they can be zoomed and rotated.
J. Baker
Addict
Posts: 2181 Joined: Sun Apr 27, 2003 8:12 am
Location: USA
Contact:
Post
by J. Baker » Wed Oct 27, 2010 8:03 pm
We now have zoomed and rotating snow based on speed.
Code: Select all
#WinWidth = 800
#WinHeight = 600
#MaxFlakes = 100
Structure SnowCalculations
SnowX.i
SnowY.i
SnowS.i
EndStructure
Procedure SnowFlakes(SnowSprite)
Static Dim Snow.SnowCalculations(#MaxFlakes)
Static SnowCount = 0
If SnowCount < #MaxFlakes
Snow(SnowSprite)\SnowX = Random(#WinWidth)
Snow(SnowSprite)\SnowY = Random(#WinHeight) - #WinHeight
Snow(SnowSprite)\SnowS = Random(2) + 1
SnowCount + 1
EndIf
If Snow(SnowSprite)\SnowY > #WinHeight + 32
Snow(SnowSprite)\SnowY = -32
Snow(SnowSprite)\SnowX = Random(#WinWidth)
Snow(SnowSprite)\SnowS = Random(2) + 1
Else
Start3D()
ZoomSprite3D(SnowSprite, Snow(SnowSprite)\SnowS * 8, Snow(SnowSprite)\SnowS * 8)
DisplaySprite3D(SnowSprite, Snow(SnowSprite)\SnowX, Snow(SnowSprite)\SnowY)
RotateSprite3D(SnowSprite, 0.2 * Snow(SnowSprite)\SnowS, #PB_Relative)
Stop3D()
EndIf
Snow(SnowSprite)\SnowY + Snow(SnowSprite)\SnowS
EndProcedure
UsePNGImageDecoder()
InitSprite()
InitSprite3D()
OpenWindow(0, 0, 0,#WinWidth, #WinHeight, "Snow Test", #PB_Window_SystemMenu|#PB_Window_ScreenCentered)
OpenWindowedScreen(WindowID(0), 0, 0, #WinWidth, #WinHeight, 0, 0, 0)
For Snow = 1 To #MaxFlakes
CatchSprite(Snow, ?Pic0, #PB_Sprite_Texture | #PB_Sprite_AlphaBlending)
CreateSprite3D(Snow, Snow)
Next Snow
Quit = #False
Repeat
Repeat
Event = WindowEvent()
If Event = #PB_Event_CloseWindow
Quit = #True
EndIf
Until Event = 0
FlipBuffers()
ClearScreen(0)
For Snow = 1 To #MaxFlakes
SnowFlakes(Snow)
Next Snow
Delay(5)
Until Quit
DataSection
Pic0: IncludeBinary "flake.png"
EndDataSection
rootuid
User
Posts: 48 Joined: Sat Nov 23, 2013 11:46 am
Post
by rootuid » Sun Nov 24, 2013 12:10 am
I compiled but got an error stating that start3d() is not a valid function. Is InitEngine3D the new version of this function ?
J. Baker
Addict
Posts: 2181 Joined: Sun Apr 27, 2003 8:12 am
Location: USA
Contact:
Post
by J. Baker » Sun Nov 24, 2013 12:44 am
rootuid wrote: I compiled but got an error stating that start3d() is not a valid function. Is InitEngine3D the new version of this function ?
This code hasn't been updated for the newest version of PureBasic. There aren't any Sprite3D commands as they all have been updated to the normal Sprite commands. Check out the help file.
rootuid
User
Posts: 48 Joined: Sat Nov 23, 2013 11:46 am
Post
by rootuid » Sun Nov 24, 2013 1:05 am
Thanks for the heads up J. Baker !
J. Baker
Addict
Posts: 2181 Joined: Sun Apr 27, 2003 8:12 am
Location: USA
Contact:
Post
by J. Baker » Sun Nov 24, 2013 1:43 am
rootuid wrote: Thanks for the heads up J. Baker !
Got a little time so I quickly edited the code for PureBasic v5.21. Alter to your liking.
Code: Select all
#WinWidth = 800
#WinHeight = 600
#MaxFlakes = 100
Structure SnowCalculations
SnowX.i
SnowY.i
SnowS.i
EndStructure
Procedure SnowFlakes(SnowSprite)
Static Dim Snow.SnowCalculations(#MaxFlakes)
Static SnowCount = 0
If SnowCount < #MaxFlakes
Snow(SnowSprite)\SnowX = Random(#WinWidth)
Snow(SnowSprite)\SnowY = Random(#WinHeight) - #WinHeight
Snow(SnowSprite)\SnowS = Random(2) + 1
SnowCount + 1
EndIf
If Snow(SnowSprite)\SnowY > #WinHeight + 32
Snow(SnowSprite)\SnowY = -32
Snow(SnowSprite)\SnowX = Random(#WinWidth)
Snow(SnowSprite)\SnowS = Random(2) + 1
Else
ZoomSprite(SnowSprite, Snow(SnowSprite)\SnowS * 8, Snow(SnowSprite)\SnowS * 8)
DisplayTransparentSprite(SnowSprite, Snow(SnowSprite)\SnowX, Snow(SnowSprite)\SnowY)
RotateSprite(SnowSprite, 0.2 * Snow(SnowSprite)\SnowS, #PB_Relative)
EndIf
Snow(SnowSprite)\SnowY + Snow(SnowSprite)\SnowS
EndProcedure
UsePNGImageDecoder()
InitSprite()
OpenWindow(0, 0, 0,#WinWidth, #WinHeight, "Snow Test", #PB_Window_SystemMenu|#PB_Window_ScreenCentered)
OpenWindowedScreen(WindowID(0), 0, 0, #WinWidth, #WinHeight, 0, 0, 0)
For Snow = 1 To #MaxFlakes
CatchSprite(Snow, ?Pic0, #PB_Sprite_AlphaBlending)
Next Snow
Quit = #False
Repeat
Repeat
Event = WindowEvent()
If Event = #PB_Event_CloseWindow
Quit = #True
EndIf
Until Event = 0
FlipBuffers()
ClearScreen(0)
For Snow = 1 To #MaxFlakes
SnowFlakes(Snow)
Next Snow
Delay(5)
Until Quit
DataSection
Pic0:
IncludeBinary "flake.png"
EndDataSection