From 65812af57a86bef6bfc82bf538a7a2de27eecfc5 Mon Sep 17 00:00:00 2001 From: Phillip Date: Tue, 15 Mar 2011 23:29:59 +0000 Subject: Added failsafe remove in CollidableObject and World classes. Increased the mass of the tank in TankMenuItem ModifyableParticle now spawns 20 DyingParticles when it collides with something. New Class DyingParticle, particle with a duration of 6 ticks. --- src/tesseract/objects/DyingParticle.java | 128 +++++++++++++++++++++++++++++++ 1 file changed, 128 insertions(+) create mode 100644 src/tesseract/objects/DyingParticle.java (limited to 'src/tesseract/objects/DyingParticle.java') diff --git a/src/tesseract/objects/DyingParticle.java b/src/tesseract/objects/DyingParticle.java new file mode 100644 index 0000000..1426293 --- /dev/null +++ b/src/tesseract/objects/DyingParticle.java @@ -0,0 +1,128 @@ +package tesseract.objects; + +import java.awt.Color; + +import javax.media.j3d.Appearance; +import javax.media.j3d.ColoringAttributes; +import javax.media.j3d.Material; +import javax.media.j3d.Shape3D; +import javax.media.j3d.TransformGroup; +import javax.vecmath.Color3f; +import javax.vecmath.Vector3f; + +import com.sun.j3d.utils.geometry.Sphere; + +/** + * A dying particle object. + * + * Particle.java used as code base, parts also taken from ModifyableParticle. + * + * @author Phillip Cardon + * @author Jesse Morgan + */ +public class DyingParticle extends PhysicalObject { + /** + * Rendered radius of particle. + */ + private static final float RADIUS = .001f; + + /** + * Default mass. + */ + private static final float DEFAULT_MASS = .1f; + + /** + * Number of divisions in the sphere. + */ + private static final int DIVISIONS = 8; + private static final int DEFAULT_LIFE = 6; + private TransformGroup myTop; + private TransformGroup myBottom; + + private Shape3D myShape; + + private Color3f myColor; + + private int myLife; + + /** + * Create a new Particle. + * + * @param position Initial position. + * @param color Initial color. Null for random. + */ + public DyingParticle(final Vector3f position, final float mass, final Color3f color, final TransformGroup top, + final TransformGroup bottom) { + super(position, mass); + myTop = top; + myBottom = bottom; + myBottom.addChild(createShape(color)); + myColor = color; + setShape(myTop); + myLife = DEFAULT_LIFE; + } + + /** + * Create a new particle of the give color. + * + * @param theColor The particle color or null for random. + * @return A sphere to visually represent the particle. + */ + private Shape3D createShape(final Color3f theColor) { + + Color3f color = theColor; + + ColoringAttributes cAttr; + + if (color == null) { + Color randomColor = Color.getHSBColor((float) Math.random(), 1, 1); + color = new Color3f(randomColor); + } + /* + cAttr = new ColoringAttributes(color, ColoringAttributes.FASTEST); + Appearance appearance = new Appearance(); + Material mat = new Material(); + mat.setAmbientColor(color); + mat.setDiffuseColor(color); + appearance.setMaterial(mat); + appearance.setColoringAttributes(cAttr); + + Sphere sphere = new Sphere(RADIUS, Sphere.ENABLE_GEOMETRY_PICKING, + DIVISIONS, appearance); + */ + + Sphere sphere = new Sphere(RADIUS, Sphere.ENABLE_GEOMETRY_PICKING, + DIVISIONS); + Shape3D shape = sphere.getShape(); + sphere.removeAllChildren(); + Appearance meshApp = new Appearance(); + Material surface = new Material(); + surface.setDiffuseColor(color); + meshApp.setMaterial(surface); + meshApp.setColoringAttributes(new ColoringAttributes(color, + ColoringAttributes.FASTEST)); + shape.setAppearance(meshApp); + myShape = shape; + myShape.setCapability(Shape3D.ALLOW_APPEARANCE_WRITE); + return shape; + } + + public boolean isDead() { + return myLife <= 0; + } + + public void updateState(float duration) { + if (!isDead()) { + myLife--; + super.updateState(duration); + } else { + super.updateState(duration); + this.detach(); + } + + } + + public void setAcceleration(Vector3f accelerator) { + this.velocity = accelerator; + } +} -- cgit v1.2.3