Examples:
- One miserable explosion particle:
this is more like a textured "bullet" ...
- Same control as previously, except ...
- Button-A: shoots a fire ball
- ExplosionParticle class: has AI!? no!!
-
A Simple Finite State Machine: in this case, so simple it is not
worth mentioning ...
-
mTimeLeft dies when this goes to zero
-
mDeltaRadius decreases the radius as time left decreases
-
mAcceleration accelerates as time left decreases (explosion
particle accelerates)
-
Notice: RANDOM is king here!! Apply randomness to anything
and everything we can think of.
-
Update() function simply updates the particle, and tells
itself to die (by removing from auto draw set).
-
Think, subclass, think a class hierarchy of
particles, behavior are all different, with different textures, and
different acceleration, different traveling paths, but with all the
identical Update() and HasDied() behavior!
- BUT THIS IS BORING!
- A particle manager:
a "manager" (system) that is capable of generating a collection of particles
at a time ...
- Same control as previously, except LargeBall is not under user control.
- Button-A: shoots a circular of fire balls
- Button-B: shoots the fire balls from LargeBall towards SmallBall,
cool?
- ExplosionSystem class: has a list of ExplosionParticle (think a list of
"generic" particles)
-
Update() iterates through all existing particles in the list,
update each, and remove all expired ones.
-
CreateParticles: simple random -1, +1 directions (circular
pattern)
-
CreateParticles: with preference towards a particular
direction and a spread angle. Remember vector components?
-
it is useful eh?
- Think: ParticleSystem should has a list of "generic" particles
rather than specific kinds of particles!
- STILL BORING! because all particles were shot out at the same time!
- Emitter with a state:
we need a particle creation system with a "state machine" ...
- Same controls as previous, except we have abstract out the Emitter
class.
- Emitter hierarchy of classes:
- Base class: has a Position and knows how many it can emits (think
about an emitter that emits non-stop!, why not?)
- EmitteParticles(): each time calls, sends out "some"
of the particles, until non-left
- CreateParticles(): this is pure virtual, have no idea
actually how to create a particle!
- CircularEmitter: overrides the CreateParticle() function,
sends n-particle randomly in circular direction
- DirectionalEmitter overrides the CreateParticle() function,
sends n-particle in the preferred direction with spread. Ineresting ponits:
- During construction, saves all run-time variable (e.g., Tan-spread) for optimization.
- Abstraction with ParticleBase class:
now, separate out the ParticleSystem and Emitter classes from Particle
class.
- Similar control as previously, except
- Button-X: emits particles from three fix locations (think
about emitters that emits particles constantly!)
- Also, we have a new type of particles now: SineParticle: semi-transparent
circles that follows a sine wave,
- A, B, and X buttons alternates between the ExplosionParticle and
SineParticle
- Main Point: ParticleBase class:
- Base class: Subclass form circle, has life time, and knows how
to shrink itself.
- Update(): updates the life, determines if particle should
die, and shrink the circle.
- Define data type for creation of ParticleBase: ParticleCreator
this is a "function pointer" data type that knows how to create a
particle.
- Derived classes: subclasses overrides the Update() method to
modify/refine behavior, and MUST define/implement appropriate methods
for ParticleCreator:
- ExplosionParticle class: Update() causes acceleration to
the particles. Define: CreateAnExplosionParticle
function for ParticleCreator purpose.
- SineParticle class: Update() causes each particle to
follow a fixed sine path. Defines: CreateASineParticle
function for ParticleCreator purpose.
- Now, notice Emitter and ParticleSystem only work with
ParticleBase, these two management classes have no idea what are
the details of the particles they are managing (that is why we can emit
either Sine or Explosion particles from the same emitter and same
system).
- Look at ClassExample.cs: when A, B, or X button is
pushed, we detetrmines which of the ParticleCreator function to use for
creating new emitter, either CreateAnExplosionParticle or
CreateASineParticle.
- Object-oriented software is really cool, eh?