Fireworks
BlitzMax Forums/BlitzMax Beginners Area/Fireworks
| ||
Hi, Can anyone help prompt me in the right direction of creating an exploding pixel, that will send pixels off at different degrees. It would be good to say to Blitz, a=int rnd(0-360) and let it send the pixel off at that bearing. Many thanks |
| ||
the little particle programs here might help you http://www.scottshaver2000.com/forum/viewtopic.php?p=379 |
| ||
Try this. Its a bit rushed cos I've been awake most of the last 24 hours:Graphics 800,600 Global t:ttimer = CreateTimer(1) Global fireworkList:TList = New TList Global sparkList:TList = New TList Global gravity:Float = 0.1 While Not KeyDown(key_escape) Cls UpdateFireworks() updateSparks() DrawFireworks() Flip Wend Function UpdateFireworks() If t.ticks() > 0 addFirework() t._ticks = 0 EndIf For f:firework = EachIn fireworkList f.ySpeed :+ gravity f.x :+ f.xSpeed f.y :+ f.ySpeed If f.ySpeed >=1 CreateExplosion(f,20) fireworkList.remove f EndIf Next End Function Function updateSparks() For s:spark = EachIn sparkList s.x :+ s.xSpeed s.ySpeed :+ gravity s.y :+ s.ySpeed If s.y > GraphicsHeight() Or s.y < 0 Or s.y > GraphicsWidth() sparkList.remove s EndIf Next End Function Function drawFireworks() For f:firework = EachIn fireworkList DrawRect f.x-1,f.y-1,2,2 Next For s:spark = EachIn sparkList DrawRect s.x,s.y,2,2 Next End Function Function CreateExplosion(f:firework, parts:Int) For n:Int = 1 To parts Local s:spark = New spark s.x = f.x s.y = f.y s.xSpeed = Rnd(-3,3) s.ySpeed = Rnd(-5,3) sparkList.addLast s Next End Function Function addFirework() Local f:firework = New firework f.x = Rand(0,GraphicsWidth()) f.y = GraphicsHeight() f.xspeed = Rnd(-2,2) f.yspeed = -8 fireworkList.addLast f End Function Type FireWork Field x:Float Field y:Float Field xSpeed:Float Field ySpeed:Float End Type Type spark Field x:Float Field y:Float Field xSpeed:Float Field ySpeed:Float End Type |
| ||
ParticleXSpeed=Radius*Cos(Angle)/Steps PartlcleYSpeed=Radius*Sin(Angle)/Steps Then each frame: XPosition:+ParticleXSpeed YPosition:+ParticleYSpeed+Gravity Gravity is probably like -0.01 or something |
| ||
You might also want to check fireworks.bmx sample. |
| ||
Actually technocally each particle should also de-accelerate over time due to air resistance. You could just say XSpeed:*0.99 and YSpeed:*0.99 or some value to decrease it. |
| ||
Actually technocally each particle should also de-accelerate over time due to air resistance. You could just say XSpeed:*0.99 and YSpeed:*0.99 or some value to decrease it. What happens if they decellerate completly before they hit the ground? Does a man come round with a net on a long pole and scoop them out of the sky? :D |
| ||
Man*height+(distance to falling star*velocity of star fall)/speed of running man+size of net=man come round with a net on a long pole and scoop them out of the sky!!! ;> lol Hey, thanks for that you all - I'll have a play around with the ideas and see how I get on. I really wanted it just for the end game sequence - better than just saying 'Congratulations!'. |
| ||
lol, the gravity takes care of them falling off the screen. |
| ||
Do you have to catch them falling off the screen? Seriously though, many thanks to you all for your help. I couldn't get the big program running above, and I got a bit flustered with the maths (Cos/SSIN etc); however, you guys steered me in the right direction and I managed to knock up an array to hold 40 star points with floating variables and various other bits so that in the end, they all begin at a single point and spread out. I threw in some random elements so they would not all look too much the same. Thanks again for your help(s) |
| ||
also worth looking at: BlitzMax\samples\simonh\fireworks.bmx |