mhframework
Class MHActor

java.lang.Object
  extended by mhframework.MHActor
All Implemented Interfaces:
MHRenderable
Direct Known Subclasses:
MHPlayingCard

public class MHActor
extends java.lang.Object
implements MHRenderable

Base class for creating interactive or autonomous game actors.


Constructor Summary
MHActor()
          Constructor.
 
Method Summary
 void advance()
          Updates the actor's animation frame number, location, and rotation.
 int getAnimationSequenceNumber()
          Returns the actor's current action, which is also the number of the actor's current animation sequence.
 java.awt.geom.Rectangle2D getBounds()
          Calculates and returns the bounding rectangle for this actor's current sprite image without regard to scaling.
 double getCenterX()
           
 double getCenterY()
           
 int getFrameCount()
           
 int getFrameNumber()
           
 int getFrameTimer()
          Returns the frameTimer.
 int getHealth()
          Returns this actor's current health value
 int getHeight()
           
 double getHorizontalSpeed()
          Returns the horizontal speed value for this actor.
 java.awt.Image getImage()
          Returns current animation frame.
 MHImageGroup getImageGroup()
           
 int getMaxHealth()
          Returns this actor's maximum health value
 double getRotation()
           
 double getRotationSpeed()
           
 double getScale()
           
 java.awt.geom.Rectangle2D getScaledBounds()
          Calculates and returns the bounding rectangle for this actor's current sprite image at its current scale.
 double getSpeed()
           
 double getVerticalSpeed()
          Returns the vertical speed value for this actor.
 int getWidth()
           
 double getX()
          Returns the x coordinate of this actor's left edge
 double getY()
          Returns the y coordinate of this actor's top side
 boolean isAnimationFinished()
           
 void render(java.awt.Graphics2D g)
          Draws the actor onto the sent graphics object based on its current action, animation frame number, and (x, y) coordinates
 void render(java.awt.Graphics2D g, int rx, int ry)
          Draws the actor onto the sent graphics object at the (x, y) coordinates specified by rx and ry.
 void setAnimationSequence(int action)
          Sets the actor's action.
 void setFrameNumber(int frameNumber)
           
 void setFrameTimer(int frameTimer)
          Sets the value of the frame timer.
 void setHealth(int health)
           
 void setHorizontalSpeed(double speed)
          Sets the horizontal movement speed of this actor.
 void setImageGroup(MHImageGroup ig)
          Assigns an existing MHImageGroup to this actor.
 void setLocation(double px, double py)
          Positions the actor at the coordinates specified by the input (x, y) parameters.
 void setMaxHealth(int max)
          Sets the maximum health value for this actor.
 void setRotation(double rotation)
           
 void setRotationSpeed(double rotationSpeed)
           
 void setScale(double scale)
           
 void setSpeed(double speed)
           
 void setVerticalSpeed(double speed)
          Sets the vertical movement speed of this actor.
 void setX(double px)
          Sets the x.
 void setY(double py)
          Sets the y.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MHActor

public MHActor()
Constructor.

Method Detail

setHorizontalSpeed

public void setHorizontalSpeed(double speed)
Sets the horizontal movement speed of this actor.

Parameters:
speed - The number of pixels to move left or right on each iteration of the game loop. A positive input causes the actor to move to the right, and a negative input causes movement to the left.

getHorizontalSpeed

public double getHorizontalSpeed()
Returns the horizontal speed value for this actor.

Returns:
The horizontal speed value for this actor.

getVerticalSpeed

public double getVerticalSpeed()
Returns the vertical speed value for this actor.

Returns:
The vertical speed value for this actor.

setVerticalSpeed

public void setVerticalSpeed(double speed)
Sets the vertical movement speed of this actor.

Parameters:
speed - The number of pixels to move up or down on each iteration of the game loop. A positive input causes the actor to go down, and a negative input causes it to go up.

setMaxHealth

public void setMaxHealth(int max)
Sets the maximum health value for this actor.

Parameters:
max - The maximum health value for this actor

getMaxHealth

public int getMaxHealth()
Returns this actor's maximum health value

Returns:
This actor's maximum health value

getHealth

public int getHealth()
Returns this actor's current health value

Returns:
This actor's current health value

setHealth

public void setHealth(int health)
Parameters:
health - the health to set

render

public void render(java.awt.Graphics2D g)
Draws the actor onto the sent graphics object based on its current action, animation frame number, and (x, y) coordinates

Specified by:
render in interface MHRenderable
Parameters:
g - The Graphics object on which to draw the actor

render

public void render(java.awt.Graphics2D g,
                   int rx,
                   int ry)
Draws the actor onto the sent graphics object at the (x, y) coordinates specified by rx and ry.

Parameters:
g - The Graphics object on which to draw the actor

getImage

public java.awt.Image getImage()
Returns current animation frame.


advance

public void advance()
Updates the actor's animation frame number, location, and rotation. Should usually be overridden by a subclass method which calls this implementation, then proceeds to do any class-specific updates of its own.

Specified by:
advance in interface MHRenderable

setImageGroup

public final void setImageGroup(MHImageGroup ig)
Assigns an existing MHImageGroup to this actor. This set of images will provide the actor's appearance.

Parameters:
ig - A reference to an existing MHImageGroup object.

getImageGroup

public MHImageGroup getImageGroup()

getBounds

public java.awt.geom.Rectangle2D getBounds()
Calculates and returns the bounding rectangle for this actor's current sprite image without regard to scaling.

Returns:
A Rectangle2D object representing this actor's bounding rectangle

getWidth

public int getWidth()

getHeight

public int getHeight()

getScaledBounds

public java.awt.geom.Rectangle2D getScaledBounds()
Calculates and returns the bounding rectangle for this actor's current sprite image at its current scale.

Returns:
A Rectangle2D object representing this actor's scaled bounding rectangle

getCenterX

public double getCenterX()

getCenterY

public double getCenterY()

getFrameTimer

public int getFrameTimer()
Returns the frameTimer.

Returns:
int

getFrameCount

public int getFrameCount()

getX

public double getX()
Returns the x coordinate of this actor's left edge

Returns:
The x coordinate of this actor's left edge

getY

public double getY()
Returns the y coordinate of this actor's top side

Returns:
The y coordinate of this actor's top side

setFrameTimer

public void setFrameTimer(int frameTimer)
Sets the value of the frame timer.

Parameters:
frameTimer - The frameTimer to set

setX

public void setX(double px)
Sets the x.

Parameters:
px - The x to set

setY

public void setY(double py)
Sets the y.

Parameters:
py - The y to set

setLocation

public void setLocation(double px,
                        double py)
Positions the actor at the coordinates specified by the input (x, y) parameters.

Parameters:
px - The x coordinate at which to position the actor
py - The y coordinate at which to position the actor

getAnimationSequenceNumber

public int getAnimationSequenceNumber()
Returns the actor's current action, which is also the number of the actor's current animation sequence.

Returns:
The actor's current action.

setAnimationSequence

public void setAnimationSequence(int action)
Sets the actor's action. The action indicates which animation sequence to perform.

Parameters:
action - The action to set

getFrameNumber

public int getFrameNumber()
Returns:
The number of the actor's current animation frame.

setFrameNumber

public void setFrameNumber(int frameNumber)
Parameters:
frameNumber - The frame number to set.

isAnimationFinished

public boolean isAnimationFinished()

getScale

public double getScale()
Returns:
the scale

setScale

public void setScale(double scale)
Parameters:
scale - the scale to set

getRotation

public double getRotation()

setRotation

public void setRotation(double rotation)

getRotationSpeed

public double getRotationSpeed()

setRotationSpeed

public void setRotationSpeed(double rotationSpeed)

getSpeed

public double getSpeed()
Returns:
the speed

setSpeed

public void setSpeed(double speed)
Parameters:
speed - the speed to set