Skip to content

GameAreaService

AElanagai edited this page Oct 16, 2024 · 2 revisions

Overview

GameAreaService is a service that provides access to the GameController and GameArea within the game. It acts as an intermediary, allowing other classes to interact with the game area and controller without direct dependencies.Basically it is a service for classes that need to spawn and dispose entities in the gamearea within their own class

Key Components

  • GameController: The main controller for the game, managing levels, rooms, and game state.
  • GameArea: Represents the current game area, handling entity spawning and disposal.

Core methods

  1. getGameArea(): Returns the current GameArea object.
  2. getGameController(): Returns the GameController object.
  3. update(): Triggers the spawning of the current room in the GameController.

Registering Service for Use

ServiceLocator.registerGameAreaService(new GameAreaService(gameController));
// spawning created entity
ServiceLocator.getGameAreaService().getGameArea().spawnEntity(entity);
// disposing entity
ServiceLocator.getGameAreaService().getGameArea().disposeEntity(entity);

When you should use GameAreaService

  • Spawn or dispose of entities from a class that doesn't directly interact with the game area.
  • Access the GameController for game state management.
  • Trigger updates to the current room or game state.

Usage

Correct implementation - is the WeaponComponent, that needs to spawn a projectile entity based off a triggered event acting within the bound of its class.
Incorrect implementation - is using the service in Rooms unnecessarily when the GameArea is passed as an argument to the function

UML Diagram

image

Table of Contents

Home

Design

Design Document

Design Choices

Game Wiki

Gameplay

Controls

Game Features

Utilities
Animals
Menus/screens
Character
Map
Weapon
Projectile
Items
Music/sound

User Guide

Starting the game

Game Engine

Getting Started

Entities and Components

Service Locator

Loading Resources

Logging

Unit Testing

Debug Terminal

Input Handling

UI

Animations

Audio

AI

Physics

Game Screens and Areas

Terrain

Concurrency & Threading

Settings

Enhancement of Settings

Troubleshooting

MacOS Setup Guide

Clone this wiki locally