Options
All
  • Public
  • Public/Protected
  • All
Menu

Main Game class. Initializes the player, map, socket connection and anything else needed for gameplay.

Hierarchy

  • Game

Index

Constructors

constructor

  • new Game(canvasName: string, fpsCounterName: string, gameHUD: any, navigator?: any, canvas?: any, windowMock?: any): Game
  • Initializes the Game.

    Parameters

    • canvasName: string

      Name of {@link Canvas} instance.

    • fpsCounterName: string

      ID of the FPS counter HTML element.

    • gameHUD: any

      Heads-up display GameHUD to relay info to the user.

    • Optional navigator: any

      Mocked navigator for unit testing.

    • Optional canvas: any

      Mocked canvas for unit testing.

    • Optional windowMock: any

    Returns Game

Properties

Private canvas

canvas: any

HTML canvas element reference

Private controls

controls: Controls

Player input from the browser

Private currentMapID

currentMapID: number

Current map ID.

Private currentMapPath

currentMapPath: string

Path to current map.

Private gameHUD

gameHUD: GameHUD

GameHUD instance. Shows info relevant to the player

Private loop

loop: GameLoop

Game loop, runs the game and controls the timing.

Private packetToGameLogic

packetToGameLogic: PacketToGameLogic

Handles messages from server to game logic.

Private player

player: Player

Player instance.

Private renderer

renderer: Renderer

Renderer instance. Needs to be updated upon window resize.

Private room

room: Room

Current room (contains map and other things, see Room).

Static Private Readonly DEFAULT_RAYCASTER_RESOLUTION

DEFAULT_RAYCASTER_RESOLUTION: 500 = 500

Default raycasting resolution. (How many strips/bars are rendered). We've found 500 to be an OK compromise between performance and graphics.

Static Private Readonly DEV_SERVER_URL

DEV_SERVER_URL: "ws://127.0.0.1:8080/ws/1" = "ws://127.0.0.1:8080/ws/1"

URL of the server. In this case

Accessors

getCanvas

  • get getCanvas(): any

getControls

getCurrentMapPath

  • get getCurrentMapPath(): string

getGameHUD

getLoop

getPacketToGameLogic

getPlayer

getRenderer

getRoom

  • get getRoom(): Room

Methods

checkConnection

  • checkConnection(): boolean
  • Checks if the connection to the server is alive.

    Returns boolean

    True if alive, False if failed

checkMap

  • checkMap(overrideMapID?: number): string
  • Checks for the current map ID obtained from server.

    We get the current map ID from PacketToGameLogic and set the map indicated by that ID

    Parameters

    • Optional overrideMapID: number

      Overridden map ID. Only needed for testing (for jasmin environment).

    Returns string

    The path to the current map.

initializeRenderer

  • initializeRenderer(windowMock?: any): void
  • Initializes the Renderer with its default settings.

    Parameters

    • Optional windowMock: any

    Returns void

initializeRoom

  • initializeRoom(mapPath: string, readFromFile?: any): void
  • Room Setup. Creates a Room.

    Parameters

    • mapPath: string

      Path to current map.

    • Optional readFromFile: any

      Reading from file method for testing purposes

    Returns void

isMapLoaded

  • isMapLoaded(): boolean
  • Checks if a map was received from server yet.

    Returns boolean

    True if the map was loaded.

loadMap

  • loadMap(newMapPath: string, windowMock?: any, readFromFile?: any): void
  • Loads a new map and re-initializes Renderer and GameHUD.

    Parameters

    • newMapPath: string

      path to new map.

    • Optional windowMock: any
    • Optional readFromFile: any

    Returns void

Private mapIDToString

  • mapIDToString(id: number): string
  • Translates map ID to map path. Must be adjusted when adding a new map.

    Note that we hard coded this for now. In the future this could be solved with a JSON

    Parameters

    • id: number

      map ID

    Returns string

    path

Private setupPlayer

  • setupPlayer(): void

Generated using TypeDoc