Package model.entities
Class PlayerModel
java.lang.Object
model.entities.EntityModel
model.entities.PlayerModel
Represents the player character in the game.
This class manages the player's state, movement, actions, and interactions with the game world. It follows the singleton pattern to ensure only one instance of the player exists.
-
Field Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoidaddPoints(int pointsToAdd) booleanChecks if the player can attack.voiddeath()Handles the player's death state.floatintgetFlipW()intgetFlipX()intintstatic PlayerModelReturns the singleton instance of the PlayerModel.booleanintgetLives()intintgetWidth()floatbooleanbooleanisInAir()booleanbooleanisMoving()booleanvoidMakes the player jump on a bubble.voidResets the player's state to the default, including lives and points.voidResets the player's movement values.voidsetAttacking(boolean attacking) voidsetBubbleCadenceMultiplier(float bubbleCadenceMultiplier) voidsetBubbleShotPoints(int bubbleShotPoints) voidsetChacknHeartImmunity(int immunityTime) voidsetInAir(boolean inAir) voidsetJump(boolean jump) voidsetJumpPoints(int jumpPoints) voidsetLeft(boolean left) voidsetRight(boolean right) voidsetSpeedMultiplier(float speedMultiplier) voidsetWalkPoints(int walkPoints) voidupdate()Updates the player's state, including timers and position.Methods inherited from class model.entities.EntityModel
conpenetrationSafeUpdateXPos, deactivate, getHitbox, getTileX, getTileY, initHitbox, initLevelManager, isActive, isImmune, setActive, updateXPos
-
Method Details
-
getInstance
Returns the singleton instance of the PlayerModel.This method ensures that only one instance of the PlayerModel is created (singleton pattern). If the instance is null, it creates a new PlayerModel object and returns it.
- Returns:
- the singleton instance of the PlayerModel
-
update
public void update()Updates the player's state, including timers and position. -
canAttack
public boolean canAttack()Checks if the player can attack.This method determines if the player is able to perform an attack action. The player can attack if they are not respawning, are inside the map boundaries, and are not under a tile roof.
- Returns:
- true if the player can attack, false otherwise
-
jumpOnBubble
public void jumpOnBubble()Makes the player jump on a bubble. -
death
public void death()Handles the player's death state. -
resetMovements
public void resetMovements()Resets the player's movement values. -
reset
Resets the player's state to the default, including lives and points.- Parameters:
resetLives- true to reset the player's lives, false otherwiseresetPoints- true to reset the player's points, false otherwise
-
setAttacking
public void setAttacking(boolean attacking) -
setLeft
public void setLeft(boolean left) -
setRight
public void setRight(boolean right) -
setJump
public void setJump(boolean jump) -
setInAir
public void setInAir(boolean inAir) -
getLives
public int getLives() -
addPoints
public void addPoints(int pointsToAdd) -
getPoints
public int getPoints() -
getXSpeed
public float getXSpeed() -
isJumpActive
public boolean isJumpActive() -
isRespawning
public boolean isRespawning() -
getDirection
-
setSpeedMultiplier
public void setSpeedMultiplier(float speedMultiplier) -
setBubbleCadenceMultiplier
public void setBubbleCadenceMultiplier(float bubbleCadenceMultiplier) -
setChacknHeartImmunity
public void setChacknHeartImmunity(int immunityTime) -
setJumpPoints
public void setJumpPoints(int jumpPoints) -
setWalkPoints
public void setWalkPoints(int walkPoints) -
setBubbleShotPoints
public void setBubbleShotPoints(int bubbleShotPoints) -
getIsJumping
public boolean getIsJumping() -
getImmuneTimer
public int getImmuneTimer() -
getWidth
public int getWidth() -
getHeight
public int getHeight() -
getFlipX
public int getFlipX() -
getFlipW
public int getFlipW() -
isMoving
public boolean isMoving() -
isInAir
public boolean isInAir() -
getAirSpeed
public float getAirSpeed() -
isAttacking
public boolean isAttacking()
-