Weather in 2D tile engines
I've added some weather effects to our 2D tile engine. You can't really see it here or hear it for that matter, but the system works quite well.
I'm working on doing some more alpha with the rain but this works for now.
The tile map was created in my tile editor and loaded into the engine.
The diffuse color has been altered for all the tiles to account for a stormy day.
When the weather system first starts up I load the various weather sounds and save the ID returned from my sound manager class. I set the rain sounds to looping via the sound manager. Then when the rain starts, I tell the sound manager to play the rain sound ID and it loops indefinitely...or as long as it rains. A thunder timer is then started to denote when the next clap of thunder will be. When this timer has elapsed I set lightning to true and a white 50% alpha blended quad is rendered over the entire screen making it flash. The flash lasts for approximately .25 seconds. A thunder delay timer is then fired off and when it elapses I play the thunder sound ID and set the timer for the next clap of thunder.
The entire system is started by calling Start(). When I'm done with the class the start function will set a spool up time to get to the desired rain percentage. When the rain is at max the thunder process will begin. The spool up is specified in the script command to make it rain. You can then stop the rain by calling Stop() which will gradually spool down the rain till it turns off completely.
The rain is a simple line list in Direct3D and wraps at the edges of the screen. The vertices are in a custom vertex array that I then send to Direct3D to render. I can update the vertices in the array w/o locking the buffer b/c it's a custom vertex buffer. You can change the percent of rain from 0 to 100, the speed of the rain, and the angle it falls at. 100% rain means there will be 256 individual lines of rain rendered. The formula is 512*(rainpercent/100) to account for all vertices. Each line is of course 2 vertices. When the final product is done we will be placing rain splatter animations at various places on tile layer 1 to simulate rain hitting the ground. Since this is 2D I really have no way of detecting a collision with anything. I could assign each raindrop a certain location to fall to and then fire of a rain splatter animation but I've not gotten that far yet. The entire system works with ID's for sound, textures, maps, and objects. So accessing any of those can be done provided you have the ID.
Quite happy with the system so far.
Just thought I'd post in case anyone was wondering how they might do something like this in their own 2D tile system.