From c96d5df01b431742f88fc6b6618fc9f1f9fea01a Mon Sep 17 00:00:00 2001 From: Jesse Morgan Date: Sat, 5 Mar 2011 22:07:10 +0000 Subject: Added copy constructor to collidableobject so that any collidableobject could become a physical object. --- src/tesseract/World.java | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) (limited to 'src/tesseract/World.java') diff --git a/src/tesseract/World.java b/src/tesseract/World.java index a7d1f85..7953491 100644 --- a/src/tesseract/World.java +++ b/src/tesseract/World.java @@ -48,7 +48,7 @@ public class World implements Observer { /** * A list of the objects in the world. */ - private List myObjects; + private List myObjects; /** * A list of the forces in the world. @@ -96,7 +96,7 @@ public class World implements Observer { myPeer.addObserver(this); myForces = new LinkedList(); - myObjects = new LinkedList(); + myObjects = new LinkedList(); // TODO: Should this go here? myScene = new BranchGroup(); @@ -194,7 +194,7 @@ public class World implements Observer { */ public void tick() { // Iterate over objects in the world. - Iterator itr = myObjects.iterator(); + Iterator itr = myObjects.iterator(); List children = new LinkedList(); @@ -202,22 +202,18 @@ public class World implements Observer { CollidableObject obj = itr.next(); // Apply forces - if (obj instanceof PhysicalObject) { - for (Force force : myForces) { - force.applyForceTo((PhysicalObject) obj); - } + for (Force force : myForces) { + force.applyForceTo((PhysicalObject) obj); } // Update the object's state. obj.updateState(1f / UPDATE_RATE); // Spawn new objects? - if (obj instanceof PhysicalObject) { - List newChildren = - ((PhysicalObject) obj).spawnChildren(1f / UPDATE_RATE); - if (newChildren != null) { - children.addAll(newChildren); - } + List newChildren = + ((PhysicalObject) obj).spawnChildren(1f / UPDATE_RATE); + if (newChildren != null) { + children.addAll(newChildren); } // If it leaves the bounds of the world, DESTROY IT @@ -340,7 +336,7 @@ public class World implements Observer { * * @param obj The object to add */ - public void addObject(final CollidableObject obj) { + public void addObject(final PhysicalObject obj) { myScene.addChild(obj.getGroup()); myObjects.add(obj); } @@ -390,7 +386,7 @@ public class World implements Observer { addObject((PhysicalObject) obj); } else if (obj instanceof CollidableObject) { - addObject((CollidableObject) obj); + addObject(new PhysicalObject((CollidableObject) obj)); } } } -- cgit v1.2.3