jplay
Class Sprite

java.lang.Object
  extended by jplay.GameObject
      extended by jplay.GameImage
          extended by jplay.Animation
              extended by jplay.Sprite

public class Sprite
extends Animation

Class responsible for controlling all actions and behaviors of sprite.


Field Summary
 
Fields inherited from class jplay.GameObject
height, width, x, y
 
Constructor Summary
Sprite(java.lang.String fileName)
          Constructor of the class.
Sprite(java.lang.String fileName, int numFrames)
          Constructor of the class.
 
Method Summary
 void fall()
          This method simulates the gravity.
 int getFloor()
          Return the value the current floor.
 double getGravity()
          Returns the value used for gravity.
 double getJumpVelocity()
          Returns the velocity of jump.
 boolean isJumping()
          Returns true if the sprite is executing the jump, false otherwise.
 boolean isOnFloor()
          Returns true if the sprite is on the floor, false otherwise.
 void jump()
          Makes the sprite jump.
 void jump(int jumpKey)
          Makes the sprite jump.
 void moveTo(double x, double y, double velocity)
          Moves the sprite from a point to another.
 void moveX(double velocity)
          Method used to move the sprite by the x-axis.
 void moveX(int leftKey, int rightKey, double velocity)
          Method used to move the sprite by the x-axis.
 void moveY(double velocity)
          Method used to move the sprite by y-axis.
 void moveY(int upKey, int downKey, double velocity)
          Method used to move the sprite by y-axis.
 void setFloor(int floor)
          Sets the floor that will be used for the methods jump or fall.
 void setGravity(double gravity)
          Sets the value for gravity.
 void setJumpVelocity(double velocity)
          Sets the jump velocity for the sprite.
 
Methods inherited from class jplay.Animation
draw, getCurrFrame, getDuration, getFinalFrame, getInitialFrame, getTotalDuration, hide, isLooping, isPlaying, pause, play, setCurrFrame, setDuration, setFinalFrame, setInitialFrame, setLoop, setSequence, setSequence, setSequenceTime, setSequenceTime, setTotalDuration, stop, unhide, update
 
Methods inherited from class jplay.GameImage
loadImage
 
Methods inherited from class jplay.GameObject
collided
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Sprite

public Sprite(java.lang.String fileName)
Constructor of the class. Creates a class with one frame.

Parameters:
fileName - Path of the file.

Sprite

public Sprite(java.lang.String fileName,
              int numFrames)
Constructor of the class.

Parameters:
fileName - Path of the file.
numFrames - number of frames.
Method Detail

moveX

public void moveX(double velocity)
Method used to move the sprite by the x-axis. The keys used to move the sprite are LEFT_KEY and RIGHT_KEY.

Parameters:
velocity - speed of locomotion in pixels.

moveX

public void moveX(int leftKey,
                  int rightKey,
                  double velocity)
Method used to move the sprite by the x-axis.

Parameters:
leftKey - Key used to move the sprite for the left.
rightKey - Key used to move the sprite for the right.
velocity - speed of locomotion in pixels.

moveY

public void moveY(double velocity)
Method used to move the sprite by y-axis. The keys used to move the sprite are UP_KEY and DOWN_KEY.

Parameters:
velocity - speed of locomotion in pixels.

moveY

public void moveY(int upKey,
                  int downKey,
                  double velocity)
Method used to move the sprite by y-axis.

Parameters:
upKey - Key used to move the sprite for the left.
downKey - Key used to move the sprite for the right.
velocity - speed of locomotion in pixels.

moveTo

public void moveTo(double x,
                   double y,
                   double velocity)
Moves the sprite from a point to another.

Parameters:
x - Target point on the x axis.
y - Target point on the y axis.
velocity - speed of locomotion in pixels.

setFloor

public void setFloor(int floor)
Sets the floor that will be used for the methods jump or fall.

Parameters:
floor - Value of the coordinate x.

getFloor

public int getFloor()
Return the value the current floor.

Returns:
int

jump

public void jump(int jumpKey)
Makes the sprite jump.

Parameters:
jumpKey - key used to start the jump.

jump

public void jump()
Makes the sprite jump. The key used is SPACE_KEY (SPACE_BAR).


isJumping

public boolean isJumping()
Returns true if the sprite is executing the jump, false otherwise. return boolean


fall

public void fall()
This method simulates the gravity. It's necessary sets the floor before call this method.


isOnFloor

public boolean isOnFloor()
Returns true if the sprite is on the floor, false otherwise.

Returns:
boolean

setJumpVelocity

public void setJumpVelocity(double velocity)
Sets the jump velocity for the sprite. This velocity is used to control the height of jump.

Parameters:
velocity - speed of locomotion in pixels.

getJumpVelocity

public double getJumpVelocity()
Returns the velocity of jump.

Returns:
double

getGravity

public double getGravity()
Returns the value used for gravity.

Returns:
double

setGravity

public void setGravity(double gravity)
Sets the value for gravity.

Parameters:
gravity -