undeadbytes

Map

The Map class manages the configuration and generation of game maps. Maps are represented as arrays of strings, where each character denotes a different game entity such as walls, enemies, pickups, and the player.

Map Configuration

Level Representation

A level is represented as an array of strings, where each character denotes a specific game entity:

Example Level Configuration

const level1 = [
  'W W W W W W W W W W W W W W W W W W W W',
  'W       W                             W',
  'W   A   W   S     E             H     W',
  'W   E   W                             W',
  'W       W           E     W W W W W W W',
  'W     W W                             W',
  'W                   E                 W',
  'W         E               S     E     W',
  'W                                     W',
  'W W W W W W W W W W W W W W           W',
  'W                         W           W',
  'W   H A E                 W           W',
  'W                   E     W           W',
  'W W W W W W W             W           W',
  'W                         W     E     W',
  'W               W W W W W W           W',
  'W   P                     W           W',
  'W                                     W',
  'W         W W W                   E   W',
  'W           W       E                 W',
  'W W W W W W W W W W W W W W W W W W W W'
];

Properties

These properties collectively define the state and configuration of the game map including the layout and position of all entities for rendering.

Methods

Constructor

constructor()

Initializes a new Map instance with default values and loads the level configurations.

newMapConfiguration()

newMapConfiguration()

Resets all entity positions to their default values, placing the player at the top-left corner and clearing arrays for enemies, walls, ammo pickups, health pickups, and stamina pickups.

generate(levelIndex)

generate(levelIndex = 1)

Generates a new map based on the specified levelIndex. Processes the corresponding level configuration and updates position arrays for entities.

getPlayerPosition()

getPlayerPosition()

Returns the current player position as an object with x and y coordinates.

getEnemyPositions()

getEnemyPositions()

Returns an array of enemy positions, each represented as an object with x and y coordinates.

getWallPositions()

getWallPositions()

Returns an array of wall positions, each represented as an object with x and y coordinates.

getAmmoPickupPositions()

getAmmoPickupPositions()

Returns an array of ammo pickup positions, each represented as an object with x and y coordinates.

getHealthPickupPositions()

getHealthPickupPositions()

Returns an array of health pickup positions, each represented as an object with x and y coordinates.

getStaminaPickupPositions()

getStaminaPickupPositions()

Returns an array of stamina pickup positions, each represented as an object with x and y coordinates.