Terrain - UQdeco2800/2021-studio-6 GitHub Wiki

The terrain in the provided example game uses tiles, placed orthogonally. The game includes functionality for creating terrains in different orientations, and converting from tile positions to world-space positions.

Key Components

  • TerrainComponent: This component, when attached to an entity, can be used to create and render a terrain. This is generally done through the TerrainFactory rather than directly instantiating it.
  • TerrainFactory: Where terrains get created, by choosing the orientation and filling in the tiles. When creating the factory, the desired tile orientation can be chosen. The TerrainFactory can then be used to create all the terrains in your game.
  • TerrainTile: Represents a single tile in the terrain. This can be modified to add features like walking speed, particle effects, and sound effects.

Orientations

Orthogonal

Isometric

Hexagonal

How to change

To change the orientation, you need to:

  • Change the TerrainOrientation in the constructor of TerrainFactory. This will likely be somewhere in the GameArea.
  • Update TerrainFactory.createTerrain() to use the tile textures you've created for your orientation. In the example game, one terrain of each type is given. Orthogonal tile textures should be square, isometric tile textures should be a 'diamond' shape, and hexagonal tiles should be... hexagonal.

UI Elements

The individual elements are created before being implemented onto a 'flat' terrain with non-interactible elements to decrease coding issues. the elements that will be added individually will be the prickly bush and cobwebs and these can interact with the player. Using the size of the main character as a reference, the first 3 items were created being the prickly bush, cobweb and branch. Using the live paint tool to accurately stick to the pixel art style of the game, these were created. Taking inspiration from other games to design these items, the items were then shown to the design committee for approval. After an necessary changes were made the items were finalised and uploaded to the repository.

For the first level the terrain will be approximately the screen size as a static background as it was decided that this level will be relatively simple so the player can understand how to play the game and navigate the terrain. the background will consists of the noninteractable assets in a singe png. shadowing will also be added to conisndie with the art style and inspiration. The terrain was created by creating a flat background with the non interactable items - trees, campsite and branches - by positing them as described by a preplanned map shown to team 5 and 4 and saving this as a single PNG.

New methods in TerrainFactory

calculatePosition

Take the following example

//mapsize = (20, 10)
position = calculatePosition(mapsize.x, mapsize.y, 0.5, 0.3)

This creates returns the coordinates that is at 50% of the map's x-axis and at 30% of the map's y-axis, i.e. (10, 3).

This function can be used to get a coordinate in a general area of the map desired if accuracy is not an issue.

For example, if you wish place something somewhere in the bottom left, you can input 10%, 10% to get a rough coordinate without having to get exact numbers.

setTilesInRegion

This function takes in a tile and a rectangular region (start point = bottom left coordinate, end point = top right coordinate), and fills all tiles in that region with the given tile.

As an example:

//start = (5, 5) end = (15, 15)
setTilesInRegion(layer, roadTile, start, end);

fills a square region from (5, 5) to (15, 15) with roadTiles.

fillTilesAtRandomInRegion

Similar to setTilesInRegion, except only fills a random number of tiles within the region given. As an example:

//start = (5, 5) end = (15, 15)
fillTilesAtRandomInRegion(layer, roadTile, start, end, 10);

fills a random 10 tiles in the square region from (5, 5) to (15, 15) with roadTiles.

Warning: do not give this function MAP_SIZE.x or .y as any of its coordinates, because it will be out of bounds and cause a NullPointerException.

Instead subtract 1 from .x or .y before giving it to the function.

setTilesInLineAtIntervals

*Currently only sets tiles horizontally.

Similar to setTilesInRegion, except this function only sets tiles according to a certain interval.

As an example:

//start = (5, 5) end = (15, 15)
setTilesInLineAtIntervals(layer, roadTile, start, end, 5, 3);

Will fill the square region from (5, 5) to (15, 15) with roadTiles, at the interval of 5 road tiles, skip 3 tiles, 5 road tiles, etc until it reaches the right side of the region.

Then it will repeat from the start in the next line, and so on until it goes through the entire specified region.

This function is currently used to set the lane markings on the road in Level 1, and can be used for similar purposes in other places if needed.