CTFTNKS Project Documentation - v1.3.0
    Preparing search index...

    Class Game

    Manages the game state, loop, and objects.

    A class for a single game round with a single map contains a list of players, list of objects in the game contains a loop mechanism for time-iteration

    Index

    Constructors

    Properties

    accumulator: number = 0

    Accumulated time for fixed-step physics updates. Ensures consistency regardless of FPS.

    canvas: Canvas

    The canvas manager, used for size/resolution.

    lastTime: number = 0

    Timestamp of the last frame for deltaTime calculation.

    loop?: number

    Interval ID for the requestAnimationFrame loop.

    map: GameMap

    The game map.

    mode: Gamemode

    The logic/rules for the current match (e.g. CaptureTheFlag).

    monitor: PerformanceMonitor = ...

    Performance Monitor instance for tracking frame budget and logic overhead.

    nkills: number = 0

    Total kills in the current game session across all players.

    objs: GameObject[] = []

    List of game objects.

    paused: boolean = false

    Whether the game simulation is currently paused. Rendering continues.

    players: Player[] = []

    List of players.

    powerUpSpawnAccumulator: number = 0

    Accumulator for powerup spawning logic.

    powerUpSpawnRateMultiplier: number = 1

    Multiplier for powerup spawn rate, can be modified by bonuses.

    t: number = 0

    Game time counter in milliseconds (since start of round).

    updatables: Updatable[] = []

    List of updatables in the game. These are not rendered but updated every tick (e.g. timeouts).

    Methods

    • Adds a player to the game.

      Parameters

      • player: Player

        The player to add.

      Returns void

    • Registers a callback to be executed after a delay in game time.

      Parameters

      • callback: () => void

        The function to call.

      • delay: number

        The delay in milliseconds.

      Returns GameTimeout

      The timeout object.

    • Ends the game and shows the leaderboard.

      Returns void

    • Main game loop driven by requestAnimationFrame. Uses an accumulator to ensure fixed-timestep updates.

      Parameters

      • timestamp: number

        The current time.

      Returns void

    • Modifies the powerup spawn rate for a duration.

      Parameters

      • duration: number

        The duration of the effect in milliseconds.

      Returns void

    • Pauses or unpauses the game.

      Returns void

    • Resets the game time and player timers.

      Returns void

    • A single step of the game loop.

      Parameters

      • dt: number

        the temporal delta of the time step

      Returns void

    • Stops the game loop and clears intervals/timeouts.

      Returns void