Sign in to follow this  
3Dgonewild

Weather effects?

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 this post


Link to post
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 this post


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

Share this post


Link to post
Share on other sites
@captain P :
Yea , i know how it sounds , but i wanted to try something different!
(Noob-home made ideas :) ).

@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;//width
if (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 this post


Link to post
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 this post


Link to post
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

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this