group1.model.gameobject
Class GameObj

java.lang.Object
  extended by group1.model.gameobject.GameObj
Direct Known Subclasses:
LivingObj, Projectile, Terrain

public abstract class GameObj
extends java.lang.Object

A generic, abstract object in the game.


Field Summary
protected  XYPair acceleration
          The acceleration.
static int ENEMY_TEAM
          For objects that cause damage to Jeff but not to enemies.
protected static double GRID_SPACE_SIZE
          The standard size of a grid space in the environment this object will be placed in.
protected  int id
          A special ID that represents this object.
protected  boolean isMovable
          Whether or not this object actually moves.
static int JEFF_TEAM
          For objects that cause damage to enemies but not to Jeff.
static int NO_TEAM
          For objects that cause no damage, and for objects that can cause damage to any and all living objects.
protected  java.util.List<ObjRegion> regions
          The list of regions within the object.
protected  java.awt.geom.Rectangle2D shape
          A rectangle representing the position and size of the object.
protected  XYPair velocity
          The velocity.
 
Constructor Summary
GameObj()
          Default constructor.
GameObj(double w, double h, boolean moves)
          Constructor, with position defaulted to (0, 0).
GameObj(double x, double y, double w, double h, boolean moves)
          Constructor.
 
Method Summary
protected  void addRegion(double x, double y, double w, double h)
          Add a region to this object.
protected  void addRegion(ObjRegion newRegion)
          Add a region to this object.
 XYPair getAcceleration()
          Get the acceleration.
 double getAccelerationX()
          Get the x-component of the acceleration.
 double getAccelerationY()
          Get the y-component of the acceleration.
 double getHeight()
          Get the height of the object.
 int getID()
          Get the ID.
 int getNumRegions()
          Get the number of regions in this object.
 XYPair getPosition()
          Get the position of the object.
 double getPositionX()
          Get the x-cooridinate position of the object.
 double getPositionY()
          Get the y-cooridinate position of the object.
 java.awt.geom.Rectangle2D getRectangle()
          Directly get the rectangle representing the placement of this object.
 ObjRegion getRegion(int i)
          Get the i'th region in this object.
 int getTeam()
          Return the team of this object.
 XYPair getVelocity()
          Get the velocity of the object.
 double getVelocityX()
          Get the x-component of the velocity.
 double getVelocityY()
          Get the y-component of the velocity.
 double getWidth()
          Get the width of the object.
 java.util.List<ObjRegion> intersectRegions(java.awt.Shape shape)
          Get the list of all regions that a shape intersects.
 boolean isMovable()
          Get whether or not this object moves.
protected  void makeRegions()
          A simple function to cover the object with 4 regions: a top, a bottom, a left side, and a right side.
protected  void makeSolid()
          A simple function to make the obj "solid" by adding 4 regions to cover the entire object: a top, a bottom, a left side, and a right side.
abstract  XYPair move(Environment env)
          Ask the object where it wants to move.
 void setAcceleration(double x, double y)
          Set the acceleration of the object.
 void setAcceleration(XYPair acc)
          Set the acceleration of the object.
 void setAccelerationX(double x)
          Set the x-component of the acceleration of the object.
 void setAccelerationY(double y)
          Set the y-component of the acceleration of the object.
 void setID(int idNum)
          Set the ID.
 void setPosition(double x, double y)
          Set the position of the object.
 void setPosition(XYPair values)
          Set the position of the object.
 void setPositionX(double x)
          Set the x-position of the object.
 void setPositionY(double y)
          Set the y-position of the object.
 void setRectangle(double x, double y, double w, double h)
          Set the entire rectangle representing this object: position and size.
 void setSize(double w, double h)
          Set the size of the object.
protected  void setTeam(int teamValue)
          Set the team value, to show which objects this one damages.
 void setVelocity(double x, double y)
          Set the velocity of the object.
 void setVelocity(XYPair vel)
          Set the velocity of the object.
 void setVelocityX(double x)
          Set the x-component of the velocity of the object.
 void setVelocityY(double y)
          Set the y-component of the velocity of the object.
 void stopHorizontal()
          Stop horizontal movement, say if it hits a wall.
 void stopVertical()
          Stop vertical movement, say if it hits a floor or ceiling.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

shape

protected java.awt.geom.Rectangle2D shape
A rectangle representing the position and size of the object.


velocity

protected XYPair velocity
The velocity.


acceleration

protected XYPair acceleration
The acceleration.


isMovable

protected boolean isMovable
Whether or not this object actually moves.


GRID_SPACE_SIZE

protected static final double GRID_SPACE_SIZE
The standard size of a grid space in the environment this object will be placed in.

See Also:
Constant Field Values

regions

protected java.util.List<ObjRegion> regions
The list of regions within the object.


id

protected int id
A special ID that represents this object. It is a value unique to each GameObj, useful to the view.


NO_TEAM

public static final int NO_TEAM
For objects that cause no damage, and for objects that can cause damage to any and all living objects.

See Also:
Constant Field Values

JEFF_TEAM

public static final int JEFF_TEAM
For objects that cause damage to enemies but not to Jeff.

See Also:
Constant Field Values

ENEMY_TEAM

public static final int ENEMY_TEAM
For objects that cause damage to Jeff but not to enemies.

See Also:
Constant Field Values
Constructor Detail

GameObj

public GameObj()
Default constructor.


GameObj

public GameObj(double w,
               double h,
               boolean moves)
Constructor, with position defaulted to (0, 0).

Parameters:
w - The width.
h - The height.
moves - Whether or not the object can move.

GameObj

public GameObj(double x,
               double y,
               double w,
               double h,
               boolean moves)
Constructor.

Parameters:
x - The x-position.
y - The y-position.
w - The width.
h - The height.
moves - Whether or not the object can move.
Method Detail

move

public abstract XYPair move(Environment env)
Ask the object where it wants to move.

Parameters:
env - The environment this object is in.
Returns:
The velocities, represented as an X-Y coordinate pair.

intersectRegions

public java.util.List<ObjRegion> intersectRegions(java.awt.Shape shape)
Get the list of all regions that a shape intersects. If the list is empty, no regions were intersected. Likewise, multiple regions may be intersected.

Parameters:
shape - The shape intersecting this object. (Typically, just a rectangle, but it can technically be anything.)
Returns:
The list of intersected regions within the object.

getRegion

public ObjRegion getRegion(int i)
Get the i'th region in this object.

Parameters:
i - The index of the region in the list.
Returns:
The i'th ObjRegion.

getNumRegions

public int getNumRegions()
Get the number of regions in this object.

Returns:
The number of ObjRegions.

addRegion

protected void addRegion(double x,
                         double y,
                         double w,
                         double h)
Add a region to this object.

Parameters:
x - The x-position.
y - The y-position.
w - The width.
h - The height.

addRegion

protected void addRegion(ObjRegion newRegion)
Add a region to this object.

Parameters:
newRegion - The object region.

setTeam

protected void setTeam(int teamValue)
Set the team value, to show which objects this one damages.

Parameters:
teamValue - The team value: NO_TEAM, JEFF_TEAM, or ENEMY_TEAM.

makeRegions

protected void makeRegions()
A simple function to cover the object with 4 regions: a top, a bottom, a left side, and a right side. Useful for the quick creation of any object that generically needs to interact with other objects.


makeSolid

protected void makeSolid()
A simple function to make the obj "solid" by adding 4 regions to cover the entire object: a top, a bottom, a left side, and a right side. Useful for the quick creation of a solid rectangular block, such as terrain blocks.


stopHorizontal

public void stopHorizontal()
Stop horizontal movement, say if it hits a wall.


stopVertical

public void stopVertical()
Stop vertical movement, say if it hits a floor or ceiling.


isMovable

public boolean isMovable()
Get whether or not this object moves.

Returns:
whether or not this object moves.

getPositionX

public double getPositionX()
Get the x-cooridinate position of the object.

Returns:
The x-coordinate position.

getPositionY

public double getPositionY()
Get the y-cooridinate position of the object.

Returns:
The y-coordinate position.

getPosition

public XYPair getPosition()
Get the position of the object.

Returns:
The position, represented as an x-y coordinate pair.

getWidth

public double getWidth()
Get the width of the object.

Returns:
The width.

getHeight

public double getHeight()
Get the height of the object.

Returns:
The height.

getRectangle

public java.awt.geom.Rectangle2D getRectangle()
Directly get the rectangle representing the placement of this object.

Returns:
The rectangle.

getVelocityX

public double getVelocityX()
Get the x-component of the velocity.

Returns:
The x-component of the velocity.

getVelocityY

public double getVelocityY()
Get the y-component of the velocity.

Returns:
The y-component of the velocity.

getVelocity

public XYPair getVelocity()
Get the velocity of the object.

Returns:
The velocity, represented as an X-Y coordinate pair.

getAccelerationX

public double getAccelerationX()
Get the x-component of the acceleration.

Returns:
The x-component of the acceleration.

getAccelerationY

public double getAccelerationY()
Get the y-component of the acceleration.

Returns:
The y-component of the acceleration.

getAcceleration

public XYPair getAcceleration()
Get the acceleration.

Returns:
The acceleration, represented as a XY-coordinate pair.

setID

public void setID(int idNum)
Set the ID.

Parameters:
idNum - The ID.

getID

public int getID()
Get the ID.

Returns:
The ID.

setPositionX

public void setPositionX(double x)
Set the x-position of the object.

Parameters:
x - The x-position.

setPositionY

public void setPositionY(double y)
Set the y-position of the object.

Parameters:
y - The y-position.

setPosition

public void setPosition(double x,
                        double y)
Set the position of the object.

Parameters:
x - The x-position.
y - The y-position.

setPosition

public void setPosition(XYPair values)
Set the position of the object.

Parameters:
values - The XY-coordinate pair.

setSize

public void setSize(double w,
                    double h)
Set the size of the object.

Parameters:
w - The width.
h - The height.

setRectangle

public void setRectangle(double x,
                         double y,
                         double w,
                         double h)
Set the entire rectangle representing this object: position and size.

Parameters:
x - The x-position.
y - The y-position.
w - The width.
h - The height.

setVelocityX

public void setVelocityX(double x)
Set the x-component of the velocity of the object.

Parameters:
x - The x-component of the velocity.

setVelocityY

public void setVelocityY(double y)
Set the y-component of the velocity of the object.

Parameters:
y - The y-component of the velocity.

setVelocity

public void setVelocity(double x,
                        double y)
Set the velocity of the object.

Parameters:
x - The x-component of the velocity.
y - The y-component of the velocity.

setVelocity

public void setVelocity(XYPair vel)
Set the velocity of the object.

Parameters:
vel - The velocity, represented as a coordinate pair.

setAccelerationX

public void setAccelerationX(double x)
Set the x-component of the acceleration of the object.

Parameters:
x - The x-component of the acceleration.

setAccelerationY

public void setAccelerationY(double y)
Set the y-component of the acceleration of the object.

Parameters:
y - The y-component of the acceleration.

setAcceleration

public void setAcceleration(double x,
                            double y)
Set the acceleration of the object.

Parameters:
x - The x-component of the acceleration.
y - The y-component of the acceleration.

setAcceleration

public void setAcceleration(XYPair acc)
Set the acceleration of the object.

Parameters:
acc - The acceleration, represented as a coordinate pair.

getTeam

public int getTeam()
Return the team of this object. This value determines which objects are damaged by which other objects. Values are final static public ints in this class. (Default == "NO_TEAM".) returns The team value.