|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectsimulation_MVC_Basic.ShapeSprite
public class ShapeSprite
This class encapsulates a sprite which is an image (as determined by the File that is passed to the constructor). The sprite's initial position is randomly chosen. The sprite will be drawn partially when it encounters the bottom and right boundaries, but not the top and left boundaries. This sprite has a maximum displacement at each frame in each of the horizontal and vertical dimensions. Each sprite has a associated trajectory, given by x and y displacement values. The sprite knows how to draw itself, given a Graphics2D instance. The sprite is alive until it is hit, then it dies and is no longer shown in the world.
Field Summary | |
---|---|
protected int |
heightOfDrawingRegion
|
protected int |
horizontalDelta
|
protected java.awt.Image |
img
|
protected java.awt.Dimension |
imgDim
|
static java.util.logging.Logger |
logger
|
protected int |
MAX_DIM
|
protected int |
verticalDelta
|
protected int |
widthOfDrawingRegion
|
Constructor Summary | |
---|---|
ShapeSprite(int widthOfDrawingRegion,
int heightOfDrawingRegion,
java.io.File file,
int targetValue)
Creates a sprite within a game world with the specified dimensions. |
Method Summary | |
---|---|
void |
bounceAway()
Causes this sprite to move one unit in the opposite direction of movement biases (defined for the random movements) |
void |
draw(java.awt.Graphics2D g)
The method draws this sprite upon the passed graphics instance. |
void |
explode()
Causes this sprite to explode. |
protected boolean |
getAliveState()
Return this sprite's state with respect to whether it is alive or not. |
java.awt.Point |
getAnchor()
Returns the anchor point of this sprite |
java.awt.geom.Rectangle2D |
getBounds2D()
This method returns a rectangular box that completely encloses this sprite. |
java.awt.Dimension |
getDimension()
Returns the dimension of this sprite |
void |
getNudgedRandomly()
Causes the sprite to get nudged in a random direction. |
int |
getPointsValue()
Returns the points value that is associated with hitting this sprite with a projectile |
boolean |
isCollided(ShapeSprite sprite2)
Returns a boolean value that indicates whether the passed sprite intersects with this sprite. |
boolean |
isCollided(Sprite s)
Determines whether the passed sprite collides with this sprite |
boolean |
isHit()
Returns whether this sprite is in the state of having been hit. |
void |
moveAlongTrajectory()
Causes the sprite to move along its defined trajectory, at its defined magnitude. |
void |
moveToCentre()
Causes the sprite to be relocated to the centre of the game world. |
protected void |
setAliveState(boolean aliveState)
Mutates this sprite's state with respect to whether it is alive or not. |
void |
setAnchor(java.awt.Point newAnchor)
Set the anchor point of this sprite to the passed value |
java.lang.String |
toString()
Generates a string representation of this sprite |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static java.util.logging.Logger logger
protected int widthOfDrawingRegion
protected int heightOfDrawingRegion
protected java.awt.Image img
protected int MAX_DIM
protected java.awt.Dimension imgDim
protected int horizontalDelta
protected int verticalDelta
Constructor Detail |
---|
public ShapeSprite(int widthOfDrawingRegion, int heightOfDrawingRegion, java.io.File file, int targetValue)
widthOfDrawingRegion
- as described aboveheightOfDrawingRegion
- as described abovefile
- as described abovetargetValue
- as described aboveMethod Detail |
---|
public void draw(java.awt.Graphics2D g)
draw
in interface Sprite
g
- public boolean isHit()
public void explode()
protected void setAliveState(boolean aliveState)
protected boolean getAliveState()
public void getNudgedRandomly()
public void moveAlongTrajectory()
public void moveToCentre()
public java.awt.Dimension getDimension()
public java.awt.Point getAnchor()
public void setAnchor(java.awt.Point newAnchor)
public boolean isCollided(ShapeSprite sprite2)
sprite2
- the other sprite
public java.awt.geom.Rectangle2D getBounds2D()
Sprite
getBounds2D
in interface Sprite
public boolean isCollided(Sprite s)
s
- as described above
public void bounceAway()
public java.lang.String toString()
toString
in class java.lang.Object
public int getPointsValue()
Sprite
getPointsValue
in interface Sprite
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |