|
|||||||||
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. The maximum displacement at each frame is 5 units in each of the horizontal and vertical dimensions. The sprite has a random movement behaviour defined for it (moving to the left/right and up/down a randomly-chosen number of units). The sprite knows how to draw itself, given a Graphics2D instance.
Field Summary | |
---|---|
static java.util.logging.Logger |
logger
|
Constructor Summary | |
---|---|
ShapeSprite(int widthOfDrawingRegion,
int heightOfDrawingRegion,
java.io.File file)
Creates a sprite within a game world with the specified dimensions. |
Method Summary | |
---|---|
void |
draw(java.awt.Graphics2D g)
The method draws this sprite upon the passed graphics instance. |
java.awt.Point |
getAnchor()
Returns the anchor point of this sprite |
java.awt.Dimension |
getDimension()
Returns the dimension of this sprite |
void |
getNudgedRandomly()
Causes the sprite to get nudged in a random direction. |
boolean |
intersects(ShapeSprite sprite2)
Returns a boolean value that indicates whether the passed sprite (sprite2) intersects with this sprite. |
void |
moveToCentre()
Causes the sprite to be relocated to the centre of the game world. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static java.util.logging.Logger logger
Constructor Detail |
---|
public ShapeSprite(int widthOfDrawingRegion, int heightOfDrawingRegion, java.io.File file)
widthOfDrawingRegion
- as described aboveheightOfDrawingRegion
- as described aboveMethod Detail |
---|
public void draw(java.awt.Graphics2D g)
g
- public void getNudgedRandomly()
public void moveToCentre()
public java.awt.Dimension getDimension()
public java.awt.Point getAnchor()
public boolean intersects(ShapeSprite sprite2)
sprite2
-
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |