Skip to content

Game Areas

Hayden edited this page Sep 16, 2021 · 2 revisions

Introduction

Game areas are areas within the game that have their own terrain, entities and UI. The aim of game areas is to make it easy to create different levels and areas within the same game screen.

The Forest Game Area within the Main Game Screen is an example of a game area.

Resource Management

Assets can be loaded/unloaded at both the screen and game area levels.

In the example game there is only one game area, however, it is very straight forward to add a new game area. This is an example of what it would look like if we added a new (made-up) game area called Forest2GameArea.

There are going to be some assets that are relevant to all game areas within the screen, e.g. the exit button on the Main Game screen. These would be loaded in the screen using the Resource Service.

Whereas assets that are only needed for a single game area, e.g. the Game Area Display which displays the game area's name, can be loaded by the game area using the Resource Service.

This is what asset loading and unloading would look like for a screen which started with a ForestGameArea then transition to a Forest2GameArea.

Usage

Initialising and Moving Between Game Areas

Intialise a game area within the screen:

TerrainFactory terrainFactory = new TerrainFactory(renderer.getCamera());

ForestGameArea forestGameArea = new ForestGameArea(terrainFactory);
forestGameArea.create();

Transition to a new game area within the same screen:

forestGameArea.dispose();
ForestGameArea2 forestGameArea2 = new ForestGameArea2(terrainFactory);
forestGameArea2.create();

Coordinate System

Cartesian to Isometric

Changing from an Orthographic view to an Isometric view doesn't change the coordinate system.

As such to put objects onto the game area correctly a function needs to be implemented to do such.

In ForestGameArea.java has a function to do so, coordTransform. This takes a GridPoint2 variable with the Cartesian Coordinates and translates it to a GridPoint2 variable which is the Isometric coordinates

  private static final GridPoint2 PLAYER_SPAWN_CART = new GridPoint2(10,0);
  private GridPoint2 isoCoord = coordTransform(PLAYER_SPAWN_CART);
  private final GridPoint2 PLAYER_SPAWN = isoCoord;
Clone this wiki locally