Skip to content

Game Room System

Kelvin Hsu edited this page Oct 17, 2026 · 2 revisions

This page details all the components that go into creating the dungeon rooms inside the game.

Room Selector

This class owns the current room entity and the player.

Usage

To instantiate the RoomSelector needs the player entity and the CameraComponent. Then to start the game call RoomSelector.start() which will register the player and the first room for the game to begin

roomSelector = new RoomSelector(player, camera);
// ... other setup
roomSelector.start();

After start is called all the game logic will be handled internally inside of the rooms.

Requesting a room switch

To switch a room once the game has started, you are only able to do so inside the room entity via it's event. A public string constant should be used as the event name then provide it an ExitConfig which will declare the details of the next room and where to spawn the player.

// Inside a component attached to a room entity
entity.getEvents.trigger(RoomSelector.SWITCH_ROOM, exitConfig)

Notification events

Events triggered by the RoomSelector to the room entity

Event Trigger condition Params
ROOM_SWITCHED_EVENT Triggered on the new room switched into RoomConfig oldConfig, RoomConfig newConfig

How it works internally

The RoomSelector should only do one thing which is switch the current room. To do this it will perform the following steps which it does in setRoom():

  1. dispose the old room (if there is one)
  2. register the new room to the entity service
  3. move the player to it spawn in the new room
  4. reset the camera
  5. set up any events to the new room
  6. Notify the new room of the switch.

Once the game has started a room switch can be request by the current room entity by triggering a "SwitchRoom" event. The event takes in an ExitConfig which the RoomSelector will give to the RoomLoader to create a room entity and spawn location and perform the room switch. Upon the "SwitchRoom" event being triggered RoomSelector will use the entity service to schedule the switching to be run on the next update() to avoid performing the switch during physic events.

Room Loader

The RoomLoader follows the facade design pattern and is currently only used by the RoomSelector. It's responsibility is to abstract away the need for the RoomSelector to also manage the WorldConfig and RoomFactory to build new room entities.

Usage

The RoomLoader requires a reference to the CameraComponent due to the RoomFactory needing the camera to build the terrain. If the RoomLoader is instantiated without a WorldConfig it will load one from the default path (configs/rooms.json). The RoomLoader has two main functions getRoom() and getSpawnPoint() with a few different overloads. It also has two specific functions for getting the starting room and the starting spawn.

public Entity getStartingRoom();
public Entity getRoom(String roomId, boolean cleared);
public Entity getRoom(ExitConfig exit, boolean cleared);
public Entity getRoom(ExitConfig exit); // Uses the room clear service to determine if cleared.

public GridPoint2 getStartingSpawn();
public GridPoint2 getSpawnPoint(ExitConfig exit);

Table of Contents

Home

Test Plan

Team 2

Features

Components
Player
Items and Inventory
Enemies
Interactable NPCs
Cutscenes and Dialogue
Music
Bosses
Rooms
Weapons
Abilities & Spells
Game Screens and Areas
Dungeons

Game Engine

Getting Started

Entities and Components

Service Locator

Loading Resources

Logging

Unit Testing

Debug Terminal

Input Handling

UI

Animations

Audio

AI

Physics

Terrain

Concurrency & Threading

Settings

Troubleshooting

MacOS Setup Guide

Clone this wiki locally