Skip to content

Event loop

Peter Svensson edited this page Dec 18, 2019 · 1 revision

The game engine is currently single-stepped, so it waits for user input, and after that is processed, the game is stepped forward.

The main class is GameBoard, which is responsible for displaying the game and responding to user events. The GameBoard has a GameMap, which holds all the game state. It has separate layers for Items, Entities and Map tiles.

The Event loop can roughly be described as;

GameBoard>>keyStroke -> moveEntity (player) -> GameMap >> stepMap -> GameEntity>step -> (for all strategies in the GameEntity) Strategy>>stepAndCheck

The Strategies are created in the GameEntity class constructor #new: and are stored in a SortedCollection sorted by priority. The idea is that certain strategies (like fleeing from an enemy) have higher priority than others (looking for good items to pick up)

When a Strategy is called (#stepAndCheck), it tries to do what it want, and if successful returns true, which stop the calls to any other strategies the Entity might have.

Clone this wiki locally