group1.model.objectregion
Class ObjRegion

java.lang.Object
  extended by group1.model.objectregion.ObjRegion

public class ObjRegion
extends java.lang.Object

ObjRegion represents a physical region within a GameObj. Its primary feature is a Shape object, which the Environment class uses to perform hit detection. ObjRegion also has properties including solidity (impassibility) and how the region gives or takes damage.

A GameObj can have multiple ObjRegion's, and it is presumably responsible for updating the Shape's in its ObjRegion's with current position information. The suggested regions for a game object are one covering the left side, one covering the right side, one covering the top, and one covering the bottom. If this arrangement is used, define which side each region represents using the member methods for best results.


Field Summary
static int BOTTOM_SIDE
          Specifies that this region is on the bottom side of the game object.
static int LEFT_SIDE
          Specifies that this region is on the left side of the game object.
static int NUMBER_OF_SIDE_VALUES
          Number of valid game object side specification options.
static int RIGHT_SIDE
          Specifies that this region is on the right side of the game object.
static int SIDE_UNDEFINED
          Specifies that the side of the game object that the region is on is undefined.
static int TOP_SIDE
          Specifies that this region is on the top side of the game object.
 
Constructor Summary
ObjRegion(java.awt.geom.Rectangle2D newShape, GameObj parentGameObj)
          Constructs a new region inside a game object.
 
Method Summary
 void damageMyGameObj(double degreeOfDamage)
          Defines what happens after this ObjRegion receives damage.
 GameObj getParentGameObj()
          Navigates back to the GameObj that contains this ObjRegion.
 java.awt.geom.Rectangle2D getShape()
          Returns the shape of this ObjRegion.
 int getWhichSide()
          Returns the specified side of the GameObj that this ObjRegion is on.
 boolean givesDamage()
          Returns true if this object gives damage, else false.
 double givesHowMuchDamage()
          Returns the amount of damage that this object gives to objects that it hits.
 void hitAnotherObject(ObjRegion regionOnOtherObjectBeingHit)
          This method defines exactly what happens when this ObjRegion hits another ObjRegion.
 boolean isSolid()
          Returns true if the object is impassable by another object, false if it is passable.
 boolean passesThroughSolids()
          Returns true if the object passes through object regions for which isSolid() is true, else false.
 void setHowMuchDamage(double newGivesHowMuchDamage)
          Set the amount of damage that this object gives to objects that it hits.
 void setIsSolid(boolean newIsSolid)
          Changes the solidity status.
 void setPassesThroughSolids(boolean newValue)
          Change whether this region passes through solids.
 void setShape(java.awt.geom.Rectangle2D newShape)
          Changes the shape of the ObjRegion.
 void setTakesDamage(boolean newTakesDamage)
          Change whether this region receives damage to the game object.
 void setToGiveNoDamage()
          Make this object give no damage.
 void setWhichSide(int newSide)
          Change the side of the GameObj that this ObjRegion is on.
 void stopMyGameObj(ObjRegion regionOnOtherObject)
          Stops this ObjRegion's GameObj.
 boolean takesDamage()
          Returns true if this object takes damage, else false.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SIDE_UNDEFINED

public static final int SIDE_UNDEFINED
Specifies that the side of the game object that the region is on is undefined.

See Also:
Constant Field Values

LEFT_SIDE

public static final int LEFT_SIDE
Specifies that this region is on the left side of the game object.

See Also:
Constant Field Values

RIGHT_SIDE

public static final int RIGHT_SIDE
Specifies that this region is on the right side of the game object.

See Also:
Constant Field Values

TOP_SIDE

public static final int TOP_SIDE
Specifies that this region is on the top side of the game object.

See Also:
Constant Field Values

BOTTOM_SIDE

public static final int BOTTOM_SIDE
Specifies that this region is on the bottom side of the game object.

See Also:
Constant Field Values

NUMBER_OF_SIDE_VALUES

public static final int NUMBER_OF_SIDE_VALUES
Number of valid game object side specification options.

See Also:
Constant Field Values
Constructor Detail

ObjRegion

public ObjRegion(java.awt.geom.Rectangle2D newShape,
                 GameObj parentGameObj)
Constructs a new region inside a game object.

Parameters:
newShape - the shape of the region.
parentGameObj - a back-pointer to the GameObj inside which this ObjRegion is to be created.
Method Detail

getParentGameObj

public GameObj getParentGameObj()
Navigates back to the GameObj that contains this ObjRegion.


getShape

public java.awt.geom.Rectangle2D getShape()
Returns the shape of this ObjRegion.


isSolid

public boolean isSolid()
Returns true if the object is impassable by another object, false if it is passable.


passesThroughSolids

public boolean passesThroughSolids()
Returns true if the object passes through object regions for which isSolid() is true, else false.


givesDamage

public boolean givesDamage()
Returns true if this object gives damage, else false. This method will return false if this object gives 0.0 units of damage, else true.


givesHowMuchDamage

public double givesHowMuchDamage()
Returns the amount of damage that this object gives to objects that it hits.


takesDamage

public boolean takesDamage()
Returns true if this object takes damage, else false.


getWhichSide

public int getWhichSide()
Returns the specified side of the GameObj that this ObjRegion is on. The values to use are SIDE_UNDEFINED, LEFT_SIDE, RIGHT_SIDE, TOP_SIDE, and BOTTOM_SIDE, all constants defined in ObjRegion.


setShape

public void setShape(java.awt.geom.Rectangle2D newShape)
Changes the shape of the ObjRegion.


setIsSolid

public void setIsSolid(boolean newIsSolid)
Changes the solidity status. Set true to make the object impassable by other objects; set false to make it passable.


setHowMuchDamage

public void setHowMuchDamage(double newGivesHowMuchDamage)
Set the amount of damage that this object gives to objects that it hits.


setToGiveNoDamage

public void setToGiveNoDamage()
Make this object give no damage. This sets the amount of damage given to 0.0 and causes givesDamage() to return false.


setTakesDamage

public void setTakesDamage(boolean newTakesDamage)
Change whether this region receives damage to the game object.


setPassesThroughSolids

public void setPassesThroughSolids(boolean newValue)
Change whether this region passes through solids.


setWhichSide

public void setWhichSide(int newSide)
Change the side of the GameObj that this ObjRegion is on. The values to use are SIDE_UNDEFINED, LEFT_SIDE, RIGHT_SIDE, TOP_SIDE, and BOTTOM_SIDE, all constants defined in ObjRegion.


hitAnotherObject

public void hitAnotherObject(ObjRegion regionOnOtherObjectBeingHit)
This method defines exactly what happens when this ObjRegion hits another ObjRegion. Environment's hit detector is supposed to call this method whenever this ObjRegion is found to conflict with another ObjRegion.

NOTE: Hit detector may call either collider's hitAnotherObject method, so we want some symmetry between effects on this ObjectRegion and the other.

ANOTHER NOTE: Environment's HIT DETECTOR SHOULD WATCH OUT NOT TO CALL HIT DETECTION TWICE ON THIS PAIR! This means that if this method is called on this ObjRegion, then don't call it again on the ObjRegion referred to by argument regionOnOtherObjectBeingHit, OR YOU MAY DOUBLE THE DAMAGE (e.g. 6 hit points deducted from Jeff when only 3 are supposed to be deducted). SUGGESTION: First identify all pairs of conflicting ObjRegion's, then for each pair, choose ONE ObjRegion and call this method.

THIRD NOTE: This method recognizes the concept of "teams" of GameObj's, where objects on the same team don't damage each other, except if both objects are on GameObj.NO_TEAM, in which case the concept of "teams" can be neglected and damage still happens.


stopMyGameObj

public void stopMyGameObj(ObjRegion regionOnOtherObject)
Stops this ObjRegion's GameObj. Depending on the side of the GameObj that this ObjRegion is on, the object may only stop horizontally or stop vertically. For example, if the GameObj collides with a wall, then it should still be able to slide down. If the side of this ObjRegion is undefined, then the GameObj stops both horizontally and vertically.


damageMyGameObj

public void damageMyGameObj(double degreeOfDamage)
Defines what happens after this ObjRegion receives damage. The classic behavior is that the containing GameObj loses hit points.