Skip to content

Procedural Map Generation

rjg1 edited this page Sep 12, 2022 · 20 revisions

Introduction

To keep gameplay unique and enhance replay value, the game map will be dynamically generated each playthrough. This means that players will have to adapt their strategy for building their militia and working force, as resources and enemies will not appear statically from game to game. In order to assist with this, the MapGenerator class has been developed, which features functionality to create and output a randomly generated map

Usage

It is necessary to include the class in all implementations

import com.deco2800.game.areas.MapGenerator.MapGenerator;

Generate a map

Generating a map should be done in a TerrainFactory class - for example - an implementation in the default TerrainFactory class, within the fillTiles() function:

    //Generate a map with the following specifications
    MapGenerator mg = new MapGenerator(mapWidth, mapHeight, citySize, islandSize);
    //Store the map
    char[][] map = mg.getMap();

    for (int x = 0; x < mapWidth; x++) {
      for (int y = 0; y < mapHeight; y++) {
        Cell cell = new Cell();
        if (map[y][x] == mg.getOceanChar()) {
          //Set ocean tiles to ocean textures
          cell.setTile(oceanTile);
        } else {
          //Set non-ocean tiles to sand textures
          cell.setTile(sandTile);
        }
        //Add the cell to the map
        layer.setCell(x, mapHeight - y, cell);
      }
    }

In this usage case, variables mapWidth, mapHeight, citySize, islandSize were all defined as static constants beforehand, and textures oceanTile and sandTile were also pre-defined TextureRegions.

Note that when setting the created cell to the layer, the y component is mapped inversely, as the MapGenerator's y component is defined inversely to the layer's.

Save human-readable representation of the generated map as a text file

//Create a new MapGenerator
MapGenerator mg = new MapGenerator(mapWidth, mapHeight, citySize, islandSize);
//Write the map to an output location - replace path as necessary
mg.writeMap("C:\\dir1\\dir2\\map.txt");

Which will give an output of the following form, with ocean tiles indicated '*', island tiles indicated 'I', and city tiles indicated 'c'

Table of Contents

Home

Game

Game Home

Design Influences

Gameplay Features

Style

Story

Friendly Units
Map
City
Buildings
Unit Selections

Spell

Game User Testing: Theme of Unit Selection & Spell System

UI User Testing

Tutorial

Resource Stats Display

Loading Screen Bar

Health Bars
In Game menu
  • Feature
  • User Testing:In Game Menu

Landscape Tile Design

Landscape Tile Design Feedback

Weather Design

Weather Design Feedback

Camera Movement

Enemy design

Enemy Units

Enemy AI

How Animation Works

Map Flooding

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