Class WeaponAbility

java.lang.Object
com.codename1.gaming.platformer.Ability
com.codename1.gaming.platformer.WeaponAbility

public class WeaponAbility extends Ability

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.

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    int
    Rounds left; negative is unlimited.
    boolean
    Whether the trigger can be held for automatic fire.
    int
    Ticks between shots.
    int
    Damage per hit.
    boolean
    Whether up/down aim the shot diagonally or vertically.
    int
    Gravity on the projectile, 0 for straight shots.
    boolean
    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.
    int
    Ticks a projectile lives (its range).
    The projectile's art type.
    int
    How far a hitscan shot reaches, fixed point.
    int
    Projectile size, fixed point.
    int
    Projectile speed, fixed point per tick; 0 makes a melee weapon.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    long
    hashState(long h)
    Mixes the ability's own state into a hash, so two runs that diverge inside an ability are caught.
    void
    Sets velocity and claims a MovementState.
    void
    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.

    Methods inherited from class Ability

    earlyProcess, isEnabled, lateProcess, mix, setEnabled

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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)
      Description copied from class: Ability

      Sets velocity and claims a MovementState.

      Parameters
      • c: the actor
      • world: the world
      Specified by:
      process in class Ability
    • hashState

      public long hashState(long h)
      Description copied from class: Ability

      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: the running hash
      Returns

      the updated hash

      Overrides:
      hashState in class Ability
    • reset

      public void reset()
      Description copied from class: Ability
      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.
      Overrides:
      reset in class Ability