Constructs a new Player.
The player's mesh (can be null, will be loaded by the factory).
The Babylon.js scene.
Accepts a visitor (not used in this implementation).
Adds an observer to the player (not used in this implementation).
Adds a sound effect to the player.
The sound name.
The StaticSound instance.
Applies a knockback impulse to the player, usually after taking damage.
Applies damage to the player, triggers knockback and state change.
The amount of damage to apply.
Returns the current HP of the player.
Returns the unique ID of the player.
Returns the maximum HP of the player.
Returns the main mesh of the player.
Returns all meshes associated with the player.
Returns the Babylon.js scene.
Returns the type of the object ("player").
Returns whether the player is alive.
Checks if the player is currently on the ground.
True if grounded, false otherwise.
Makes the player jump by applying an upward impulse.
Kills the player, sets HP to 0, and plays the death sound.
Moves the player using physics based on input and delta time.
Delta time.
The current input state.
Handles contact events (not used for player).
Always false.
Handles logic when the game is paused.
Handles logic when the game is resumed.
Plays a sound effect by name.
The sound name.
Removes the physics body from the player.
Sets the unique ID of the player.
The new ID.
Handles taking damage using the player's damage state.
The amount of damage to apply.
Updates the player's state machine and damage state.
Delta time.
The current input state.
Player represents the main controllable character in the game.
Responsibilities:
Usage:
move(dt, input)
to move the player based on input.jump()
to make the player jump.takeDamage(damage)
to apply damage and trigger state changes.update(dt, input)
in the game loop to update player state.isAlive()
andkill()
to manage player life state.addSound(name, sound)
andplaySound(name)
for sound effects.getMesh()
andgetMeshes()
to access the player's mesh(es).onPause()
andonResume()
to handle game pause/resume.