rdlester / hermes

A game engine for rapid world prototyping in Processing/Java:
https://rdlester.github.io/hermes/
MIT License
48 stars 4 forks source link

WorldManager #7

Open rdlester opened 8 years ago

rdlester commented 8 years ago

Design a generalizable system for switching between Worlds (between levels, or from the main menu to a level, etc.) or overlaying Worlds (pause screen over a paused level).

kpd73 commented 7 years ago

Hi, I came up with an easy solution for level (or different screens like credits, options etc) design. I designed an interface GameScreen:

interface GameScreen {

/A callback method made by a being. Can be used to tell the world that it needs to change state / abstract public void alert(Being b);

//In the activateScreen() method, the code should either create the Beings that the level holds, or it should make them visible and subscribe them to the postOffice.*/ abstract public void activateScreen();

/Similarly the deactivateScreen() method should either delete the Beings that the level holds (good if you know that the level will never be used again) or make them invisible (not draw them) and unsubscribe them from the PO (good if the level may be reloaded in the future)./ abstract public void deactivateScreen();

/draws the background or anythis else the level needs. The beings are drawn by the wold/ abstract public void draw(); }

Every level is an implementation of this interface.

The world holds an array of the levels, as well an integer that holds the index inthe array that holds the current screen. To change levels or screens when the wold is notified by the current screen, the wold calls deactivateScreen() of the current level, and then activateScreen() of the level to load.

Basically the GameScreen is a container of the beings in the level.

email me if you need an example