Infinite Generating Terrains_Implementation Explanation - UQdeco2800/2021-ext-studio-2 GitHub Wiki

Overview

The main part of this feature is located in MainGameScreen.java, ForestGameArea.java, TerrainFactory.java. We changed the whole camera perspective from an up-down view to a 2D scrolling game, which continuously generates the terrains.

Logic section

Scrolling screen

  • In the MainGameScreen.java, we changed the constructor's local variable into a global variable : forestGameArea = new ForestGameArea(terrainFactory);
  • In ForestGameArea.java, it automatically generated a player which stores in this class, we need to save the player's variable in the MainGameScreen.java for later use: player = forestGameArea.player;
  • In the MainGameScreen.java's render function, we will get the player's current position from the player's variable which stored previously. player.setPosition((float) (player.getPosition().x+0.05), player.getPosition().y);
  • Then we centralised the screen to the player by setting the camera position to the player's current position:
    Vector2 screenVector = player.getPosition(); screenVector.y = 7f; renderer.getCamera().getEntity().setPosition(screenVector);

Infinite loop the terrain

  • In the MainGameScreen.java's render function, when the player move to each terrain(22 square box as a set) set's middle point, it will start generating the next set of terrain. if(screenVector.x > (2*counter+1)*10) { counter+=1; forestGameArea.spawnTerrainRandomly((int) (screenVector.x+2));
  • In the ForestGameArea.java, we created a spawnTerrainRandomly function, which is used to spawn the next set of terrain randomly based on the player's x-value position, and generate a set of terrain randomly according to the random number.

Terrain generation

  • In the ForestGameArea.java's spawnTerrain function, we created a set of terrain by generating 22 square boxes (Entity) which player can walk on them.
  • Then, we apply the image of each square boxes of the terrain.

Display Section

  • Infinite generating the terrain and scrolling screen.

Future implementations

In the following sprint, we will implement various kinds of terrain and randomly generate them. We will also come up with some algorithms to better pile up rocks and woods to improve the user experience.