Class Player

All Implemented Interfaces:
Hittable, SpecialAbilityCapable

public class Player extends Character implements Hittable, SpecialAbilityCapable
Represents the player character in the game. Handles movement, shooting, dashing, and special abilities.
  • Field Details

    • name

      private String name
      Name of the player.
    • SPEED

      private static final double SPEED
      Movement speed in units per second.
      See Also:
    • BULLET_SPEED

      private static final double BULLET_SPEED
      Bullet speed constants.
      See Also:
    • coins

      private int coins
      Coins collected by the player.
    • lastShotTime

      private long lastShotTime
      Time tracker for shooting.
    • shootCooldown

      private static final double shootCooldown
      Shooting cooldown in milliseconds.
      See Also:
    • lastDirX

      private double lastDirX
      Last laser direction (X).
    • lastDirY

      private double lastDirY
      Last laser direction (Y).
    • lastLaserTime

      private long lastLaserTime
      Time tracker for laser special ability.
    • LASER_COOLDOWN

      private static final long LASER_COOLDOWN
      Laser cooldown in milliseconds.
      See Also:
    • isDashing

      private boolean isDashing
      Dash state
    • dashTime

      private double dashTime
      Current dashing duration
    • DASH_DURATION

      private static final double DASH_DURATION
      Max dashing duration
      See Also:
    • DASH_SPEED

      private static final double DASH_SPEED
      Dash speed
      See Also:
    • DASH_COOLDOWN

      private static final double DASH_COOLDOWN
      Dash cooldown
      See Also:
    • dashCooldownTimer

      private double dashCooldownTimer
      Time tracker for dash cooldown
    • dashDirX

      private double dashDirX
      Dash indicator (X axis)
    • dashDirY

      private double dashDirY
      Dash indicator (Y axis)
    • PLAYER_SPRITE

      private static javafx.scene.image.Image PLAYER_SPRITE
      Player sprite image.
    • damageFlash

      private double damageFlash
      Damage flash alpha for visual feedback.
  • Constructor Details

    • Player

      public Player(double x, double y, int hp, int power, String name, double diameter)
      Constructs a Player object at the specified position with stats.
      Parameters:
      x - X coordinate
      y - Y coordinate
      hp - Initial health points
      power - Attack power
      name - Player name
      diameter - Diameter for hitbox rendering
      cooldown - Attack cooldown in ms
  • Method Details

    • dash

      public void dash()
      Performs a dash in the current movement direction if cooldown allows.
    • attack

      public void attack()
      Shoots a bullet in the direction of input keys (Arrow keys).
    • onHit

      public void onHit(int damage)
      Triggered on hit
      Specified by:
      onHit in interface Hittable
      Parameters:
      damage - damage taken
    • useSpecialAbility

      public void useSpecialAbility()
      Use special ability
      Specified by:
      useSpecialAbility in interface SpecialAbilityCapable
    • onDead

      public void onDead()
      Do nothing
      Specified by:
      onDead in interface Hittable
    • getName

      public String getName()
      Returns:
      Player name
    • setName

      public void setName(String name)
      Parameters:
      name - Sets the player name
    • getDamageFlash

      public double getDamageFlash()
      Returns:
      Current damage flash alpha
    • setDamageFlash

      public void setDamageFlash(double damageFlash)
      Parameters:
      damageFlash - Set damage flash alpha (0-1)
    • getPlayerSprite

      public static javafx.scene.image.Image getPlayerSprite()
      Returns:
      Player sprite image
    • setCoin

      public void setCoin(int coin)
      Parameters:
      coin - Sets player's coins
    • getCoin

      public int getCoin()
      Returns:
      Player's coin count
    • addCoin

      public void addCoin(int amount)
      Parameters:
      amount - Adds coins to player
    • useCoin

      public void useCoin(int amount)
      Parameters:
      amount - Uses coins from player
    • sufficientAmount

      public boolean sufficientAmount(int amount)
      Parameters:
      amount - Check if player has sufficient coins
      Returns:
      true if coins >= amount
    • update

      public void update(double dt)
      Updates player movement, dash, and attack state.
      Specified by:
      update in class GameObject
      Parameters:
      dt - Delta time in seconds
    • render

      public void render(javafx.scene.canvas.GraphicsContext gc)
      Renders the player sprite.
      Specified by:
      render in class GameObject
      Parameters:
      gc - GraphicsContext used for rendering