simulation_MVC_Basic
Class ShapeSprite

java.lang.Object
  extended by simulation_MVC_Basic.ShapeSprite

public class ShapeSprite
extends java.lang.Object

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.

Author:
mb

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

logger

public static java.util.logging.Logger logger
Constructor Detail

ShapeSprite

public ShapeSprite(int widthOfDrawingRegion,
                   int heightOfDrawingRegion,
                   java.io.File file)
Creates a sprite within a game world with the specified dimensions.

Parameters:
widthOfDrawingRegion - as described above
heightOfDrawingRegion - as described above
Method Detail

draw

public void draw(java.awt.Graphics2D g)
The method draws this sprite upon the passed graphics instance.

Parameters:
g -

getNudgedRandomly

public void getNudgedRandomly()
Causes the sprite to get nudged in a random direction. There is a direction bias (left/right, up/down), which shifts once the sprite encounters a world boundary.


moveToCentre

public void moveToCentre()
Causes the sprite to be relocated to the centre of the game world.


getDimension

public java.awt.Dimension getDimension()
Returns the dimension of this sprite

Returns:
as described above

getAnchor

public java.awt.Point getAnchor()
Returns the anchor point of this sprite

Returns:
as described above

intersects

public boolean intersects(ShapeSprite sprite2)
Returns a boolean value that indicates whether the passed sprite (sprite2) intersects with this sprite.

Parameters:
sprite2 -
Returns:
as described above