components
Class GameObject

java.lang.Object
  extended by java.awt.event.KeyAdapter
      extended by components.GameObject
All Implemented Interfaces:
ActionListener, KeyListener, EventListener
Direct Known Subclasses:
Absorber, Ball, CircleBumper, Flipper, SquareBumper, TriangleBumper, Wall

public abstract class GameObject
extends KeyAdapter
implements ActionListener

GameObject is the most basic description of an object in gizmo ball. It is mutable and abstract.

Specification Fields

Field Summary
protected  Vect3 center
           
protected  double coRef
           
protected  int delay
           
protected  int depth
           
protected  boolean frozen
           
protected  GameSpace g
           
protected  int height
           
protected  String name
           
protected  Angle orientAngle
           
protected  Vect3 orientVect
           
protected  boolean selected
           
protected  Shape shape
           
protected  Set<GameObject> targets
           
protected  Vect3 velocity
           
protected  boolean visible
           
protected  int width
           
 
Constructor Summary
GameObject(Map<String,String> props, GameSpace gs)
           
GameObject(Vect3 tlf, Vect3 ov, Angle oa, String name, GameSpace g)
           
GameObject(Vect3 tlf, Vect3 velocity, Vect3 ov, Angle oa, String name, GameSpace g)
           
 
Method Summary
 void action()
          Schedules actionPerformed() to happen after this.delay
 void actionPerformed(ActionEvent e)
          This is overriden in objects where something actually occurs when triggered, for example, Flippers
 void addTarget(GameObject obj)
           
 void clearTargets()
           
protected  Map<String,String> defaults()
          sets all the defaults for this class.
 boolean equals(Object go)
           
 void getBasicPropertyMap(Map<String,String> m)
          changes the map to represent the values of this GameObject required by the xml spec
 PhysicsShape getBounds()
           
 Vect3 getCenter()
          get the center of rotation of the object
 double getCoRef()
           
 int getDelay()
           
 int getDepth()
           
 Vect3 getDiff()
          Difference between TLF and center.
 GameSpace getGameSpace()
           
abstract  GameObjectClassification getGOClassification()
          Requires that all obejects return their own classification
 int getHeight()
           
 String getName()
           
 Vect3 getNonRoundedTLF()
          gets the top-left-front corner, no rounding
abstract  Set<Vect3> getOccupiedPositions()
           
 Angle getOrientAngle()
           
 Vect3 getOrientVector()
           
 Vect3 getRoundedTLF()
          convenience method -- getTLF() is rounded
 Shape getShape()
           
 Set<GameObject> getTargets()
           
 Vect3 getTLF()
          gets the top-left-front corner, rounded for double precision things
 Vect3 getVelocity()
           
 int getWidth()
           
 int hashCode()
           
 boolean isFrozen()
           
 boolean isSelected()
           
 boolean isVisible()
           
 void onCollision(GameObject projectile)
           
static void putInVect3(Vect3 v, Map<String,String> m, String title)
          Convience overload of putInVect3, this prevents rounding
static void putInVect3(Vect3 v, Map<String,String> m, String title, boolean round)
          Given a property map, a vector, and a string, adds the keys x + title, y + title, and z + title with the corresponding values from v, to m
 boolean removeTarget(GameObject t)
           
 void setCenter(Vect3 c)
           
 void setCoRef(double coRef)
           
 void setDelay(int d)
           
 void setDepth(int depth)
           
 void setFrozen(boolean frozen)
           
 void setHeight(int height)
           
 void setOrientAngle(Angle newAngle)
           
 void setOrientVect(Vect3 newVect)
           
protected  void setProperty(String s1, String s2)
           
 void setSelected(boolean s)
           
 void setTLF(Vect3 tlf)
          Set the top-left-front corner of the object
 void setVelocity(Vect3 newVel)
           
 void setVisible(boolean visible)
           
 void setWidth(int width)
           
protected abstract  Shape shape()
          the Shape of the object
 void stepFrame()
          This is overriden in mobile objects
 String toString()
          string representation of this object.
 
Methods inherited from class java.awt.event.KeyAdapter
keyPressed, keyReleased, keyTyped
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

g

protected GameSpace g

center

protected Vect3 center

orientVect

protected Vect3 orientVect

orientAngle

protected Angle orientAngle

velocity

protected Vect3 velocity

shape

protected Shape shape

name

protected String name

coRef

protected double coRef

visible

protected boolean visible

frozen

protected boolean frozen

width

protected int width

height

protected int height

depth

protected int depth

delay

protected int delay

targets

protected Set<GameObject> targets

selected

protected boolean selected
Constructor Detail

GameObject

public GameObject(Vect3 tlf,
                  Vect3 ov,
                  Angle oa,
                  String name,
                  GameSpace g)
Effects:
creates a GameObject with zero velocity

GameObject

public GameObject(Map<String,String> props,
                  GameSpace gs)
Effects:
creates a GameObject with zero velocity

GameObject

public GameObject(Vect3 tlf,
                  Vect3 velocity,
                  Vect3 ov,
                  Angle oa,
                  String name,
                  GameSpace g)
Effects:
creates a GameObject
Method Detail

defaults

protected Map<String,String> defaults()
sets all the defaults for this class. override in subclass if you want different defaults must be called at the beginning of the constructor.


setProperty

protected void setProperty(String s1,
                           String s2)
Requires:
string s is a property in this
Effects:
adds this property to this

getDiff

public Vect3 getDiff()
Difference between TLF and center. ZERO for balls, so should be overridden

Returns:
a Vect3 that points from TLF to center. by default this is the center by width, height, depth

shape

protected abstract Shape shape()
the Shape of the object


getTLF

public Vect3 getTLF()
gets the top-left-front corner, rounded for double precision things

Returns:
the position of this object, rounded

getNonRoundedTLF

public Vect3 getNonRoundedTLF()
gets the top-left-front corner, no rounding

Returns:
the TLF in its original form

getRoundedTLF

public Vect3 getRoundedTLF()
convenience method -- getTLF() is rounded

Returns:
the position of this object, rounded

setTLF

public void setTLF(Vect3 tlf)
Set the top-left-front corner of the object

Requires:
tlf != null
Effects:
sets the top left corner of the object

getVelocity

public Vect3 getVelocity()
Returns:
this object's velocity

setVelocity

public void setVelocity(Vect3 newVel)
Requires:
newVel != null
Effects:
sets velocity to newVel
Modifies:
velocity

getGameSpace

public GameSpace getGameSpace()
Returns:
the gamespace this object is in

getName

public String getName()
Returns:
this.name

getCenter

public Vect3 getCenter()
get the center of rotation of the object

Returns:
the center of roation of the object

setCenter

public void setCenter(Vect3 c)
Effects:
changes the center of rotation for the object

getOrientAngle

public Angle getOrientAngle()
Returns:
the orientation angle of the object

setOrientAngle

public void setOrientAngle(Angle newAngle)
Requires:
newAngle != null
Effects:
sets orientAngle to newAngle
Modifies:
orientAngle

getOrientVector

public Vect3 getOrientVector()
Returns:
the orientation vector of the object

setOrientVect

public void setOrientVect(Vect3 newVect)
Requires:
newVect != null
Effects:
sets orientVect to newVect
Modifies:
orientVect

getTargets

public Set<GameObject> getTargets()
Returns:
the targets of this object

addTarget

public void addTarget(GameObject obj)
Requires:
obj != null, obj.gs == this.gs
Effects:
adds obj to targets
Modifies:
targets

clearTargets

public void clearTargets()
Effects:
removes all targets of this
Modifies:
targets

removeTarget

public boolean removeTarget(GameObject t)
Effects:
removes the given target, if present
Modifies:
targets

stepFrame

public void stepFrame()
This is overriden in mobile objects

Effects:
specifies what the GameObject does in a frame

action

public void action()
Schedules actionPerformed() to happen after this.delay


actionPerformed

public void actionPerformed(ActionEvent e)
This is overriden in objects where something actually occurs when triggered, for example, Flippers

Specified by:
actionPerformed in interface ActionListener
Effects:
specifies what the GameObject does when it is triggered.

onCollision

public void onCollision(GameObject projectile)
Effects:
iterates through targets and tell them to perform action()

hashCode

public int hashCode()
Overrides:
hashCode in class Object
Returns:
a valid hash code for this object

equals

public boolean equals(Object go)
Overrides:
equals in class Object
Returns:
go != null && (go instanceof GameObject) && ...

getShape

public Shape getShape()
Returns:
the Shape describing this Object

getBounds

public PhysicsShape getBounds()
Returns:
the bounding shape of this

isVisible

public boolean isVisible()
Returns:
true if the object is visible

setVisible

public void setVisible(boolean visible)
Parameters:
visible - the visible to set

isFrozen

public boolean isFrozen()
Returns:
true if frozen

setFrozen

public void setFrozen(boolean frozen)
Parameters:
frozen - the frozen to set

getBasicPropertyMap

public void getBasicPropertyMap(Map<String,String> m)
changes the map to represent the values of this GameObject required by the xml spec

Modifies:
m

putInVect3

public static void putInVect3(Vect3 v,
                              Map<String,String> m,
                              String title,
                              boolean round)
Given a property map, a vector, and a string, adds the keys x + title, y + title, and z + title with the corresponding values from v, to m

Requires:
no variables passed are null
Modifies:
m, if round is true, puts them in as ints, otherwise as doubles

putInVect3

public static void putInVect3(Vect3 v,
                              Map<String,String> m,
                              String title)
Convience overload of putInVect3, this prevents rounding


getGOClassification

public abstract GameObjectClassification getGOClassification()
Requires that all obejects return their own classification


getOccupiedPositions

public abstract Set<Vect3> getOccupiedPositions()
Returns:
the top left front coner points of all the grid positions occupied by this GameObject

isSelected

public boolean isSelected()
Returns:
whether this GameObject is selected

setSelected

public void setSelected(boolean s)
Effects:
sets selected to s

getDepth

public int getDepth()
Returns:
the depth

setDepth

public void setDepth(int depth)
Parameters:
depth - the depth to set

getHeight

public int getHeight()
Returns:
the height

setHeight

public void setHeight(int height)
Requires:
height > 0
Effects:
sets this.height to height
Modifies:
this.height

getWidth

public int getWidth()
Returns:
the width

setWidth

public void setWidth(int width)
Requires:
width > 0
Effects:
sets this.width to width
Modifies:
this.width

setDelay

public void setDelay(int d)
Requires:
d >= 0
Effects:
sets delay to d
Modifies:
delay

getDelay

public int getDelay()
Returns:
the delay time of this

toString

public String toString()
string representation of this object. ROUNDED coordinates.

Overrides:
toString in class Object

getCoRef

public double getCoRef()
Returns:
the coRef

setCoRef

public void setCoRef(double coRef)
Parameters:
coRef - the coRef to set