group1.model.gameobject
Class GameObj

java.lang.Object
  extended by group1.model.gameobject.GameObj
Direct Known Subclasses:
HorizontalMovingPassThruPlatform, Item, 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.
protected  GameObjState myState
          The current state of the object, used to determine animation
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 static double THICKNESS
          The thickness of a standard ObjRegion.
protected  XYPair velocity
          The velocity.
 
Constructor Summary
GameObj()
          Default constructor.
GameObj(double w, double h, boolean moves, PictureList p)
          Constructor, with position defaulted to (0, 0).
GameObj(double x, double y, double w, double h, boolean moves, PictureList p)
          Constructor.
GameObj(double x, double y, PictureList p)
          Standard factory 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.
 boolean equals(java.lang.Object o)
          Whether or not this GameObj and another Object are considered equal.
 XYPair getAcceleration()
          Get the acceleration.
 double getAccelerationX()
          Get the x-component of the acceleration.
 double getAccelerationY()
          Get the y-component of the acceleration.
 java.util.List<java.io.File> getFilm()
          Grabs the film requested based on the object's current State.
 double getHeight()
          Get the height of the object.
 int getID()
          Get the ID.
 int getNumRegions()
          Get the number of regions in this object.
 PictureList getPictureList()
          Accessor for the PictureList.
 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.
 GameObjState getState()
          Accessor for the state.
 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.
 void giveDamage()
          An overridable method that defines exactly what happens to a LivingObj when it gives damage.
 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.
 boolean isSameState(GameObj g)
          Compares the state of this GameObj to the state of another GameObj.
protected  ObjRegion makeBottomSideRegion()
          Make the bottom side of an object, automatically sized and placed based on the size and position of the object.
protected  ObjRegion makeLeftSideRegion()
          Make the left side of an object, automatically sized and placed based on the size and position of the object.
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  ObjRegion makeRightSideRegion()
          Make the right side of an object, automatically sized and placed based on the size and position of the object.
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.
protected  void makeSolidTop()
          A simple function to make the top of the obj "solid" by adding one region.
protected  ObjRegion makeTopSideRegion()
          Make the top side of an object, automatically sized and placed based on the size and position of the object.
abstract  XYPair move(Environment env)
          Ask the object where it wants to move.
protected  void playAudio(Audio a)
          Play a piece of audio by sending it to the game to play an event.
 void resizeBottomRegion(ObjRegion region)
          Automatically resize an object region that is a "bottom" side.
 void resizeLeftRegion(ObjRegion region)
          Automatically resize an object region that is a "left" side.
 void resizeRightRegion(ObjRegion region)
          Automatically resize an object region that is a "right" side.
 void resizeTopRegion(ObjRegion region)
          Automatically resize an object region that is a "top" side.
 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 setPictureList(PictureList p)
          Mutator for the PictureList.
 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.
 void setState(GameObjState s)
          Mutator for the state.
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.
 boolean shouldBeBlinking()
          A special overridable method to inform the view whether or not this object should be "blinking." (The idea is that Jeff should blink while he's invincible.) (As such, this is false for virtually all GameObjs.
 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, 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.


myState

protected GameObjState myState
The current state of the object, used to determine animation


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

THICKNESS

protected static final double THICKNESS
The thickness of a standard ObjRegion.

See Also:
Constant Field Values
Constructor Detail

GameObj

public GameObj()
Default constructor.


GameObj

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

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

GameObj

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

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

GameObj

public GameObj(double x,
               double y,
               PictureList p)
Standard factory constructor. Sets position and the picture list only. Overridable. (And overridden by virtually every object, actually, to set the size and movement correctly.)

Parameters:
x - The x-position.
y - The y-position.
p - The picture list.
Method Detail

move

public abstract XYPair move(Environment env)
Ask the object where it wants to move. Called for every GameObj at each time click.

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.


makeLeftSideRegion

protected ObjRegion makeLeftSideRegion()
Make the left side of an object, automatically sized and placed based on the size and position of the object.

Returns:
The new object region.

makeRightSideRegion

protected ObjRegion makeRightSideRegion()
Make the right side of an object, automatically sized and placed based on the size and position of the object.

Returns:
The new object region.

makeTopSideRegion

protected ObjRegion makeTopSideRegion()
Make the top side of an object, automatically sized and placed based on the size and position of the object.

Returns:
The new object region.

makeBottomSideRegion

protected ObjRegion makeBottomSideRegion()
Make the bottom side of an object, automatically sized and placed based on the size and position of the object.

Returns:
The new object region.

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.


makeSolidTop

protected void makeSolidTop()
A simple function to make the top of the obj "solid" by adding one region. Useful for the quick creation of pass-through platforms.


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.

isSameState

public boolean isSameState(GameObj g)
Compares the state of this GameObj to the state of another GameObj.

Parameters:
g - The second game object.
Returns:
true is they have the same state.

setState

public void setState(GameObjState s)
Mutator for the state.

Parameters:
s - The state enum type.

getState

public GameObjState getState()
Accessor for the state.

Returns:
The state enum type.

setPictureList

public void setPictureList(PictureList p)
Mutator for the PictureList.

Parameters:
p - The picture list.

getPictureList

public PictureList getPictureList()
Accessor for the PictureList.

Returns:
The picture list.

getFilm

public java.util.List<java.io.File> getFilm()
Grabs the film requested based on the object's current State.

Returns:
The "film," a list of files.

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.

resizeTopRegion

public void resizeTopRegion(ObjRegion region)
Automatically resize an object region that is a "top" side.

Parameters:
region - The object region to be resized.

resizeBottomRegion

public void resizeBottomRegion(ObjRegion region)
Automatically resize an object region that is a "bottom" side.

Parameters:
region - The object region to be resized.

resizeLeftRegion

public void resizeLeftRegion(ObjRegion region)
Automatically resize an object region that is a "left" side.

Parameters:
region - The object region to be resized.

resizeRightRegion

public void resizeRightRegion(ObjRegion region)
Automatically resize an object region that is a "right" side.

Parameters:
region - The object region to be resized.

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.


equals

public boolean equals(java.lang.Object o)
Whether or not this GameObj and another Object are considered equal. They are considered equal if their ID values are equal, regardless of any of the (possibly changing) state information of a GameObj. (Overridden at the request of Jeff O.)

Overrides:
equals in class java.lang.Object
Parameters:
o - The Object to compare this GameObj to.
Returns:
Whether or not the Objects are equal.

playAudio

protected void playAudio(Audio a)
Play a piece of audio by sending it to the game to play an event.

Parameters:
a - The audio enum type to be played.

giveDamage

public void giveDamage()
An overridable method that defines exactly what happens to a LivingObj when it gives damage. (Like, does it bounce upward, or disappear, or something?)

Default: Nothing in particular happens.


shouldBeBlinking

public boolean shouldBeBlinking()
A special overridable method to inform the view whether or not this object should be "blinking." (The idea is that Jeff should blink while he's invincible.) (As such, this is false for virtually all GameObjs. We override this in Jeff to let him blink.)

Returns:
true if this GameObj should be blinking, false if not.