com.b3dgs.lionengine.game.strategy
Class AbstractEntry<TTile extends AbstractPathTile,TSkill extends AbstractSkill<TTile,TSkill,TAttr>,TAttr extends AbstractAttributes>

java.lang.Object
  extended by com.b3dgs.lionengine.game.purviews.Configurable
      extended by com.b3dgs.lionengine.game.Entity
          extended by com.b3dgs.lionengine.game.strategy.AbstractEntry<TTile,TSkill,TAttr>
Type Parameters:
TTile - tile type used.
TSkill - skill type used.
TAttr - attributes type used.
All Implemented Interfaces:
Animator, Collisionable, Mirrorable
Direct Known Subclasses:
AbstractBuilding, AbstractUnit

public abstract class AbstractEntry<TTile extends AbstractPathTile,TSkill extends AbstractSkill<TTile,TSkill,TAttr>,TAttr extends AbstractAttributes>
extends Entity
implements Animator

This class represent the first abstraction for any kind of object which can be used in a strategy game. It contains a set of useful functions, a specific ID, a ready to use animated sprite, and a list of attributes. Entry data are automaticaly loaded, from the file data. It requires theses minimum instructions:

 =RNG= #FRAMES#   = {start-end}
 =INT= #ICON#       = (value)
 =INT= #WIDTH#    = (size)
 =INT= #HEIGHT#   = (size)
 =INT= #OFFSET_X# = (value) // horizontal gfx offset
 =INT= #OFFSET_Y# = (value) // vertical gfx offset
 =INT= #MAX_LIFE# = (value)
 

See Also:
AnimatedSprite, AbstractAttributes

Field Summary
 Animation anim
          Current playing animation.
protected  java.lang.String animName
          Current anim name.
 TAttr attr
          Entry attributes.
 int icon
          Entry icon number.
 int id
          Entry id.
protected  AbstractEntry<TTile,TSkill,TAttr> lastAttacker
          Last attacker reference.
 Alterable life
          Entry life.
 PathBasedMap<TTile> map
          Map reference.
protected  int offsetX
          Entry location offset.
protected  int offsetY
          Entry location offset.
protected  AnimatedSprite sprite
          Animation surface.
 
Fields inherited from class com.b3dgs.lionengine.game.Entity
collisionable, height, mirrorable, width, x, xOld, y, yOld
 
Constructor Summary
AbstractEntry(java.lang.String data, PathBasedMap<TTile> map, java.awt.image.BufferedImage surface, TAttr attr)
          Create a new entry.
 
Method Summary
 void addSkill(TSkill skill)
          Link skill to the entry.
 void applyOrder(AbstractEntry<TTile,TSkill,TAttr> target)
          Apply choice from control panel by setting target and call skill action.
 void applyOrder(int dx, int dy)
          Apply choice from control panel by setting destination and call skill action.
 AnimState getAnimState()
          Get current animation state.
 int getDistance(AbstractEntry<TTile,TSkill,TAttr> entry)
          Get distance in tile between the specified entry.
 int getDistance(int tx, int ty, int tw, int th)
          Get distance in tile between the area.
 int getFieldOfView()
          Get field of view value (in tile).
 int getFrame()
          Get the current playing frame number.
 int getHeight()
          Get entry height (it may not be the collision area, it is only the real size).
 int getHeightInTile()
          Get entry height int tile.
 int getLayer()
          Get current layer value.
 int getLayerOld()
          Get last layer value, before changes.
 TSkill getOrderedSkill()
          Get ordered skill reference.
 int getOwnerID()
          Get owner id (player id owning this entry).
 float getRealFrame()
          Get the current playing frame with accurate precision.
 TSkill getSkill(java.lang.String name)
          Get a skill from its id.
 java.util.Collection<TSkill> getSkills()
          Get all skills as collection (iterable).
 int getWidth()
          Get entry width (it may not be the collision area, it is only the real size).
 int getWidthInTile()
          Get entry width in tile.
 int getXInTile()
          Get horizontal tile location.
 int getXOffset()
          Get horizontal offset (used in case of rendering).
 int getYInTile()
          Get vertical tile location.
 int getYOffset()
          Get vertical offset (used in case of rendering).
 boolean hasChangedLayer()
          Check if layer has be changed.
 boolean isActive()
          Check if entry is active.
 boolean isAlive()
          Check if entry is alive.
 boolean isOver()
          Check if entry is currently over a cursor (hit by a cursor).
 boolean isRemoved()
          Check if entry is still existing.
 boolean isSelected()
          Check if entry is currently selected (hit by a cursor selection).
 boolean isUnselected()
          Check if entry has just been unselected.
 boolean isVisible()
          Check if entry is visible.
 void onHit(AbstractEntry<TTile,TSkill,TAttr> attacker)
          Action called when entry is hiting another one.
abstract  void onKilled(AbstractEntry<TTile,TSkill,TAttr> attacker)
          Action called when entry is killed by another one.
 void onOrdered(TSkill skill)
          Action called when entry applyed an order (action selected from control panel).
abstract  void onOrderedFail(TSkill skill)
          Action called when entry order failed.
abstract  void onSelection()
          Action called when entry is selected (in case of a single selection).
 void place(int tx, int ty)
          Set specific location in tile.
 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 remove()
          Remove entry from world, and free memory.
protected  void removeRef()
          Remove any map ref for this entry, arround its size.
 void removeSkill(java.lang.String name)
          Remove a skill.
 void render(java.awt.Graphics2D g, Camera camera)
          Render entry on screen depending of the camera.
 void setActive(boolean state)
          Set active state (false to cancel update).
 void setAlive(boolean state)
          Set alive state.
 void setAnimation(java.lang.String anim)
          Change animation by a new one from its name.
 void setFieldOfView(int fov)
          Set field of view value (in tile).
 void setFrame(int frame)
          Set a fixed frame (it will overwrite the current animation).
 void setLayer(int layer)
          Define a layer number, used for rendering priority.
 void setLayerChanged(boolean state)
          Set layer changes state.
 void setOrderedSkill(TSkill skill)
          Set reference from chosen skill in control panel.
 void setOver(boolean state)
          Set over state (used with cursor selection, to apply cursor over effect).
 void setOwnerID(int id)
          Set owner id (player id owning this entry).
 void setSelection(boolean state)
          Set selection state (used with cursor selection, to give an order).
 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 setVisibility(boolean state)
          Set visibility state.
 void stopAnimation()
          Stop current animation (animation state set to READY).
 void unselect()
          This will unselect entry.
 void update(Keyboard keyboard, Mouse mouse, float extrp)
          Main routine, has to be called in a game loop.
 void updateAnimation(float extrp)
          Deprecated. already called in main loop. Has to be called only on specific cases.
 
Methods inherited from class com.b3dgs.lionengine.game.Entity
backupCoord, cancelMirror, collide, collide, getCancelMirror, getCollision, getMirror, getRay, getX, getXOld, getXReal, getY, getYOld, getYReal, invertYAxis, mirror, move, 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

attr

public final TAttr extends AbstractAttributes attr
Entry attributes.


life

public final Alterable life
Entry life.


id

public final int id
Entry id. Reference can be found by using AbstractEntry.get(id)


icon

public final int icon
Entry icon number.


map

public final PathBasedMap<TTile extends AbstractPathTile> map
Map reference.


sprite

protected final AnimatedSprite sprite
Animation surface.


anim

public final Animation anim
Current playing animation.


offsetX

protected int offsetX
Entry location offset.


offsetY

protected int offsetY
Entry location offset.


animName

protected java.lang.String animName
Current anim name.


lastAttacker

protected AbstractEntry<TTile extends AbstractPathTile,TSkill extends AbstractSkill<TTile,TSkill,TAttr>,TAttr extends AbstractAttributes> lastAttacker
Last attacker reference.

Constructor Detail

AbstractEntry

public AbstractEntry(java.lang.String data,
                     PathBasedMap<TTile> map,
                     java.awt.image.BufferedImage surface,
                     TAttr attr)
Create a new entry.

Parameters:
data - entry data file path.
map - map reference.
surface - building image file path.
attr - attributes reference.
Method Detail

update

public void update(Keyboard keyboard,
                   Mouse mouse,
                   float extrp)
Main routine, has to be called in a game loop.

Parameters:
keyboard - keyboard reference.
mouse - mouse reference.
extrp - extrapolation value.

render

public void render(java.awt.Graphics2D g,
                   Camera camera)
Render entry on screen depending of the camera.

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

removeRef

protected void removeRef()
Remove any map ref for this entry, arround its size.


setLayer

public void setLayer(int layer)
Define a layer number, used for rendering priority. Layer number has to be between 0 and 3 included. 0 is rendered firstly, 3 is rendered lastly. Changes can be done only one time, until a call to setLayerChanged(false).

Parameters:
layer - layer number [0-3].

getLayer

public int getLayer()
Get current layer value.

Returns:
current layer value.

getLayerOld

public int getLayerOld()
Get last layer value, before changes.

Returns:
last layer value.

setLayerChanged

public void setLayerChanged(boolean state)
Set layer changes state. After a call to setLayer(), it is automatically set to true. It has to be set to false when changes are done.

Parameters:
state -

hasChangedLayer

public boolean hasChangedLayer()
Check if layer has be changed.

Returns:
changed state.

place

public void place(int tx,
                  int ty)
Set specific location in tile.

Overrides:
place in class Entity
Parameters:
tx - horizontal tile location.
ty - vertical tile location.

getXInTile

public int getXInTile()
Get horizontal tile location.

Returns:
horizontal tile location.

getYInTile

public int getYInTile()
Get vertical tile location.

Returns:
vertical tile location.

getXOffset

public int getXOffset()
Get horizontal offset (used in case of rendering).

Returns:
horizontal rendering offset.

getYOffset

public int getYOffset()
Get vertical offset (used in case of rendering).

Returns:
vertical rendering offset.

getWidth

public int getWidth()
Get entry width (it may not be the collision area, it is only the real size).

Overrides:
getWidth in class Entity
Returns:
entry width.

getHeight

public int getHeight()
Get entry height (it may not be the collision area, it is only the real size).

Overrides:
getHeight in class Entity
Returns:
entry height.

getWidthInTile

public int getWidthInTile()
Get entry width in tile.

Returns:
entry width.

getHeightInTile

public int getHeightInTile()
Get entry height int tile.

Returns:
entry height.

getDistance

public int getDistance(int tx,
                       int ty,
                       int tw,
                       int th)
Get distance in tile between the area.

Parameters:
tx - tile x.
ty - tile y.
tw - width in tile.
th - height in tile.
Returns:
number of tiles between them.

getDistance

public int getDistance(AbstractEntry<TTile,TSkill,TAttr> entry)
Get distance in tile between the specified entry.

Parameters:
entry - entry to check.
Returns:
number of tiles between them.

setFieldOfView

public void setFieldOfView(int fov)
Set field of view value (in tile).

Parameters:
fov - field of view.

getFieldOfView

public int getFieldOfView()
Get field of view value (in tile).

Returns:
field of view 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

setAnimation

public void setAnimation(java.lang.String anim)
Change animation by a new one from its name.

Parameters:
anim - animation name.

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.

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.

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

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 main loop. Has to be called only on specific cases.

Description copied from interface: Animator
Animation update routine.

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

addSkill

public void addSkill(TSkill skill)
Link skill to the entry.

Parameters:
skill - skill to add.

getSkill

public TSkill getSkill(java.lang.String name)
Get a skill from its id.

Parameters:
name - skill name.
Returns:
skill found.

removeSkill

public void removeSkill(java.lang.String name)
Remove a skill.

Parameters:
name - skill name.

getSkills

public java.util.Collection<TSkill> getSkills()
Get all skills as collection (iterable).

Returns:
all skills.

setSelection

public void setSelection(boolean state)
Set selection state (used with cursor selection, to give an order).

Parameters:
state - state.

setOver

public void setOver(boolean state)
Set over state (used with cursor selection, to apply cursor over effect).

Parameters:
state - state.

isSelected

public boolean isSelected()
Check if entry is currently selected (hit by a cursor selection).

Returns:
true if selected, false else.

unselect

public void unselect()
This will unselect entry.


isUnselected

public boolean isUnselected()
Check if entry has just been unselected.

Returns:
unselected state.

isOver

public boolean isOver()
Check if entry is currently over a cursor (hit by a cursor).

Returns:
true if over, false else.

setActive

public void setActive(boolean state)
Set active state (false to cancel update).

Parameters:
state - active state.

isActive

public boolean isActive()
Check if entry is active.

Returns:
true if active, false else.

setVisibility

public void setVisibility(boolean state)
Set visibility state.

Parameters:
state - visibility state.

isVisible

public boolean isVisible()
Check if entry is visible.

Returns:
visibility state.

setOwnerID

public void setOwnerID(int id)
Set owner id (player id owning this entry).

Parameters:
id - owner id.

getOwnerID

public int getOwnerID()
Get owner id (player id owning this entry).

Returns:
owner id.

setAlive

public void setAlive(boolean state)
Set alive state.

Parameters:
state - alive state.

isAlive

public boolean isAlive()
Check if entry is alive.

Returns:
true if alive.

isRemoved

public boolean isRemoved()
Check if entry is still existing.

Returns:
true if existing.

remove

public void remove()
Remove entry from world, and free memory.


setOrderedSkill

public void setOrderedSkill(TSkill skill)
Set reference from chosen skill in control panel.

Parameters:
skill - chosen skill in control panel.

getOrderedSkill

public TSkill getOrderedSkill()
Get ordered skill reference.

Returns:
ordered skill reference.

applyOrder

public void applyOrder(int dx,
                       int dy)
Apply choice from control panel by setting destination and call skill action.

Parameters:
dx - horizontal map tile location.
dy - vertical map tile location.

applyOrder

public void applyOrder(AbstractEntry<TTile,TSkill,TAttr> target)
Apply choice from control panel by setting target and call skill action.

Parameters:
target - target reference.

onSelection

public abstract void onSelection()
Action called when entry is selected (in case of a single selection).


onOrdered

public void onOrdered(TSkill skill)
Action called when entry applyed an order (action selected from control panel).

Parameters:
skill - ordered skill

onOrderedFail

public abstract void onOrderedFail(TSkill skill)
Action called when entry order failed.

Parameters:
skill - ordered skill

onHit

public void onHit(AbstractEntry<TTile,TSkill,TAttr> attacker)
Action called when entry is hiting another one.

Parameters:
attacker - attacker reference.

onKilled

public abstract void onKilled(AbstractEntry<TTile,TSkill,TAttr> attacker)
Action called when entry is killed by another one.

Parameters:
attacker - attacker reference.