Class PlayerModel

java.lang.Object
model.entities.EntityModel
model.entities.PlayerModel

public class PlayerModel extends EntityModel
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.

  • Method Details

    • getInstance

      public static PlayerModel 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

      public void reset(Boolean resetLives, Boolean resetPoints)
      Resets the player's state to the default, including lives and points.
      Parameters:
      resetLives - true to reset the player's lives, false otherwise
      resetPoints - 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

      public Constants.Direction 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()