-
Notifications
You must be signed in to change notification settings - Fork 0
Map Generation and Functionality
The generation and functionality of the terrain has to conform to these parameters:
- It has to place tiles in a way that simulates a sandy island being surrounded by water
- It has to be a static map (in response to feedback)
- The island has to be able to expand upon a condition
- The island has to be able to shrink upon a condition
- Island boundaries must be generated such that the player cannot walk off of the island
- The tile textures must change in response to different times of the day.
To aid in the generation of a static map, PNGToMapFile.java has been created to convert a visually designed map to a file that is able to be interpreted by TerrainFactory.
This program converts a variable length .png file to a text file filled with 3-bit integers. Each bit representing a different attribute of the tile. This allows for the overall map shape to be designed visually in a pixel-art program, and then used in the game as a layout for the map.
PNGToMapFile maps the RGB values of a pixel to the corresponding 3-bit integer, readable by TerrainFactory. The mapping is as follows:
Red Value > 0 -> Yes: The tile is a land tile. No: The tile is a water tile.
Green Value > 0 -> Yes: There is an island border on this tile
Blue Value > 0 -> Yes: Enemies can spawn on this tile.
Examples of how a visually designed map may look:
Note: the cyan colour surrounding the red island is generated by R: 0 G: 255: B: 255, which implies the tile is a water tile, has a island border on it, and enemies can spawn on it.
To convert the .png file to a game-readable file, ensure that the png is in the same directory as PNGToMapFile, and execute:
java PNGToMapFile.java fileName.png
To convert multiple images:
java PNGToMapFile.java fileName1.png fileName2.png fileNameN.png
Example of Generated Island:
On initialisation, TerrainFactory reads in 5 level files, adding them to a list of arrays which contain each 3-bit integer, describing the tile. 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 integer in the level array (using little-endian notation):
- Least significant bit (a): Land Bit -> 0 for water, 1 for land
- a+1: Border bit -> 0 for no border, 1 for border on the tile
- a+2: Spawnable bit -> 0 for not spawnable, 1 for spawnable
Each layer is added to the TiledMap, which is passed as a parameter to the TerrainComponent for ForestGameArea to handle.
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 impl