Public Group

# Weather effects?

This topic is 4137 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hello again! With your help , i've done great things...i couldnt believe that i could create a 2d space game. But again , i need your help. Im looking for a way to add rain effect in my game , but , i have no idea how to write such a thing. The class with the object(s) is ready , all i need is some code!! ...

##### Share on other sites
Rain... in a space game? Uhh, whatever, if you say so... ;)

Anyway, what kind of rain effect are you looking for? You surely will not know how to do something when you don't know what you want in the first place, so writing down what exactly you want would be a good place to start. I usually get some idea's on how to implement it when I sketch things out. And even if you still don't see a way to do it then, at least you can tell us so we can help you further. :)

##### Share on other sites
Weather effects, blood, explosions, smoke, etc. can be implemented with a particle engine. Google is your friend ;-)

##### Share on other sites
Quote:
 Original post by Captain PRain... in a space game? Uhh, whatever, if you say so... ;)

Rain in space seems to be quite popular recently.

John B

##### Share on other sites
@captain P :
Yea , i know how it sounds , but i wanted to try something different!

@Anhfelt :
Well , i want something really simple , particle engine seems to be complex .

Anyway , here's my idea :

//LIST =VEVTOR list with images..int counter=0;int y=0;//create 1200 images! (window height * 2 !)for (a=0;a<=list.size-1;a++){LIST[a].repositionobject(counter,y);y+=50;//widthif (y>screen_width) {y=0;counter-=40//(height)}}

then i could just move them with a loop...
But im sure my idea is noobish ://

##### Share on other sites
I'm not quite sure I can follow your implementation... 1200 images? where do you draw? why are you comparing y and width (looks like it should be height)?

In any case, although a particle engine is a bit more work (though not much) you'll be able to use it for a wide variety of effects in your game. I'd say it's worth it.

Each particle needs a position (x, y) and a velocity (xVelocity, yVelocity), and each logical frame, the velocity should be applied to the position. You probably won't need the gravity since you're in space, but I threw it in for illustration.

for(... each particle p ...) {    p->x += p->xVelocity;    p->y += p->yVelocity;    p->yVelocity += GRAVITY;}

In a future version, you should multiply the velocity by the time passed since last frame to ensure the particles only moves as much as they ought to.

You should also give each particle a time limit, so they'll disappear after a given time. And you should check to make sure that the particle is visible (something like 0 < x < screenWidth and 0 < y < screenHeight) and kill it if it's not.

##### Share on other sites
or you could do this:

place raindrops(sprites) randomly at the max+(nr of pixels the sprite has) height of the viewport and then let them fall down until they hit the min-(nr of pixels the sprite has) height of the viewport , then place the ones that hit the min back at the max... (or delete them and place others at the max, but this is slower)

that would be a quick replacement for the particle engine... but you should do that in the future if you don't want to code 3d rain or whaterver by hand

1. 1
2. 2
3. 3
Rutin
18
4. 4
JoeJ
14
5. 5

• 14
• 10
• 23
• 9
• 32
• ### Forum Statistics

• Total Topics
632630
• Total Posts
3007526
• ### Who's Online (See full list)

There are no registered users currently online

×