Skip to content

Map Generation and Functionality

Sam Behm edited this page Oct 4, 2022 · 13 revisions

Generation and Functionality Overview

The generation and functionality of the terrain has to conform to these parameters:

  1. It has to place tiles in a way that simulates a sandy island being surrounded by water
  2. It has to be a static map (in response to feedback)
  3. The island has to be able to expand upon a condition
  4. The island has to be able to shrink upon a condition
  5. Island boundaries must be generated such that the player cannot walk off of the island
  6. The tile textures must change in response to different times of the day.

Generating a Static Map

To aid in the generation of a static map, MapMaker.java has been created to convert a visually designed map to a file that is able to be interpreted by TerrainFactory.

MapMaker.java

The MapMaker program is a tool used to visually design the map, allowing more creative control over level generation. The program is fairly intuitive to use, simply select a tile to place, and press on the map panel (left side of the screen) to place it on the map.

Controls

Buttons:

  • The 11 image-buttons are tiles that can be placed on the map
  • Eraser Button: Sets the currently selected tile to null. Any tile clicked on the map panel will be removed from the image position mapping.
  • Save Button: Writes the game out to a file with the specified name. There must be tiles placed, as well as a centre tile placed. The file specified cannot already exist.
  • Load Button: Reads a game-readable map file into MapMaker, placing the tiles on the screen. If the tiles do not appear at first, click the map panel to repaint it.

Tile Types in Game vs MapMaker

Specific tiles placed in MapMaker have additional qualities that are written out into the game-readable map file to aid in entity generation.

  • Water Tile: a water tile placed in MapMaker corresponds to an enemy-spawnable tile in game. Non-spawnable water tiles should be left empty as TerrainFactory will fill any tiles that aren't placed with non-spawnable water tiles. The player cannot walk or build on these tiles.
  • Center Tile: this tile can only be placed once. It denotes the centre of the island, allowing you to keep track of how the island expands. The coordinates of this tile are also written out to the game-readable map file to allow TerrainFactory to keep the map design centred.
  • Sand Tiles: the player can walk and build on these tiles, and land-based environmental objects can spawn on these tiles.
  • Shoreline Tiles: Currently, these tiles act as sand tiles.

Map-readable files

When saving and loading game-readable map files, tiles are read/loaded using a different number per tile-type. This number corresponds to the texture index in the textures array, as follows:

  • 0: water
  • 1: sand
  • 2: bottom shoreline
  • 3: top shoreline
  • 4: bottom right shoreline
  • 5: bottom left shoreline
  • 6: top right shoreline
  • 7: top left shoreline
  • 8: left shoreline
  • 9: right shoreline

MapMaker writes the tiles from the minimum x and y values, to the maximum x and y values so that no tiles are missed in writing. When a coordinate is being written that does not have a tile corresponding to it, the character 'a' is written to denote it. In TerrainFactory, this tile will be filled with a non-spawnable water tile.

Before writing tile positions, the centre tile position is written to the top of the file.

Generating the Map from Map Files

On initialisation, TerrainFactory reads in 3 level files, adding them to a list of integer arrays, each integer describing the tile as in MapMaker. Then, when the terrain is called to be generated (in ForestGameArea), all levels are generated by looping over array, creating a tiled map layer (TiledMapTileLayer). Each tile in the tile map is generated based on the equivalent texture as before, and also adds any sand-tiles to a list of land-tiles, and any water tiles placed in MapMaker to a list of spawnable tiles:

image

For sand tiles, a sand-based texture is selected.

Each layer is added to the TiledMap, which is passed as a parameter to the TerrainComponent for ForestGameArea to handle.

Changing the Map Size

When the Crystal is upgraded, the function incrementMapLvl is called in the TerrainComponent. This function increments the map level counter, which describes what level file is being used to display the map, hides the previous layer, and makes the new layer visible.

After every night, if the crystals health is less than 50%, the map shrinks. This is similarly implemented by calling TerrainComponent's decrementMapLvl.

Table of Contents

Home

How to Play

Introduction

Game Features

Main Character

Enemies
The Final Boss

Landscape Objects

Shop
Inventory
Achievements
Camera

Crystal

Infrastructure

Audio

User Interfaces Across All Pages
Juicy UI
User Interfaces Buildings
Guidebook
[Resource Management](Resource-Management)
Map
Day and Night Cycle
Unified Grid System (UGS)
Polishing

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

Troubleshooting

MacOS Setup Guide

Clone this wiki locally