gameobjects.characters
Class AbstractCharacterSprite

java.lang.Object
  extended by com.golden.gamedev.object.Sprite
      extended by com.golden.gamedev.object.AnimatedSprite
          extended by gameobjects.AbstractGameObject
              extended by gameobjects.characters.AbstractCharacterSprite
All Implemented Interfaces:
java.io.Serializable, java.lang.Comparable<AbstractGameObject>
Direct Known Subclasses:
NPCSprite, Player

public abstract class AbstractCharacterSprite
extends AbstractGameObject

This class is holding basic animations that every game character needs.

Author:
Frank Bruns
See Also:
Serialized Form

Field Summary
static int DIR_LEFT
           
static int DIR_NO_DIR
           
static int DIR_RIGHT
           
 
Constructor Summary
AbstractCharacterSprite(java.lang.String name, java.lang.String bshName, double x, double y, java.awt.Color speechColor, com.golden.gamedev.engine.BaseLoader bsLoader, com.golden.gamedev.engine.BaseInput bsInput, com.golden.gamedev.engine.BaseAudio bsSound)
          Creates a new character sprite for a game character
 
Method Summary
 void addAction(AbstractGameAction action)
          Convenience method to add a game action to the characters game action scheduler without calling the getGameActionScheduler() method first.
 void addActions(java.util.List<AbstractGameAction> actions)
          Convenience method to add a list of game actions to the characters game action scheduler at once without calling the getGameActionScheduler() method first.
 int getDirection()
          Returns the current set direction value as a constant like AbstractCharacterSprite.DIR_RIGHT
 GameActionScheduler getGameActionScheduler()
          Returns the game action scheduler
 int getPreviousDirection()
          Return the direction that was set before a new direction was set with setDirection()
 java.awt.Color getSpeechColor()
          Returns the speech color of this character
 double getTargetX()
          Returns the x-coordinate of the sprite's target position
 double getTargetY()
          Returns the y-coordinate of the sprite's target position
 boolean hasJustUsedExit()
          Determines whether the character has just used an exit
 void pause()
          Convenience method that pauses the game action manager of the character
 void render(java.awt.Graphics2D g)
           
 void resume()
          Convenience method that resumes the game action manager of the character
 void setDirection(int dir)
          Sets the current direction to the specified constant.
 void setJustUsedExit(boolean usedExit)
          Sets if the character just used an exit.
 void setTargetPosition(double x, double y)
          Sets the new target position for the character
 void setTargetX(double x)
          Sets the new target x-coordinate for the character
 void setTargetY(double y)
          Sets the new target y-coordinate for the character
 void update(long elapsedTime)
           
 
Methods inherited from class gameobjects.AbstractGameObject
compareTo, getAnimPool, getAnimScheduler, getBshName, getBsLoader, getDescription, getGameLocation, getHotspot, getMidX, getMidY, getName, isPicked, setDescription, setGameLocation, setName, setToPicked
 
Methods inherited from class com.golden.gamedev.object.AnimatedSprite
getAnimationTimer, getFinishAnimationFrame, getFrame, getImage, getImage, getImages, getStartAnimationFrame, isAnimate, isLoopAnim, render, setAnimate, setAnimationFrame, setAnimationTimer, setFrame, setImage, setImages, setLoopAnim
 
Methods inherited from class com.golden.gamedev.object.Sprite
addHorizontalSpeed, addVerticalSpeed, forceX, forceY, getBackground, getDataID, getDistance, getHeight, getHorizontalSpeed, getID, getLayer, getOldX, getOldY, getScreenX, getScreenY, getVerticalSpeed, getWidth, getX, getY, isActive, isImmutable, isOnScreen, isOnScreen, move, moveTo, moveX, moveY, setActive, setBackground, setDataID, setHorizontalSpeed, setID, setImmutable, setLayer, setLocation, setMovement, setSpeed, setVerticalSpeed, setX, setY
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DIR_NO_DIR

public static final int DIR_NO_DIR
See Also:
Constant Field Values

DIR_LEFT

public static final int DIR_LEFT
See Also:
Constant Field Values

DIR_RIGHT

public static final int DIR_RIGHT
See Also:
Constant Field Values
Constructor Detail

AbstractCharacterSprite

public AbstractCharacterSprite(java.lang.String name,
                               java.lang.String bshName,
                               double x,
                               double y,
                               java.awt.Color speechColor,
                               com.golden.gamedev.engine.BaseLoader bsLoader,
                               com.golden.gamedev.engine.BaseInput bsInput,
                               com.golden.gamedev.engine.BaseAudio bsSound)
Creates a new character sprite for a game character

Parameters:
name - Name of the character
bshName - name that will be used for this character in beanshell scripts set to the character at first. Use it like [YourCharacterClass].WALK_LEFT
x - x-coordinate, where the sprite should initially appear
y - y-coordinate, where the sprite should initially appear
speechColor - color for the spoken dialog lines on screen
bsLoader -
bsInput -
bsSound -
Method Detail

setDirection

public void setDirection(int dir)
Sets the current direction to the specified constant. E.g. AbstractCharacterSprite.DIR_LEFT

Parameters:
dir - constant defning the direction of the character

getDirection

public int getDirection()
Returns the current set direction value as a constant like AbstractCharacterSprite.DIR_RIGHT

Returns:
current direction value

getPreviousDirection

public int getPreviousDirection()
Return the direction that was set before a new direction was set with setDirection()

Returns:
direction before the current one

setTargetPosition

public void setTargetPosition(double x,
                              double y)
Sets the new target position for the character

Parameters:
x - x-coordinate
y - y-coordinate

setTargetX

public void setTargetX(double x)
Sets the new target x-coordinate for the character

Parameters:
x - x-coordinate

setTargetY

public void setTargetY(double y)
Sets the new target y-coordinate for the character

Parameters:
y - y-coordinate

getTargetX

public double getTargetX()
Returns the x-coordinate of the sprite's target position

Returns:
x-coordinate of target position

getTargetY

public double getTargetY()
Returns the y-coordinate of the sprite's target position

Returns:
y-coordinate of target position

getSpeechColor

public java.awt.Color getSpeechColor()
Returns the speech color of this character

Returns:
speech color of this character

getGameActionScheduler

public GameActionScheduler getGameActionScheduler()
Returns the game action scheduler

Returns:
game action scheduler

setJustUsedExit

public void setJustUsedExit(boolean usedExit)
Sets if the character just used an exit. This is important to set after using an exit, because the mouse position must not be processed just after using an exit.

Parameters:
usedExit - player just used an exit? --> true=yes, false=no

hasJustUsedExit

public boolean hasJustUsedExit()
Determines whether the character has just used an exit

Returns:
has the player just used an exit? true=yes, false=no

addAction

public void addAction(AbstractGameAction action)
Convenience method to add a game action to the characters game action scheduler without calling the getGameActionScheduler() method first.

Parameters:
action - game action to add to the game action manager

addActions

public void addActions(java.util.List<AbstractGameAction> actions)
Convenience method to add a list of game actions to the characters game action scheduler at once without calling the getGameActionScheduler() method first.

Parameters:
actions - game actions to add to the game action manager

pause

public void pause()
Convenience method that pauses the game action manager of the character


resume

public void resume()
Convenience method that resumes the game action manager of the character


render

public void render(java.awt.Graphics2D g)
Overrides:
render in class AbstractGameObject

update

public void update(long elapsedTime)
Overrides:
update in class AbstractGameObject