Client and backend. This class is shared: the same code is compiled into your app and into your server, so everything on this page works in both.

public class Projectile

  1. Object
  2. LevelEntity
  3. Projectile
A bullet, arrow or fireball: flies at a fixed velocity, optionally falls, and damages the first actor of another team it touches. It disappears on a solid tile, on a hit, or when its range runs out.

Constructors

public Projectile(String id, String type, int x, int y, int size, int vx, int vy, int gravity, int team, int damage, int lifeTicks)Creates a projectile.

Methods

public int getVx()The horizontal speed, which the view uses to flip the sprite.
public void step(PlatformWorld world)Advances one tick.
public void onTouch(PlatformWorld world, Actor c)Called each tick a living actor overlaps the entity.
public long hashState(long h)Mixes the entity’s play-relevant state into a hash.

Inherited fields

From LevelEntity

x, y, w, h

Inherited methods

Constructor details

Projectile

public Projectile(String id, String type, int x, int y, int size, int vx, int vy, int gravity, int team, int damage, int lifeTicks)
Creates a projectile.

Parameters

id String
the id
type String
the kind, for the art ("bullet", "arrow", "slash")
x int
left, fixed point
y int
top, fixed point
size int
width and height, fixed point
vx int
horizontal speed, fixed point per tick
vy int
vertical speed, fixed point per tick
gravity int
downward acceleration, 0 for a straight shot
team int
the shooter’s team; it never hurts its own
damage int
hit points removed on a hit
lifeTicks int
ticks before it expires

Method details

getVx

public int getVx()
The horizontal speed, which the view uses to flip the sprite.

Returns

the speed, fixed point per tick

step

public void step(PlatformWorld world)
Advances one tick. The default does nothing.

Parameters

world PlatformWorld
the world

onTouch

public void onTouch(PlatformWorld world, Actor c)
Called each tick a living actor overlaps the entity.

Parameters

world PlatformWorld
the world
c Actor
the actor

hashState

public long hashState(long h)
Mixes the entity’s play-relevant state into a hash. The default mixes the position and whether it is active.

Parameters

h long
the running hash

Returns

the updated hash