Nocturna
    Preparing search index...

    Player represents the main controllable character in the game.

    Responsibilities:

    • Handles player movement, jumping, and physics interactions.
    • Manages player state (idle, knockback, damageable, etc.) using a state machine.
    • Supports taking damage, death, and respawn logic.
    • Integrates with Babylon.js for mesh, physics, and sound management.
    • Provides methods for updating, pausing, resuming, and interacting with the game world.
    • Implements the GameObject interface for compatibility with the game engine.

    Usage:

    • Instantiated by the PlayerFactory, which loads the mesh, applies physics, and loads sounds.
    • Use move(dt, input) to move the player based on input.
    • Use jump() to make the player jump.
    • Use takeDamage(damage) to apply damage and trigger state changes.
    • Use update(dt, input) in the game loop to update player state.
    • Use isAlive() and kill() to manage player life state.
    • Use addSound(name, sound) and playSound(name) for sound effects.
    • Use getMesh() and getMeshes() to access the player's mesh(es).
    • Use onPause() and onResume() to handle game pause/resume.

    Implements

    Index

    Constructors

    • Constructs a new Player.

      Parameters

      • mesh: Mesh

        The player's mesh (can be null, will be loaded by the factory).

      • scene: Scene

        The Babylon.js scene.

      Returns Player

    Properties

    mesh: Mesh[] = []
    Type: string = "player"

    Methods

    • Adds a sound effect to the player.

      Parameters

      • name: string

        The sound name.

      • sound: StaticSound

        The StaticSound instance.

      Returns void

    • Applies a knockback impulse to the player, usually after taking damage.

      Returns void

    • Applies damage to the player, triggers knockback and state change.

      Parameters

      • damage: number

        The amount of damage to apply.

      Returns void

    • Checks if the player is currently on the ground.

      Returns boolean

      True if grounded, false otherwise.

    • Plays a sound effect by name.

      Parameters

      • name: string

        The sound name.

      Returns void

    • Sets the unique ID of the player.

      Parameters

      • id: string

        The new ID.

      Returns void

    • Handles taking damage using the player's damage state.

      Parameters

      • damage: number

        The amount of damage to apply.

      Returns void