Skip to content

Adding Resources to the game

rjg1 edited this page Sep 11, 2022 · 4 revisions

Introduction

As the game develops, it is likely that many more resources will be required by developers to achieve desired gameplay loops. This process has been made easy with ResourceGenerator, as adding a resource is as simple as editing a .json file, and creating a factory.

Steps to implement

Modify resources.json

resources.json is the resource config file, found in assets/configs/resource.json. It contains all the data the game needs to allocate space on the map for a resource. For example, if you wanted to add a new resource "Amethyst" in addition to the current resources, you would edit the file as follows:

File prior to editing:

{
resources: [
	{ 
		"name": "Tree",
		"width": 1,
		"height": 1,
		"minAmount": 25,
		"maxAmount": 60,
		"preferredDistance": 30
	},
	{
		"name": "Stone",
		"width": 2,
		"height": 2,
		"minAmount": 5,
		"maxAmount": 10,
		"preferredDistance": 999
	}
]
}

File post editing:

{
resources: [
	{ 
		"name": "Tree",
		"width": 1,
		"height": 1,
		"minAmount": 25,
		"maxAmount": 60,
		"preferredDistance": 30
	},
	{
		"name": "Stone",
		"width": 2,
		"height": 2,
		"minAmount": 5,
		"maxAmount": 10,
		"preferredDistance": 999
	},
	{
		"name": "Amethyst",
		"width": 1,
		"height": 1,
		"minAmount": 1,
		"maxAmount": 5,
		"preferredDistance": 20
	}
]
}

This will allocate space on the map for up to 5 amethyst resources (randomly chosen), each occupying space of 1x1 tiles.

Create your ResourceFactory

In order to create an entity with the required components, create a resource factory (see StoneFactory or TreeFactory).

Edit the spawnResources() function in AtlantisGameArea

spawnResources() iterates through a list of ResourceSpecification to spawn all resources produced by ResourceGenerator. Add to the set of conditional statements that determine which type of resource it is based on name, and use your ResourceFactory to spawn your resource.

e.g.

                if (rs.getName().equals("Tree")) {
                    //Spawn a Tree entity
                    mapComponent.setDisplayColour(Color.FOREST);
                    spawnEntityAt(TreeFactory.createTree().addComponent(mapComponent), spawn, false, false);
                } else if (rs.getName().equals("Stone")) {
                    //Spawn a Stone entity
                    mapComponent.setDisplayColour(Color.DARK_GRAY);
                    spawnEntityAt(StoneFactory.createStone().addComponent(mapComponent), spawn, false, false);
                }

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