Class Player
java.lang.Object
core.GameObject
core.Character
entities.player.Player
- All Implemented Interfaces:
Hittable,SpecialAbilityCapable
Represents the player character in the game.
Handles movement, shooting, dashing, and special abilities.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final doubleBullet speed constants.private intCoins collected by the player.private doubleDamage flash alpha for visual feedback.private static final doubleDash cooldownprivate static final doubleMax dashing durationprivate static final doubleDash speedprivate doubleTime tracker for dash cooldownprivate doubleDash indicator (X axis)private doubleDash indicator (Y axis)private doubleCurrent dashing durationprivate booleanDash stateprivate static final longLaser cooldown in milliseconds.private doubleLast laser direction (X).private doubleLast laser direction (Y).private longTime tracker for laser special ability.private longTime tracker for shooting.private StringName of the player.private static javafx.scene.image.ImagePlayer sprite image.private static final doubleShooting cooldown in milliseconds.private static final doubleMovement speed in units per second.Fields inherited from class core.GameObject
x, y -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddCoin(int amount) voidattack()Shoots a bullet in the direction of input keys (Arrow keys).voiddash()Performs a dash in the current movement direction if cooldown allows.intgetCoin()doublegetName()static javafx.scene.image.ImagevoidonDead()Do nothingvoidonHit(int damage) Triggered on hitvoidrender(javafx.scene.canvas.GraphicsContext gc) Renders the player sprite.voidsetCoin(int coin) voidsetDamageFlash(double damageFlash) voidbooleansufficientAmount(int amount) voidupdate(double dt) Updates player movement, dash, and attack state.voiduseCoin(int amount) voidUse special abilityMethods inherited from class core.Character
getDiameter, getHitbox, getHp, getMaxHp, getPower, isAlive, isDead, setAlive, setDiameter, setHp, setMaxHp, setPowerMethods inherited from class core.GameObject
getX, getY, setX, setYMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface core.Hittable
getDiameter, getHitbox, isAlive
-
Field Details
-
name
Name of the player. -
SPEED
private static final double SPEEDMovement speed in units per second.- See Also:
-
BULLET_SPEED
private static final double BULLET_SPEEDBullet speed constants.- See Also:
-
coins
private int coinsCoins collected by the player. -
lastShotTime
private long lastShotTimeTime tracker for shooting. -
shootCooldown
private static final double shootCooldownShooting cooldown in milliseconds.- See Also:
-
lastDirX
private double lastDirXLast laser direction (X). -
lastDirY
private double lastDirYLast laser direction (Y). -
lastLaserTime
private long lastLaserTimeTime tracker for laser special ability. -
LASER_COOLDOWN
private static final long LASER_COOLDOWNLaser cooldown in milliseconds.- See Also:
-
isDashing
private boolean isDashingDash state -
dashTime
private double dashTimeCurrent dashing duration -
DASH_DURATION
private static final double DASH_DURATIONMax dashing duration- See Also:
-
DASH_SPEED
private static final double DASH_SPEEDDash speed- See Also:
-
DASH_COOLDOWN
private static final double DASH_COOLDOWNDash cooldown- See Also:
-
dashCooldownTimer
private double dashCooldownTimerTime tracker for dash cooldown -
dashDirX
private double dashDirXDash indicator (X axis) -
dashDirY
private double dashDirYDash indicator (Y axis) -
PLAYER_SPRITE
private static javafx.scene.image.Image PLAYER_SPRITEPlayer sprite image. -
damageFlash
private double damageFlashDamage flash alpha for visual feedback.
-
-
Constructor Details
-
Player
Constructs a Player object at the specified position with stats.- Parameters:
x- X coordinatey- Y coordinatehp- Initial health pointspower- Attack powername- Player namediameter- Diameter for hitbox renderingcooldown- 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
-
useSpecialAbility
public void useSpecialAbility()Use special ability- Specified by:
useSpecialAbilityin interfaceSpecialAbilityCapable
-
onDead
-
getName
- Returns:
- Player name
-
setName
- 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:
updatein classGameObject- Parameters:
dt- Delta time in seconds
-
render
public void render(javafx.scene.canvas.GraphicsContext gc) Renders the player sprite.- Specified by:
renderin classGameObject- Parameters:
gc- GraphicsContext used for rendering
-