Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/Team-3-maps-main' into Team-3-ma…
Browse files Browse the repository at this point in the history
…ps-main
  • Loading branch information
aadityayadav17 committed Sep 11, 2023
2 parents 0b3fba6 + 22661e2 commit 41afb48
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 5 deletions.
Binary file modified source/core/assets/images/lava_bg.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import com.csse3200.game.screens.GameLevelData;
import com.csse3200.game.services.ResourceService;
import com.csse3200.game.services.ServiceLocator;

import static com.csse3200.game.screens.MainGameScreen.viewportHeight;
import static com.csse3200.game.screens.MainGameScreen.viewportWidth;

Expand All @@ -37,6 +36,7 @@ public class TerrainFactory {
int selectedLevel = GameLevelData.getSelectedLevel();
private Texture whiteTexture;


/**
* Create a terrain factory with Orthogonal orientation
*
Expand All @@ -48,7 +48,6 @@ public TerrainFactory(CameraComponent cameraComponent) {
Viewport viewport = new ScreenViewport(camera);
viewport.update(viewportWidth, viewportHeight, true);
stage = new Stage(viewport, new SpriteBatch());

camera.update();

Pixmap pixmap = new Pixmap(1, 1, Pixmap.Format.RGBA8888);
Expand Down Expand Up @@ -108,9 +107,19 @@ private TiledMapRenderer createRenderer(TiledMap tiledMap, float tileScale) {

private TiledMap createForestDemoTiles(GridPoint2 tileSize, TextureRegion grass) {
TiledMap tiledMap = new TiledMap();
/**
* Creates a background layer for a tiled map with the specified dimensions and tile size.
*
* @param width The width of the layer in tiles.
* @param height The height of the layer in tiles.
* @param tileWidth The width of each individual tile in pixels.
* @param tileHeight The height of each individual tile in pixels.
*/

// Create a background layer
TiledMapTileLayer backgroundLayer = new TiledMapTileLayer(20, 8, tileSize.x, tileSize.y);
/**
* Define a TextureRegion to be used as the background texture.
*/
TextureRegion backgroundTextureRegion ;

switch (selectedLevel) {
Expand All @@ -129,14 +138,30 @@ private TiledMap createForestDemoTiles(GridPoint2 tileSize, TextureRegion grass)
break;
}

// Create a single cell for the entire background image
/**
* Creates a single cell with the specified background texture region and adds it to the background layer
* of a tiled map. The background layer represents the entire background image of the map.
*
* @param backgroundTextureRegion The TextureRegion to use as the background texture.
* @param tileSizeX The width of each individual tile in pixels.
* @param tileSizeY The height of each individual tile in pixels.
* @param tiledMap The TiledMap to which the background layer should be added.
*/
Cell cell = new Cell();
cell.setTile(new StaticTiledMapTile(backgroundTextureRegion));
backgroundLayer.setCell(0, 0, cell);

tiledMap.getLayers().add(backgroundLayer);

// Create a grass layer
/**
* Creates a grass layer for the tiled map with the specified dimensions and tile size, filling it with
* grass tiles using the provided grass terrain tile.
*
* @param tileSizeX The width of each individual tile in pixels.
* @param tileSizeY The height of each individual tile in pixels.
* @param grassTile The TerrainTile representing the grass tile to be used for the layer.
* @param tiledMap The TiledMap to which the grass layer should be added.
*/
TerrainTile grassTile = new TerrainTile(grass);
TiledMapTileLayer grassLayer = new TiledMapTileLayer(20, 8, tileSize.x, tileSize.y);
fillTiles(grassLayer, new GridPoint2(20, 8), grassTile);
Expand Down
30 changes: 30 additions & 0 deletions source/core/src/test/GameLevelDataTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import com.csse3200.game.screens.GameLevelData;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.*;

class GameLevelDataTest {

@Test
void shouldInitializeSelectedLevelToMinusOne() {
assertEquals(-1, GameLevelData.getSelectedLevel());
}

@Test
void shouldSetSelectedLevel() {
GameLevelData.setSelectedLevel(2);
assertEquals(2, GameLevelData.getSelectedLevel());
}

@Test
void shouldSetSelectedLevelToZero() {
GameLevelData.setSelectedLevel(0);
assertEquals(0, GameLevelData.getSelectedLevel());
}

@Test
void shouldSetSelectedLevelToNegativeValue() {
GameLevelData.setSelectedLevel(-5);
assertEquals(-5, GameLevelData.getSelectedLevel());
}
}

0 comments on commit 41afb48

Please sign in to comment.