Snow effect?
Monkey Forums/Monkey Programming/Snow effect?
| ||
I know Christmas is still a while off, but we're looking to create a festive version of one of our games. Part of this has to include snow, snow, snow.. Now I'm sure I can craft something, but maybe there's an elegant, efficient approach to having some fluffy snowflakes drift down the screen? Early festive greetings, all :-) |
| ||
If you make it 3d, you can use my particle engine. ;) |
| ||
nice, but this was going to be 2d, just some flakes drifting down the screen, hopefully a bit better than back in 1983.. http://www.youtube.com/watch?v=8Nfgdr4fOS8 |
| ||
If you just want it to drift, it should be pretty easy... but if you want it to build up against objects, that'll be tricky... [monkeycode]Strict Import mojo Function Main:Int() New SnowApp() Return 0 End Class SnowApp Extends App Method OnCreate:Int() SetUpdateRate(60) For Local i:Int = 0 To 1000 New SnowFlake(Rnd(0, DeviceWidth()), Rnd(0, DeviceHeight())) Next For Local s:SnowFlake = Eachin SnowFlake.list s.dx = 1 Next Return 0 End Method OnUpdate:Int() SnowFlake.UpdateAll() If KeyDown(KEY_Z) For Local s:SnowFlake = Eachin SnowFlake.list s.dx-=.1 Next End If KeyDown(KEY_X) For Local s:SnowFlake = Eachin SnowFlake.list s.dx+=.1 Next End Return 0 End Method OnRender:Int() Cls(0, 0, 0) SnowFlake.DrawAll() Return 0 End End Class SnowFlake Global list:List<SnowFlake> = New List<SnowFlake> Field x:Float, y:Float Field dx:Float, dy:Float Field size:Float Method New(x:Float, y:Float) Self.x = x Self.y = y Self.dy = Rnd(1, 3) Self.size = Rnd(1, 3) list.AddLast(Self) End Function UpdateAll:Void() If Not list Return For Local s:SnowFlake = Eachin list s.Update() Next End Method Update:Void() y+=dy x+=dx If y > DeviceHeight() x = Rnd(0, DeviceWidth()) y = 0 End If x > DeviceWidth() x = 0 End If x < 0 x = DeviceWidth() End End Function DrawAll:Void() If Not list Return For Local s:SnowFlake = Eachin list s.Draw() Next End Method Draw:Void() SetColor(255, 255, 255) DrawOval(x, y, size, size) End End[/monkeycode] |
| ||
Cheers for the ideas.. Drift? Yep Build up 'gainst objects? Nope |
| ||
Nice effect, Steve! |
| ||
Steve - I've tried your code and its fab. Is it ok to include a modified version in my free game? |
| ||
Nice effect, Steve! Thanks! Took me a whole 2 mins to write ;) Is it ok to include a modified version in my free game? Feel free, just make sure you use some delta timing or something :) |