diff options
author | Jesse Morgan <jesse@jesterpm.net> | 2011-01-28 20:55:28 +0000 |
---|---|---|
committer | Jesse Morgan <jesse@jesterpm.net> | 2011-01-28 20:55:28 +0000 |
commit | f93d4988249f3166329e84699cbaeccd65d16ba8 (patch) | |
tree | 888e9d11b04e061a7cb5f23241c7a0b14921bf56 /src/tesseract/objects/emitters | |
parent | 93bce11072ffec1166606ce981ac508bc7fadce6 (diff) |
Added a shiny new particle emitter.
Diffstat (limited to 'src/tesseract/objects/emitters')
-rw-r--r-- | src/tesseract/objects/emitters/ParticleEmitter.java | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/src/tesseract/objects/emitters/ParticleEmitter.java b/src/tesseract/objects/emitters/ParticleEmitter.java new file mode 100644 index 0000000..de5a556 --- /dev/null +++ b/src/tesseract/objects/emitters/ParticleEmitter.java @@ -0,0 +1,72 @@ +package tesseract.objects.emitters; + +import java.util.LinkedList; +import java.util.List; + +import javax.vecmath.Color3f; +import javax.vecmath.Vector3f; + +import tesseract.objects.Particle; +import tesseract.objects.PhysicalObject; + +/** + * ParticleEmitter Class. + * + * @author Jesse Morgan + */ +public class ParticleEmitter extends PhysicalObject { + + /** + * Frequency of new objects. + */ + private float myFrequency; + + /** + * The object to create... + */ + private Color3f myColor; + + /** + * Counter to keep track of how long has passed. + */ + private float myCount; + + /** + * Construct a new Particle Emitter. + * + * @param position Where to put the emitter + * @param frequency How often to emit the object (seconds). + * @param color Color the particle be (null for random). + */ + public ParticleEmitter(final Vector3f position, final float frequency, + final Color3f color) { + + super(position); + + myCount = 0; + myFrequency = frequency; + myColor = color; + } + + /** + * Update State and maybe generate a new object. + * + * @param duration The length of time that has passed. + * @return A list of new objects to add to the world. + */ + public List<PhysicalObject> updateState(final float duration) { + List<PhysicalObject> children = super.updateState(duration); + + if (children == null) { + children = new LinkedList<PhysicalObject>(); + } + + myCount += duration; + if (myCount >= myFrequency) { + children.add(new Particle(getPosition(), myColor)); + myCount = 0; + } + + return children; + } +} |