gameobjects.characters
Class Player

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
                  extended by gameobjects.characters.Player
All Implemented Interfaces:
java.io.Serializable, java.lang.Comparable<AbstractGameObject>

public class Player
extends AbstractCharacterSprite

This class represents the main character sprite of the game. This character is controlled by the player.

Author:
Frank Bruns
See Also:
Serialized Form

Field Summary
static java.lang.String DIGGING
           
static java.lang.String STANDARD
          Constant that refers to the standard animation of a game object
static java.lang.String TALK
          constant refering to the talking animation
static java.lang.String WAIT
          constant refering to the waiting animation
static java.lang.String WALK_LEFT
          constant refering to the walking left animation
static java.lang.String WALK_RIGHT
          constant refering to the walking right animation
 
Fields inherited from class gameobjects.characters.AbstractCharacterSprite
DIR_LEFT, DIR_NO_DIR, DIR_RIGHT
 
Constructor Summary
Player(java.lang.String name, java.lang.String bshName, double x, double y, java.awt.Color speachColor, com.golden.gamedev.engine.BaseLoader bsLoader, com.golden.gamedev.engine.BaseInput bsInput, com.golden.gamedev.engine.BaseAudio bsSound)
          Creates a new player sprite.
 
Method Summary
 void addDialog(Dialog dialog)
          Adds a dialog to the set of player dialogs
 Dialog getDialog(java.lang.String name)
           
 Item getInventItem()
          Convenience method for simpler use in beanshell scripts to get the player's currently selected inventory item.
 Inventory getInventory()
          Returns the player's inventory containing the collected items
 boolean hasArrivedAtTarget()
          Returns whether the player has arrived at his designated target location.
 boolean hasItem(Item item)
          Convenience method to check if the specified item is contained in the player's inventory
 boolean isInDialog()
          Determines whether the player is currently making conversation
 boolean isLookingAtInventory()
          Convenience method to determine whether the player is currently looking at the inventory
 void loseItem(Item item)
          Convenience method to remove an item from the player's inventory
 void pickItem(Item item)
          Takes an item and adds it to the player's inventory while removing it from the game location it was taken from
 void render(java.awt.Graphics2D g)
           
 void runDialog(java.lang.String dialogName)
          Convenience method to run the dialog for the player
 void setHasArrivedAtTarget(boolean arrived)
          Sets whether the player has arrived at target
 void setIsInDialog(boolean isInDialog)
          Sets the dialog current status of the player
 void update(long elapsedTime)
           
 boolean uses(Item item)
          This method checks, if the currently selected inventory item is equal to the specified item.
 
Methods inherited from class gameobjects.characters.AbstractCharacterSprite
addAction, addActions, getDirection, getGameActionScheduler, getPreviousDirection, getSpeechColor, getTargetX, getTargetY, hasJustUsedExit, pause, resume, setDirection, setJustUsedExit, setTargetPosition, setTargetX, setTargetY
 
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

STANDARD

public static final java.lang.String STANDARD
Constant that refers to the standard animation of a game object

See Also:
Constant Field Values

WAIT

public static final java.lang.String WAIT
constant refering to the waiting animation

See Also:
Constant Field Values

WALK_RIGHT

public static final java.lang.String WALK_RIGHT
constant refering to the walking right animation

See Also:
Constant Field Values

WALK_LEFT

public static final java.lang.String WALK_LEFT
constant refering to the walking left animation

See Also:
Constant Field Values

TALK

public static final java.lang.String TALK
constant refering to the talking animation

See Also:
Constant Field Values

DIGGING

public static final java.lang.String DIGGING
See Also:
Constant Field Values
Constructor Detail

Player

public Player(java.lang.String name,
              java.lang.String bshName,
              double x,
              double y,
              java.awt.Color speachColor,
              com.golden.gamedev.engine.BaseLoader bsLoader,
              com.golden.gamedev.engine.BaseInput bsInput,
              com.golden.gamedev.engine.BaseAudio bsSound)
Creates a new player sprite.

Parameters:
name - Name of the player character
bshName - name that will be used for the player in beanshell scripts. I recommend to simply use "player" as the beanshell name
x - x-coordinate, where the sprite should initially appear
y - y-coordinate, where the sprite should initially appear
speachColor - color for the spoken dialog lines on screen
bsLoader - the BaseLoader object from the Main class
bsSound - the BaseAudio object from the Main class
bsInput - the BaseInput object from the Main class
Method Detail

hasArrivedAtTarget

public boolean hasArrivedAtTarget()
Returns whether the player has arrived at his designated target location.

Returns:
has arrived at target location? --> true=yes, false=no

setHasArrivedAtTarget

public void setHasArrivedAtTarget(boolean arrived)
Sets whether the player has arrived at target

Parameters:
arrived - has arrived? --> true=yes, false=no

getInventory

public Inventory getInventory()
Returns the player's inventory containing the collected items

Returns:
the player's inventory

isLookingAtInventory

public boolean isLookingAtInventory()
Convenience method to determine whether the player is currently looking at the inventory

Returns:
is player looking at inventory? --> true=yes, false=no

isInDialog

public boolean isInDialog()
Determines whether the player is currently making conversation

Returns:
is player making conversation? --> true=yes, false=no

setIsInDialog

public void setIsInDialog(boolean isInDialog)
Sets the dialog current status of the player

Parameters:
isInDialog - is making conversation? --> true=yes, false=no

runDialog

public void runDialog(java.lang.String dialogName)
Convenience method to run the dialog for the player

Parameters:
dialogName - indentifying name of the dialog to apply with the player

addDialog

public void addDialog(Dialog dialog)
Adds a dialog to the set of player dialogs

Parameters:
dialog - the dialog to add

getDialog

public Dialog getDialog(java.lang.String name)

getInventItem

public Item getInventItem()
Convenience method for simpler use in beanshell scripts to get the player's currently selected inventory item. This method returns null, if currently none is selected

Returns:
player's currently selected inventory item, null if none is seleceted

uses

public boolean uses(Item item)
This method checks, if the currently selected inventory item is equal to the specified item.

Parameters:
item - item to check for use
Returns:
does the player currently use the specified item? --> true=yes, false=no

hasItem

public boolean hasItem(Item item)
Convenience method to check if the specified item is contained in the player's inventory

Parameters:
item - item to check for existence in the player's inventory
Returns:
inventory contains the item? --> true=yes, false=no

pickItem

public void pickItem(Item item)
Takes an item and adds it to the player's inventory while removing it from the game location it was taken from

Parameters:
item - item to pick and add to the player's inventory

loseItem

public void loseItem(Item item)
Convenience method to remove an item from the player's inventory

Parameters:
item - item to remove from inventory

update

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

render

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