Simplest Particles help please

Community Forums/General Help/Simplest Particles help please

David819(Posted 2009) [#1]
Hi,

I'm currently working on developing for the GBA and though i'm still in the early stages of it's capability, I've made an simple program with basic graphics, I'm wanting to add a rain effect to the scene but i've only scrapped the surface of classes in c++ so don't really want to use them, I've searched the code archives and on google trying to find very simple/ messy code for creating rain to reproduce in c++ but i could not find anything that was the simplest way possible, I was wandering if anyone knew where i could get very simple rain code or if someone has some time make a sample of code of a rain emitter (doesn't need to be in c++), and help will be great.
Thank you
Dave


_PJ_(Posted 2009) [#2]
The simplest idea I can imagine for rain, is a 2D effect where the raindrops appear at a random X position along the top of the screen and fall directly down the Y direction - (splashes, presumably optional)

I duno, maybe this is TOO basic for your needs?
a kinda pseudo code thing in Blitz3D:



David819(Posted 2009) [#3]
Hey Malice

Thats pretty much the sort of thing i'm looking for i've implemented it into c++ though it's doesn't quite working properly (i've probably missed something i need to put in), the result i get is a few pixels going down the screen at the same area's (due to the GBA not supporting sRand()) and producing lines over time at those areas, i'm not sure if you can help anymore but my code is as follows for just the rain particles:




markcw(Posted 2009) [#4]
            if( Rain[temp,2] == 149 )

What is that?


David819(Posted 2009) [#5]
The reason for that is to limit the particles to 149 on the Y-Axis.


markcw(Posted 2009) [#6]
Oh, it's the y axis. Heh sorry.


David819(Posted 2009) [#7]
it was my Bad i should of labeled the code better.


_PJ_(Posted 2009) [#8]
My C++ knowledge is pretty slim, hence why I gave an example in Blitz :D but I can see how you're doing the kinda thing I posted, only I've NEVER dealt with graphics in C++ but as it's just 'Plots' it looks pretty logical as to what's what.
To me, though, it does looks like it SHOULD do everything it says on the tin, so yeah not sure what to suggest for now.


hrm... except MAYBE...

PlotPixel16(Rain[temp,1],Rain[temp,2]-5,BGR(0,0,0)); 

Is this actually clearing a trail, or just wiping out a single pixel half way above the latest drawn 'raindrop' ???


_PJ_(Posted 2009) [#9]
Okay I feel a little dumb.
Running the BB version, I notice that

1) It needed a cls, due to black background being transparent (dunno if its relevant in C++)

2) All the drops of course, fall at the same rate and start at the same Y coord, so they look pretty crap when falling as a 'group'

I dunno if there's limitations on Drawing to -Y values or when Y>the screen height, but if you can, then it helps assign a few more randomised values to where the recycled drops get placed on the Y axis (from say -1 to -50 or so?)
and even a greater than screenheight and slightly randomised modifier for WHEN they get recycled?


markcw(Posted 2009) [#10]
Could be a problem with the random function.


David819(Posted 2009) [#11]
I pretty much got it to work srt of now, and added a little direction to the rain aswell but i have to keep the speed at 1 for with the line of code that clears the trail behind each particle doesn't working properly (explanation of that line is that the produced a black pixel behind the particle but it follows the same path behind it and so resets the color of the background to black.). with concerns to the rand() function, that in itself is a problem as developement say that using this command for GBA projects causes slow down so i'm going to have to create my own function to randomly generate a number. apart from that, i want to thanks you both for your help and the experience you've both given me. :D


AJ00200(Posted 2009) [#12]
Maybe get some random numbers, store them in an array, and then cycle through the array pulling out the numbers when you need them.