Adding Resources to the game - UQdeco2800/2022-studio-3 GitHub Wiki
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);
}