Hardcore Programming Section
Preliminary Particle Systems
 Particle Systems? Particle systems aren't paticularly fun in themselves, but once you start playing with it, you can get some really cool effects cheaply. Here are some examples. Machine Gun That's right, now after all these years in the dark ages, QBRPGs can FINALLY have  machine guns. I think we're all better human beings for this achievement, which we went without for so long. God Bless QB. Bless it. Explosions Ever played Quake? You know all those explosions? Particles and sprites, all of them. What does this mean? It means that we have now progressed to a 1996 level of Explosion kickassity which was unattainable before! Gay-ass magic dots Yeah, I know. Nobody wants gay-ass magic dots. They all say that, but how many modern RPGs have them? They're the biggest waste of resources since the last one, and they're pretty damn gay, but we have to have them to look cool. You can even pair it up with blendermaps to make a groovy(but still gay) glowing particle effect. Exploding PEOPLE! Think about it. Assemble some particles that look like a person, Then tell them to fly apart. WHOAH! HOLY SHIT! THAT GUY JUST BLEW UP! We're living the dream, people. We're living the dream.

A particle system can provide some really cool looking effects at a minimum code cost. In this example, we just have various forms of precipitation.

'In the event your renderer supports transparancy, here we define which number will make it transparant.
CONST particle.transparant = -1
'This number is important because too many will slow the computer down to a crawl, whereas too few will make for an unrealistic effect.
CONST MaxActiveParticles = 1500
DEFINT A-Z

'Here we define what our particle will look like to the computer. Simple, yes?
TYPE particle
x AS INTEGER
y AS INTEGER
active AS INTEGER
colour AS INTEGER '-1 will be transparant
behaviour AS INTEGER
life AS INTEGER
END TYPE

'Here we get all the memory we need for particles.
DIM SHARED particles(1 TO MaxActiveParticles) AS particle

FUNCTION ParticleActiveNumber% () 'This function looks at the current number of particles.
b = 0
FOR a = 1 TO MaxActiveParticles
IF particles(a).active THEN b = b + 1
NEXT a
ParticleActiveNumber% = b
END FUNCTION

SUB ParticleBehave () 'This function tells particles what to do. Right now we have several behaviours basically coming down to "particle go down".
FOR a = 1 TO MaxActiveParticles
IF particles(a).active THEN
SELECT CASE particles(a).behaviour
CASE 1
particles(a).y = particles(a).y + 2
particles(a).life = particles(a).life - 3
CASE 2
particles(a).y = particles(a).y + 3
particles(a).life = particles(a).life - 4
CASE 3
particles(a).y = particles(a).y + 3
particles(a).x = particles(a).x + 1
particles(a).life = particles(a).life - 4
CASE 4
particles(a).y = particles(a).y + 3
particles(a).x = particles(a).x - 1
particles(a).life = particles(a).life - 4
CASE ELSE
particles(a).life = particles(a).life - 1

END SELECT
END IF

NEXT a

END SUB

SUB ParticleClip () 'This removes particles that are off the screen from the bank. This saves CPU time, as non-existant particles don't need to be calculated.
FOR a = 1 TO MaxActiveParticles
IF particles(a).active = 1 THEN
IF (particles(a).x < 0) OR (particles(a).x > 320) OR (particles(a).y < 0) OR (particles(a).y > 240) THEN 'FIXME:change to 240 in the actual engine!
particles(a).active = 0
END IF
IF particles(a).life <= 0 THEN particles(a).active = 0
END IF
NEXT a
END SUB

DEFSNG A-Z
FUNCTION ParticleGetFree% () 'This finds an empty particle space and returns that number.,
x = 1
WHILE (particles(x).active = 1) AND x < MaxActiveParticles: x = x + 1: WEND
ParticleGetFree% = x
END FUNCTION

DEFINT A-Z
SUB ParticleRandomGenerator (colr%, ParticleType%) 'This randomly creates particles based on the ParticleType%.
SELECT CASE ParticleType%
CASE 1
a = ParticleGetFree()
particles(a).x = INT(RND(1) * 320)
particles(a).y = INT(RND(1) * 10)
particles(a).active = 1
particles(a).colour = colr%'INT(RND(1) * 255)
particles(a).behaviour = INT(RND(1) * 4) + 1
particles(a).life = INT(RND(1) * 200) + 120

b = ParticleGetFree()
particles(b).x = particles(a).x
particles(b).y = particles(a).y - 1
particles(b).active = 1
particles(b).colour = colr%
particles(b).behaviour = particles(a).behaviour
particles(b).life = particles(a).life
CASE 2
a = ParticleGetFree()
particles(a).x = INT(RND(1) * 320)
particles(a).y = INT(RND(1) * 10)
particles(a).active = 1
particles(a).colour = colr%'INT(RND(1) * 255)
particles(a).behaviour = INT(RND(1) * 2) + 1
particles(a).life = INT(RND(1) * 200) + 120

b = ParticleGetFree()
particles(b).x = particles(a).x
particles(b).y = particles(a).y - 1
particles(b).active = 1
particles(b).colour = colr%
particles(b).behaviour = particles(a).behaviour
particles(b).life = particles(a).life

END SELECT

END SUB

SUB ParticleRender () 'renders all active particles to the screen.
FOR a = 1 TO MaxActiveParticles
IF particles(a).active THEN
putd particles(a).x, particles(a).y, particles(a).colour
END IF
NEXT a

END SUB

SUB putd(x, y, colr)'I like making a placeholder function called putd in my programs that allows me to plug the code
PSET (x,y), colr     'into a different program by changing one function.
END SUB

-SJ Zero uses particle effects to make people explode! With machine guns! And gay-ass magic dots!.