com.b3dgs.lionengine.game.platform
Class AbstractPlatformEntity<TType extends DefaultTile>

java.lang.Object
  extended by com.b3dgs.lionengine.game.purviews.Configurable
      extended by com.b3dgs.lionengine.game.Entity
          extended by com.b3dgs.lionengine.game.AbstractEntity
              extended by com.b3dgs.lionengine.game.platform.AbstractPlatformEntity<TType>
Type Parameters:
TType - tile type used.
All Implemented Interfaces:
Animator, Collisionable, Mirrorable
Direct Known Subclasses:
AbstractRasteredPlatformEntity

public abstract class AbstractPlatformEntity<TType extends DefaultTile>
extends AbstractEntity
implements Animator

Abstract and standard entity used for platform games. It already support gravity, animation and collisions.


Field Summary
protected  boolean borderLeft
          Borders flag.
protected  boolean borderRight
          Borders flag.
protected  int collOffX
          Collisions special offsets.
protected  int collOffY
          Collisions special offsets.
 Gravity gravity
          Gravity handler.
protected  TileBasedMap<TType> map
          Map reference.
protected  AnimatedSprite sprite
          Animation surface.
 
Fields inherited from class com.b3dgs.lionengine.game.Entity
collisionable, height, mirrorable, width, x, xOld, y, yOld
 
Constructor Summary
AbstractPlatformEntity(PlatformEntrySetup setup)
          Create a new platform entity from an existing, sharing the same surface.
 
Method Summary
 void applyXColl(int x)
          Apply an horizontal collision using the specified blocking x value.
 void applyYColl(int y)
          Apply a vertical collision using the specified blocking y value.
protected  TType checkCollision(int offsetX, int offsetY)
          Return the first hit tile which is flagged as collidable tile.
protected  boolean collisionTest(TType tile)
          Can be overrided in case of specific tiles (ex: collision exception).
 AnimState getAnimState()
          Get current animation state.
 int getFrame()
          Get the current playing frame number.
 float getRealFrame()
          Get the current playing frame with accurate precision.
 AnimatedSprite getSprite()
          Get sprite surface.
 int getXInTile()
          Get location x relative to map referential as tile.
 int getXOldInTile()
          Get old location x relative to map referential as tile.
 int getXOldOnTile(TType tile)
          Get old x value on tile referential (between 0 and tile width).
 int getXOnTile(TType tile)
          Get x value on tile referential (between 0 and tile width).
 int getYInTile()
          Get location y relative to map referential as tile.
 int getYOldInTile()
          Get old location y relative to map referential as tile.
 int getYOldOnTile(TType tile)
          Get old y value on tile referential (between 0 and tile height).
 int getYOnTile(TType tile)
          Get y value on tile referential (between 0 and tile height).
protected abstract  void handleActions(float extrp)
          Update actions, such as moves and attacks.
protected abstract  void handleAnimations()
          Update data, corresponding to a movement.
protected abstract  void handleCollision()
          Update collision, after movements.
protected abstract  void handleInputListener(Keyboard keyboard, Mouse mouse)
          Update input states, listen to inputs changes.
protected abstract  void handleMovement(float extrp)
          Update movement, depending of actions.
 boolean isCheating()
          Get cheating state.
 void play(Animation anim)
          Play the animated sprite with a specific animation, previously created.
 void play(Animation anim, float speed)
          Play the animated sprite with a specific animation, previously created.
 void play(int start, int end, float speed, boolean reverse, boolean repeat)
          Play the animated sprite with a specific animation data.
 void render(java.awt.Graphics2D g, int offsetX, int offsetY)
          Render on screen.
 void render(java.awt.Graphics2D g, PlatformCamera camera)
          Render on screen.
protected  void renderAnim(java.awt.Graphics2D g, AnimatedSprite sprite, PlatformCamera camera)
          Render an animated sprite from the entity location, following camera view point.
protected  void renderAnim(java.awt.Graphics2D g, AnimatedSprite sprite, PlatformCamera camera, int rx, int ry, boolean mirror)
          Render an animated sprite from the entity location, following camera view point.
 void renderCollisions(java.awt.Graphics2D g, PlatformCamera camera)
          Render collisions box area (used as debug).
protected  void setCheatsEnabled(boolean cheats)
          Set cheats state.
 void setFrame(int frame)
          Set a fixed frame (it will overwrite the current animation).
 void setMap(AbstractTileMap<TType> map)
          Set map reference.
 void setSkipLastFrameOnReverse(boolean skip)
          Skip last frame when reverse playing is enable It will directly play the last-1 frame when reversing if set to true.
 void stopAnimation()
          Stop current animation (animation state set to READY).
 void update(Keyboard keyboard, Mouse mouse, float extrp)
          Update routine.
 void updateAnimation(float extrp)
          Deprecated. already called in update(...) function.
protected  void updateGravity(float extrp)
           
 
Methods inherited from class com.b3dgs.lionengine.game.AbstractEntity
getSpeed, getSpeedAdd, getSpeedAddDest, getSpeedDest, getSpeedMax, getSpeedReal, resetAllSpeed, setSize, setSpeed, setSpeedAdd, setSpeedAddDest, setSpeedDest, setSpeedMax, setX, setY
 
Methods inherited from class com.b3dgs.lionengine.game.Entity
backupCoord, cancelMirror, collide, collide, getCancelMirror, getCollision, getHeight, getMirror, getRay, getWidth, getX, getXOld, getXReal, getY, getYOld, getYReal, invertYAxis, mirror, move, place, renderCollision, updateCollision, updateMirror
 
Methods inherited from class com.b3dgs.lionengine.game.purviews.Configurable
checkInstruction, getAnim, getCollArea, getData, getDataBool, getDataInt, getDataString, getRange, loadData
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

gravity

public final Gravity gravity
Gravity handler.


sprite

protected final AnimatedSprite sprite
Animation surface.


map

protected TileBasedMap<TType extends DefaultTile> map
Map reference.


borderLeft

protected boolean borderLeft
Borders flag.


borderRight

protected boolean borderRight
Borders flag.


collOffX

protected int collOffX
Collisions special offsets.


collOffY

protected int collOffY
Collisions special offsets.

Constructor Detail

AbstractPlatformEntity

public AbstractPlatformEntity(PlatformEntrySetup setup)
Create a new platform entity from an existing, sharing the same surface.

Parameters:
setup - entry setup.
Method Detail

update

public void update(Keyboard keyboard,
                   Mouse mouse,
                   float extrp)
Description copied from class: AbstractEntity
Update routine.

Specified by:
update in class AbstractEntity
Parameters:
keyboard - keyboard reference.
mouse - mouse reference.
extrp - extrapolation value.

updateGravity

protected void updateGravity(float extrp)

handleInputListener

protected abstract void handleInputListener(Keyboard keyboard,
                                            Mouse mouse)
Update input states, listen to inputs changes.

Parameters:
keyboard - keyboard reference.
mouse - mouse reference.

handleActions

protected abstract void handleActions(float extrp)
Update actions, such as moves and attacks.

Parameters:
extrp - extrapolation value.

handleMovement

protected abstract void handleMovement(float extrp)
Update movement, depending of actions.

Parameters:
extrp - extrapolation value.

handleCollision

protected abstract void handleCollision()
Update collision, after movements.


handleAnimations

protected abstract void handleAnimations()
Update data, corresponding to a movement.


render

public void render(java.awt.Graphics2D g,
                   int offsetX,
                   int offsetY)
Render on screen.

Parameters:
g - graphic output.
offsetX - horizontal offset.
offsetY - vertical offset.

render

public void render(java.awt.Graphics2D g,
                   PlatformCamera camera)
Render on screen.

Parameters:
g - graphic output.
camera - camera viewpoint.

renderAnim

protected void renderAnim(java.awt.Graphics2D g,
                          AnimatedSprite sprite,
                          PlatformCamera camera)
Render an animated sprite from the entity location, following camera view point.

Parameters:
g - graphics output.
sprite - sprite to render.
camera - camera reference.

renderAnim

protected void renderAnim(java.awt.Graphics2D g,
                          AnimatedSprite sprite,
                          PlatformCamera camera,
                          int rx,
                          int ry,
                          boolean mirror)
Render an animated sprite from the entity location, following camera view point.

Parameters:
g - graphics output.
sprite - sprite to render.
camera - camera reference.
rx - horizontal rendering offset.
ry - vertical rendering offset.
mirror - apply mirror.

renderCollisions

public void renderCollisions(java.awt.Graphics2D g,
                             PlatformCamera camera)
Render collisions box area (used as debug).

Parameters:
g - graphic output.
camera - camera reference.

checkCollision

protected TType checkCollision(int offsetX,
                               int offsetY)
Return the first hit tile which is flagged as collidable tile.

Parameters:
offsetX -
offsetY -
Returns:
first hit tile (ray cast).

collisionTest

protected boolean collisionTest(TType tile)
Can be overrided in case of specific tiles (ex: collision exception).

Parameters:
tile - input tile.
Returns:
true if collision is allowed, false else.

setCheatsEnabled

protected void setCheatsEnabled(boolean cheats)
Set cheats state.

Parameters:
cheats - true will enabled, false will disable.

isCheating

public boolean isCheating()
Get cheating state.

Returns:
cheating state.

setMap

public void setMap(AbstractTileMap<TType> map)
Set map reference.

Parameters:
map - map reference.

getXInTile

public int getXInTile()
Get location x relative to map referential as tile.

Returns:
location x relative to map referential as tile.

getYInTile

public int getYInTile()
Get location y relative to map referential as tile.

Returns:
location y relative to map referential as tile.

getXOldInTile

public int getXOldInTile()
Get old location x relative to map referential as tile.

Returns:
old location x relative to map referential as tile.

getYOldInTile

public int getYOldInTile()
Get old location y relative to map referential as tile.

Returns:
old location y relative to map referential as tile.

getXOnTile

public int getXOnTile(TType tile)
Get x value on tile referential (between 0 and tile width).

Parameters:
tile - tile referential.
Returns:
x value.

getYOnTile

public int getYOnTile(TType tile)
Get y value on tile referential (between 0 and tile height).

Parameters:
tile - tile referential.
Returns:
y value.

getXOldOnTile

public int getXOldOnTile(TType tile)
Get old x value on tile referential (between 0 and tile width).

Parameters:
tile - tile referential.
Returns:
old x value.

getYOldOnTile

public int getYOldOnTile(TType tile)
Get old y value on tile referential (between 0 and tile height).

Parameters:
tile - tile referential.
Returns:
old y value.

applyXColl

public void applyXColl(int x)
Apply an horizontal collision using the specified blocking x value.

Parameters:
x - blocking x value.

applyYColl

public void applyYColl(int y)
Apply a vertical collision using the specified blocking y value.

Parameters:
y - blocking y value.

play

public void play(Animation anim)
Description copied from interface: Animator
Play the animated sprite with a specific animation, previously created.

Specified by:
play in interface Animator
Parameters:
anim - animation reference.

play

public void play(Animation anim,
                 float speed)
Description copied from interface: Animator
Play the animated sprite with a specific animation, previously created. The specified speed will overwrite the default animation speed.

Specified by:
play in interface Animator
Parameters:
anim - animation reference.
speed - specified speed.

play

public void play(int start,
                 int end,
                 float speed,
                 boolean reverse,
                 boolean repeat)
Description copied from interface: Animator
Play the animated sprite with a specific animation data.

Specified by:
play in interface Animator
Parameters:
start - first frame to play.
end - last frame to reach.
speed - specified speed.
reverse - reverse play when end is reached.
repeat - play in loop.

setSkipLastFrameOnReverse

public void setSkipLastFrameOnReverse(boolean skip)
Description copied from interface: Animator
Skip last frame when reverse playing is enable It will directly play the last-1 frame when reversing if set to true.

Specified by:
setSkipLastFrameOnReverse in interface Animator

getFrame

public int getFrame()
Description copied from interface: Animator
Get the current playing frame number.

Specified by:
getFrame in interface Animator
Returns:
current playing frame number.

getRealFrame

public float getRealFrame()
Description copied from interface: Animator
Get the current playing frame with accurate precision.

Specified by:
getRealFrame in interface Animator
Returns:
real frame.

stopAnimation

public void stopAnimation()
Description copied from interface: Animator
Stop current animation (animation state set to READY).

Specified by:
stopAnimation in interface Animator

updateAnimation

@Deprecated
public void updateAnimation(float extrp)
Deprecated. already called in update(...) function.

Description copied from interface: Animator
Animation update routine.

Specified by:
updateAnimation in interface Animator
Parameters:
extrp - extrapolation value.

getAnimState

public AnimState getAnimState()
Description copied from interface: Animator
Get current animation state.

Specified by:
getAnimState in interface Animator
Returns:
animation state (READY, ANIMATING...).
See Also:
AnimState

setFrame

public void setFrame(int frame)
Description copied from interface: Animator
Set a fixed frame (it will overwrite the current animation).

Specified by:
setFrame in interface Animator
Parameters:
frame - frame to set.

getSprite

public AnimatedSprite getSprite()
Get sprite surface.

Returns:
sprite surface.