Skip to content

Border Generation

junelee045 edited this page Sep 16, 2021 · 8 revisions

Overview

The wall generations enclose the game room through 4 individuals walls in isometric view(Top Left, Bottom Left, Top Right, Bottom Right). Each wall is constructed from individual wall entities which contain a physical bound for the players and the enemy (Mum). The wall is constructed as an entity and it is layered over the tile generation. It is planned that for each room generated, there will be 4 walls to enclose all sides, and any adjacent rooms will be linked for player movement via a wall entity. All generation of of entities should be located within the game area.

Key Components for Wall Generation

  • ForestGameArea.java: Creates the game area, including terrain, dynamic entities (player/mum), static entities (walls).
    • Responsible for determining each individual wall entity grid position in spawnWalls.
    • FOREST_DEMO_ISO: Defines the orientation of the tiled game area as a isometric view.
  • GameArea.java: Represents the area where the game is being played. Terrain and entity components are added through this class.
    • spawnEntity: Function which spawns entities at its current position.
    • spawnEntityAt: Function which spawns entities at a specific grid point.
  • TerrainFactory.java: Factory for creating the game terrain.
    • MAP_SIZE: grid point defining the x and y of the game area.
    • ISOMETRIC: case from TiledMapRenderer which generates the isometric renderer.
  • TerrainComponent.java: Renders the tiled terrain for a given tiled map with the tiled orientation transformation (isometric).
    • tileToWorldPosition: Determines the grid point translation given its given tiled orientation transformation (isometric).
  • ObstacleFactory.java: Factory which generates obstacle entities
    • createDoor: Function which generates the door tile at some grid point within the wall generation

Development Process

To rotate the game view to isometric the following lines of code were changed:

  • In ForestGameArea: terrain = terrainFactory.createTerrain(TerrainType.FOREST_DEMO_ISO);
  • In TerrainFactory: public TerrainFactory(CameraComponent cameraComponent) { this(cameraComponent, TerrainOrientation.ISOMETRIC);}

This rotated the orientation of the game to isometric by 45 degrees clockwise. Where the x axis represented the bottom left side of the map and the y axis represented the top left of the map. The visible area of the new orientation only displayed the top corner of the game map, thus the initial spawn position of the player was adjusted in ForestGameArea. The tree entities spawned out of the area, which meant most likely they were being spawned from the original orthogonal boundaries.

test

At every instance a game area (room) is generated, each sides of the walls will be generated within spawnWalls through a for loop which increments until the max wall entities is reached. Given the MAP_SIZE.x and MAP_SIZE.y components, which both are equal, this can define the max number of individual walls needed for each side and the minimum position component of the MAP_SIZE. However, when applying the wall generation a clear outline of the original orthogonal boundaries could be visibly detected.

To fix this rotational issue the following lines of code were adjusted:

  • In TerrainComponent.java under the function tileToWorldPosition: The dividing factor of the isometric y component was changed from 2 to 3.724f
  • return new Vector2((x + y) * tileSize / 2, (y - x) * tileSize / 3.724f);

test

Given that the positions of the walls have been correctly aligned, test wall textures were implemented with a scale of 1f before each wall entity was generated. Additionally, on the bottom left wall, a gap of 2 tiles was left for the implementation for the door which allowed the player/mum to freely move in and out of the room. These changes were all made within the spawnWalls function under the ForestGameArea.java file. Given the scaling of the door with the player height, setting 2 tiles with the door is reasonable.

test

With the new map generation in HouseGameArea.java the methods of wall generations were transferred over to spawnWalls. However with new generation, the dividing factor from TerrainComponent 3.724f offset the walls from the floor tiles and was no longer consistent. Adjusting the value to 4f solved this problem.

  • return new Vector2((x + y) * tileSize / 2, (y - x) * tileSize / 4f);

test

Clone this wiki locally