|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object group1.model.objectregion.ObjRegion
public class ObjRegion
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 |
---|
public static final int SIDE_UNDEFINED
public static final int LEFT_SIDE
public static final int RIGHT_SIDE
public static final int TOP_SIDE
public static final int BOTTOM_SIDE
public static final int NUMBER_OF_SIDE_VALUES
Constructor Detail |
---|
public ObjRegion(java.awt.geom.Rectangle2D newShape, GameObj parentGameObj)
newShape
- the shape of the region.parentGameObj
- a back-pointer to the GameObj inside which this
ObjRegion is to be created.Method Detail |
---|
public GameObj getParentGameObj()
public java.awt.geom.Rectangle2D getShape()
public boolean isSolid()
public boolean passesThroughSolids()
public boolean givesDamage()
public double givesHowMuchDamage()
public boolean takesDamage()
public int getWhichSide()
public void setShape(java.awt.geom.Rectangle2D newShape)
public void setIsSolid(boolean newIsSolid)
public void setHowMuchDamage(double newGivesHowMuchDamage)
public void setToGiveNoDamage()
public void setTakesDamage(boolean newTakesDamage)
public void setPassesThroughSolids(boolean newValue)
public void setWhichSide(int newSide)
public void hitAnotherObject(ObjRegion regionOnOtherObjectBeingHit)
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.
public void stopMyGameObj(ObjRegion regionOnOtherObject)
public void damageMyGameObj(double degreeOfDamage)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |