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 WeaponAbility

  1. Object
  2. Ability
  3. WeaponAbility

Firing on Input#FIRE: projectiles (a blaster, a bow) or a melee swing, with a cooldown, optional ammunition and eight-way aiming from the held directions.

A melee weapon (speed 0) is a short-lived projectile that does not move, placed in front of the actor, so one mechanism covers both.

Fields

public String projectileTypeThe projectile’s art type.
public int speedProjectile speed, fixed point per tick; 0 makes a melee weapon.
public int sizeProjectile size, fixed point.
public int gravityGravity on the projectile, 0 for straight shots.
public int damageDamage per hit.
public int cooldownTicksTicks between shots.
public int lifeTicksTicks a projectile lives (its range).
public int ammoRounds left; negative is unlimited.
public boolean eightWayWhether up/down aim the shot diagonally or vertically.
public boolean automaticWhether the trigger can be held for automatic fire.
public boolean hitscanWhether the shot is instant (a laser, a rifle): it travels range in the tick it is fired, stops at the first solid tile and hits the first actor of another team on the way.
public int rangeHow far a hitscan shot reaches, fixed point.

Constructors

public WeaponAbility()

Methods

public void process(Actor c, PlatformWorld world)Sets velocity and claims a MovementState.
public long hashState(long h)Mixes the ability’s own state into a hash, so two runs that diverge inside an ability are caught.
public void reset()Forgets what the ability was in the middle of, when its actor respawns: a dash, a buffered jump or a grip does not outlive a death.

Inherited methods

Field details

projectileType

public String projectileType
The projectile’s art type.

speed

public int speed
Projectile speed, fixed point per tick; 0 makes a melee weapon.

size

public int size
Projectile size, fixed point.

gravity

public int gravity
Gravity on the projectile, 0 for straight shots.

damage

public int damage
Damage per hit.

cooldownTicks

public int cooldownTicks
Ticks between shots.

lifeTicks

public int lifeTicks
Ticks a projectile lives (its range).

ammo

public int ammo
Rounds left; negative is unlimited.

eightWay

public boolean eightWay
Whether up/down aim the shot diagonally or vertically.

automatic

public boolean automatic
Whether the trigger can be held for automatic fire.

hitscan

public boolean hitscan
Whether the shot is instant (a laser, a rifle): it travels range in the tick it is fired, stops at the first solid tile and hits the first actor of another team on the way. No projectile is made.

range

public int range
How far a hitscan shot reaches, fixed point.

Constructor details

WeaponAbility

public WeaponAbility()

Method details

process

public void process(Actor c, PlatformWorld world)
Sets velocity and claims a MovementState.

Parameters

c Actor
the actor
world PlatformWorld
the world

hashState

public long hashState(long h)
Mixes the ability’s own state into a hash, so two runs that diverge inside an ability are caught. The default mixes nothing.

Parameters

h long
the running hash

Returns

the updated hash

reset

public void reset()
Forgets what the ability was in the middle of, when its actor respawns: a dash, a buffered jump or a grip does not outlive a death. The default does nothing; an ability with per-run state overrides it.