-
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, MapMaker.java has been created to convert a visually designed map to a file that is able to be interpreted by TerrainFactory.
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.
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.
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.
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.
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:
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.
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.