com.b3dgs.lionengine.game
Class Projectile<TProj extends Projectile<TProj>>

java.lang.Object
  extended by com.b3dgs.lionengine.game.purviews.Configurable
      extended by com.b3dgs.lionengine.game.Entity
          extended by com.b3dgs.lionengine.game.Projectile<TProj>
Type Parameters:
TProj - projectile type.
All Implemented Interfaces:
Animator, Collisionable, Mirrorable

public abstract class Projectile<TProj extends Projectile<TProj>>
extends Entity
implements Animator

Represent an entity which can thrown intances of itself. It already handle all created instance, and garbage collection. Can be used for things like bow, stone, fire...


Field Summary
 Damages damages
          Projectile damages.
protected  AbstractEntry<?,?,?> source
          Entrys references.
protected  AnimatedSprite sprite
          Projectile animation.
protected  AbstractEntry<?,?,?> target
          Entrys references.
 
Fields inherited from class com.b3dgs.lionengine.game.Entity
collisionable, height, mirrorable, width, x, xOld, y, yOld
 
Constructor Summary
  Projectile(java.awt.image.BufferedImage surface, int hframes, int vframes)
          Create a new projectile.
protected Projectile(Projectile<TProj> p)
          Create a new sub projectile, ready to be thrown.
 
Method Summary
protected  void clean()
          Clean projectile before removing it.
protected abstract  TProj createInstance()
          Create a projectile instance.
 AnimState getAnimState()
          Get current animation state.
 int getFrame()
          Get the current playing frame number.
 boolean isAlive()
          Check if projectile is still alive.
 boolean isVisible()
          Check if projectile is visible.
 void launch(AbstractEntry<?,?,?> src, AbstractEntry<?,?,?> tgt)
          Prepare a new projectile to be launched from souce to target.
protected abstract  void onDestoyed()
          Action called when a projectile is destroyed, life's end.
protected abstract  void onHitTarget(AbstractEntry<?,?,?> target)
          Action called when a projectile hit the target.
protected abstract  void onMove()
          Action called when projectile is moving (alive).
 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, Camera camera)
          Render all projectiles on screen.
protected  void renderProjectile(java.awt.Graphics2D g, Camera camera)
          Render a single projectile on screen.
 void setFrame(int frame)
          Set a fixed frame (it will overwrite the current animation).
 void setLifeTime(long time)
          Set projectile life time, in millisecond.
 void setRelativeHit(boolean state)
          True to accept collision even target moved (no dodge).
 void setSize(int width, int height)
          Set projectile size (collision area).
 void setSpeed(float speed)
          Set projectile speed.
 void setVisibility(boolean state)
          Set projectile visibility flag.
 void stopAnimation()
          Stop current animation (animation state set to READY).
protected  void terminate()
          Terminate projectile activity.
 void update(float extrp)
          Update projectiles thrown.
 void updateAnimation(float extrp)
          Animation update routine.
protected  void updateProjectile(float extrp)
          Update thrown projectile routine.
protected  void updateVector()
          Update projectile vector move from source to target.
 
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
 
Methods inherited from interface com.b3dgs.lionengine.drawable.Animator
getRealFrame, setSkipLastFrameOnReverse
 

Field Detail

damages

public final Damages damages
Projectile damages.


sprite

protected final AnimatedSprite sprite
Projectile animation.


source

protected AbstractEntry<?,?,?> source
Entrys references.


target

protected AbstractEntry<?,?,?> target
Entrys references.

Constructor Detail

Projectile

public Projectile(java.awt.image.BufferedImage surface,
                  int hframes,
                  int vframes)
Create a new projectile.

Parameters:
surface - surface reference.
hframes - horizontal frames.
vframes - vertical frames.

Projectile

protected Projectile(Projectile<TProj> p)
Create a new sub projectile, ready to be thrown.

Parameters:
p - projectile main reference.
Method Detail

launch

public void launch(AbstractEntry<?,?,?> src,
                   AbstractEntry<?,?,?> tgt)
Prepare a new projectile to be launched from souce to target.

Parameters:
src - launch source.
tgt - target.

setRelativeHit

public void setRelativeHit(boolean state)
True to accept collision even target moved (no dodge).

Parameters:
state - relative state.

update

public void update(float extrp)
Update projectiles thrown.

Parameters:
extrp - extrapolation value.

render

public void render(java.awt.Graphics2D g,
                   Camera camera)
Render all projectiles on screen.

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

setSpeed

public void setSpeed(float speed)
Set projectile speed.

Parameters:
speed - projectile move speed.

setSize

public void setSize(int width,
                    int height)
Set projectile size (collision area).

Parameters:
width - projectile width.
height - projectile height.

setVisibility

public void setVisibility(boolean state)
Set projectile visibility flag.

Parameters:
state - visibility flag.

isVisible

public boolean isVisible()
Check if projectile is visible.

Returns:
true if visible.

isAlive

public boolean isAlive()
Check if projectile is still alive.

Returns:
true if alive.

setLifeTime

public void setLifeTime(long time)
Set projectile life time, in millisecond.

Parameters:
time - life time.

createInstance

protected abstract TProj createInstance()
Create a projectile instance.

Returns:
created projectile.

terminate

protected void terminate()
Terminate projectile activity.


clean

protected void clean()
Clean projectile before removing it.


updateVector

protected void updateVector()
Update projectile vector move from source to target.


updateProjectile

protected void updateProjectile(float extrp)
Update thrown projectile routine.

Parameters:
extrp - extrapolation value.

renderProjectile

protected void renderProjectile(java.awt.Graphics2D g,
                                Camera camera)
Render a single projectile on screen.

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

onMove

protected abstract void onMove()
Action called when projectile is moving (alive).


onHitTarget

protected abstract void onHitTarget(AbstractEntry<?,?,?> target)
Action called when a projectile hit the target.

Parameters:
target - target hit.

onDestoyed

protected abstract void onDestoyed()
Action called when a projectile is destroyed, life's end.


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.

stopAnimation

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

Specified by:
stopAnimation in interface Animator

updateAnimation

public void updateAnimation(float extrp)
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.

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.