diff --git a/source/core/assets/images/Dusty_MoonBG.png b/source/core/assets/images/Dusty_MoonBG.png index aabbd3547..2301477d4 100644 Binary files a/source/core/assets/images/Dusty_MoonBG.png and b/source/core/assets/images/Dusty_MoonBG.png differ diff --git a/source/core/assets/images/desert_bg.png b/source/core/assets/images/desert_bg.png index 2301477d4..953e2c838 100644 Binary files a/source/core/assets/images/desert_bg.png and b/source/core/assets/images/desert_bg.png differ diff --git a/source/core/assets/images/desert_bg2.png b/source/core/assets/images/desert_bg2.png new file mode 100644 index 000000000..57597b9fd Binary files /dev/null and b/source/core/assets/images/desert_bg2.png differ diff --git a/source/core/assets/images/ice_bg.png b/source/core/assets/images/ice_bg.png index 2fae5a19e..aca79c945 100644 Binary files a/source/core/assets/images/ice_bg.png and b/source/core/assets/images/ice_bg.png differ diff --git a/source/core/assets/images/ice_bg1.png b/source/core/assets/images/ice_bg1.png new file mode 100644 index 000000000..2fae5a19e Binary files /dev/null and b/source/core/assets/images/ice_bg1.png differ diff --git a/source/core/assets/images/lava_bg.png b/source/core/assets/images/lava_bg.png index cca706805..b5b4c278e 100644 Binary files a/source/core/assets/images/lava_bg.png and b/source/core/assets/images/lava_bg.png differ diff --git a/source/core/assets/images/lava_bg1.png b/source/core/assets/images/lava_bg1.png new file mode 100644 index 000000000..cca706805 Binary files /dev/null and b/source/core/assets/images/lava_bg1.png differ diff --git a/source/core/src/main/com/csse3200/game/areas/ForestGameArea.java b/source/core/src/main/com/csse3200/game/areas/ForestGameArea.java index 9f441ef98..3ed44061f 100644 --- a/source/core/src/main/com/csse3200/game/areas/ForestGameArea.java +++ b/source/core/src/main/com/csse3200/game/areas/ForestGameArea.java @@ -1,6 +1,8 @@ package com.csse3200.game.areas; import com.badlogic.gdx.audio.Music; +import com.badlogic.gdx.graphics.Texture; +import com.badlogic.gdx.graphics.g2d.SpriteBatch; import com.badlogic.gdx.math.GridPoint2; import com.badlogic.gdx.math.Vector2; import com.csse3200.game.components.ProjectileEffects; @@ -255,37 +257,16 @@ public void create() { player = spawnPlayer(); player.getEvents().addListener("spawnWave", this::spawnWave); playMusic(); - - // spawnFireTowerTowerAt(3, 1); - // spawnFireTowerTowerAt(3, 2); - // spawnFireTowerTowerAt(3, 3); - // spawnFireTowerTowerAt(3, 4); - // spawnFireTowerTowerAt(3, 5); - // spawnDroidTowerAt(3, 1); - // spawnDroidTowerAt(3, 2); - // spawnDroidTowerAt(3, 3); - // spawnDroidTowerAt(3, 4); - // spawnDroidTowerAt(3, 5); - // spawnSplittingXenoGrunt(15, 5); + spawnXenoGrunts(); + startWaveTimer(); + spawnScrap(); spawnDeflectXenoGrunt(15, 5); spawnSplittingXenoGrunt(15, 4); - // spawnSplittingXenoGrunt(15, 5); - // spawnDodgingDragonKnight(15, 3); - // spawnDemonBoss(); - // spawnPatrickBoss(); - // spawnFireWorm(); - - //mobBoss1 = spawnMobBoss1(); - // startWaveTimer(); -//// spawnIncome(); - spawnScrap(); - spawnTNTTower(); - spawnWeaponTower(); -// - // spawnGapScanners(); + spawnScrap(); + spawnTNTTower(); + spawnWeaponTower(); + spawnGapScanners(); spawnDroidTower(); -// -// mobBoss2 = spawnMobBoss2(); } @@ -298,8 +279,8 @@ private void displayUI() { } private void spawnTerrain() { - // Background terrain - terrain = terrainFactory.createTerrain(TerrainType.FOREST_DEMO); + + terrain = terrainFactory.createTerrain(TerrainType.ALL_DEMO); spawnEntity(new Entity().addComponent(terrain)); // Terrain walls @@ -308,9 +289,11 @@ private void spawnTerrain() { Vector2 worldBounds = new Vector2(tileBounds.x * tileSize, tileBounds.y * tileSize); // Left - // ! THIS ONE DOESNT WORK. GRIDPOINTS2UTIL.ZERO is (0, 4), not (0, 0) spawnEntityAt( - ObstacleFactory.createWall(WALL_WIDTH, worldBounds.y), new GridPoint2(1, 0), false, false); + ObstacleFactory.createWall(WALL_WIDTH, worldBounds.y), + new GridPoint2(0, 2), + false, + false); // Right spawnEntityAt( ObstacleFactory.createWall(WALL_WIDTH, worldBounds.y), @@ -324,12 +307,14 @@ private void spawnTerrain() { false, false); // Bottom - // spawnEntityAt( - // ObstacleFactory.createWall(worldBounds.x, WALL_WIDTH), GridPoint2Utils.ZERO, false, false); - // * TMPORARY spawnEntityAt( - ObstacleFactory.createWall(worldBounds.x, WALL_WIDTH * 7), new GridPoint2(0, 0), false, false); + ObstacleFactory.createWall(worldBounds.x, WALL_WIDTH ), + new GridPoint2(0, 2), + false, + false); } + + // private void spawnBuilding1() { // GridPoint2 minPos = new GridPoint2(0, 0); // GridPoint2 maxPos = terrain.getMapBounds(0).sub(2, 2); @@ -600,7 +585,7 @@ private void spawnWaterSlime() { // } private void spawnWeaponTower() { - GridPoint2 minPos = new GridPoint2(0, 0); + GridPoint2 minPos = new GridPoint2(0, 2); GridPoint2 maxPos = terrain.getMapBounds(0).sub(2, 2); for (int i = 0; i < NUM_WEAPON_TOWERS + 10; i++) { @@ -629,7 +614,7 @@ private void spawnDroidTowerAt(int x, int y) { } private void spawnTNTTower() { - GridPoint2 minPos = new GridPoint2(0, 0); + GridPoint2 minPos = new GridPoint2(0, 2); GridPoint2 maxPos = terrain.getMapBounds(0).sub(2, 2); for (int i = 0; i < NUM_WEAPON_TOWERS; i++) { @@ -641,7 +626,7 @@ private void spawnTNTTower() { } private void spawnDroidTower() { - GridPoint2 minPos = new GridPoint2(0, 0); + GridPoint2 minPos = new GridPoint2(0, 2); GridPoint2 maxPos = terrain.getMapBounds(0).sub(2, 2); for (int i = 0; i < NUM_WEAPON_TOWERS; i++) { diff --git a/source/core/src/main/com/csse3200/game/areas/terrain/TerrainFactory.java b/source/core/src/main/com/csse3200/game/areas/terrain/TerrainFactory.java index 0f087d6fd..d6377e4a1 100644 --- a/source/core/src/main/com/csse3200/game/areas/terrain/TerrainFactory.java +++ b/source/core/src/main/com/csse3200/game/areas/terrain/TerrainFactory.java @@ -1,40 +1,24 @@ package com.csse3200.game.areas.terrain; -import com.badlogic.gdx.graphics.Color; import com.badlogic.gdx.graphics.OrthographicCamera; -import com.badlogic.gdx.graphics.Pixmap; import com.badlogic.gdx.graphics.Texture; -import com.badlogic.gdx.graphics.g2d.BitmapFont; -import com.badlogic.gdx.graphics.g2d.SpriteBatch; import com.badlogic.gdx.graphics.g2d.TextureRegion; import com.badlogic.gdx.maps.tiled.TiledMap; import com.badlogic.gdx.maps.tiled.TiledMapRenderer; import com.badlogic.gdx.maps.tiled.TiledMapTileLayer; import com.badlogic.gdx.maps.tiled.TiledMapTileLayer.Cell; import com.badlogic.gdx.maps.tiled.renderers.OrthogonalTiledMapRenderer; -import com.badlogic.gdx.maps.tiled.tiles.StaticTiledMapTile; import com.badlogic.gdx.math.GridPoint2; -import com.badlogic.gdx.scenes.scene2d.Stage; -import com.badlogic.gdx.scenes.scene2d.ui.TextButton; -import com.badlogic.gdx.utils.viewport.ScreenViewport; -import com.badlogic.gdx.utils.viewport.Viewport; -import com.csse3200.game.areas.terrain.TerrainComponent.TerrainOrientation; import com.csse3200.game.components.CameraComponent; import com.csse3200.game.services.ResourceService; import com.csse3200.game.services.ServiceLocator; -import com.csse3200.game.screens.GameLevelData; -import static com.csse3200.game.screens.MainGameScreen.viewportHeight; -import static com.csse3200.game.screens.MainGameScreen.viewportWidth; /** Factory for creating game terrains. */ public class TerrainFactory { - public static final GridPoint2 MAP_SIZE = new GridPoint2(20, 8); - private static OrthographicCamera camera; - private final TerrainOrientation orientation; - private static Stage stage; - private Texture whiteTexture; - int selectedLevel = GameLevelData.getSelectedLevel(); + + private final OrthographicCamera camera; + private final TerrainComponent.TerrainOrientation orientation; /** * Create a terrain factory with Orthogonal orientation @@ -42,19 +26,7 @@ public class TerrainFactory { * @param cameraComponent Camera to render terrains to. Must be ortographic. */ public TerrainFactory(CameraComponent cameraComponent) { - this(cameraComponent, TerrainOrientation.ORTHOGONAL); - camera.position.set(viewportWidth / 2f, (viewportHeight / 2f), 10); - 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); - pixmap.setColor(1, 1, 1, 1); - pixmap.fill(); - whiteTexture = new Texture(pixmap); - pixmap.dispose(); + this(cameraComponent, TerrainComponent.TerrainOrientation.ORTHOGONAL); } /** @@ -63,39 +35,52 @@ public TerrainFactory(CameraComponent cameraComponent) { * @param cameraComponent Camera to render terrains to. Must be orthographic. * @param orientation orientation to render terrain at */ - public TerrainFactory(CameraComponent cameraComponent, TerrainOrientation orientation) { + public TerrainFactory(CameraComponent cameraComponent, TerrainComponent.TerrainOrientation orientation) { this.camera = (OrthographicCamera) cameraComponent.getCamera(); this.orientation = orientation; } /** - * Create a terrain of the given type, using the orientation of the factory. This can be extended - * to add additional game terrains. - * + * Create a terrain of the given type, using the orientation of the factory. + * This can be extended to add additional game terrains. * @param terrainType Terrain to create * @return Terrain component which renders the terrain */ public TerrainComponent createTerrain(TerrainType terrainType) { ResourceService resourceService = ServiceLocator.getResourceService(); switch (terrainType) { - case FOREST_DEMO: - TextureRegion orthoGrass = + case ALL_DEMO: + TextureRegion orthogonal = new TextureRegion(resourceService.getAsset("images/terrain_use.png", Texture.class)); - return createForestDemoTerrain(1f, orthoGrass); - + return createTerrain(1f, orthogonal); default: return null; } } - private TerrainComponent createForestDemoTerrain( - float tileWorldSize, TextureRegion grass) { - GridPoint2 tilePixelSize = new GridPoint2(grass.getRegionWidth(), grass.getRegionHeight()); - TiledMap tiledMap = createForestDemoTiles(tilePixelSize, grass); + /** + * Creates and returns a terrain component . + * + * @param tileWorldSize The world size of a tile. + * @param terrain The texture region representing grass. + * @return A TerrainComponent instance representing the created terrain. + */ + + private TerrainComponent createTerrain(float tileWorldSize, TextureRegion terrain) { + GridPoint2 tilePixelSize = new GridPoint2(terrain.getRegionWidth(), terrain.getRegionHeight()); + TiledMap tiledMap = createTiles(tilePixelSize, terrain); TiledMapRenderer renderer = createRenderer(tiledMap, tileWorldSize / tilePixelSize.x); return new TerrainComponent(camera, tiledMap, renderer, orientation, tileWorldSize); } + /** + * Creates and returns a renderer for the provided tiled map and scale. + * + * @param tiledMap The tiled map for which the renderer is created. + * @param tileScale The scale factor for the tiles. + * @return A TiledMapRenderer instance suitable for the given map and scale. + */ + private TiledMapRenderer createRenderer(TiledMap tiledMap, float tileScale) { switch (orientation) { case ORTHOGONAL: @@ -105,235 +90,43 @@ private TiledMapRenderer createRenderer(TiledMap tiledMap, float tileScale) { } } - private TiledMap createForestDemoTiles(GridPoint2 tileSize, TextureRegion grass) { + /** + * Creates a tiled map filled with forest demo tiles using the provided grass texture. + * + * @param tileSize The dimensions (width and height) of a tile in pixels. + * @param terrain The texture region representing grass. + * @return A TiledMap instance representing the created map. + */ + private TiledMap createTiles(GridPoint2 tileSize, TextureRegion terrain) { 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) { - case 0: // Desert - backgroundTextureRegion = new TextureRegion(ServiceLocator.getResourceService().getAsset("images/desert_bg.png", Texture.class)); - break; - case 1: // Ice - backgroundTextureRegion = new TextureRegion(ServiceLocator.getResourceService().getAsset("images/ice_bg.png", Texture.class)); - break; - case 2: // Lava - backgroundTextureRegion = new TextureRegion(ServiceLocator.getResourceService().getAsset("images/lava_bg.png", Texture.class)); - break; - default: - // Use a default background for other levels or planets - backgroundTextureRegion = new TextureRegion(ServiceLocator.getResourceService().getAsset("images/desert_bg.png", Texture.class)); - break; - } - /** - * 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); - - /** - * 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); - tiledMap.getLayers().add(grassLayer); - - /** - * Creates lanes of invisible tiles in the TiledMap. These lanes are added as separate layers - * and are typically used for gameplay purposes. - * - * @param tiledMap The TiledMap to which the lanes should be added. - * @param tileSize The size of each tile in pixels (width and height). - * @param numberOfLanes The total number of lanes to create. - * @param mapWidth The width of the TiledMap in tiles. - * @param mapHeight The height of the TiledMap in tiles. - * @return The modified TiledMap with the added invisible lanes. - */ - int numberOfLanes = 8; - int laneHeight = 1; // Height of each lane in tiles - int mapWidth = 20; - int mapHeight = 8; - int laneTileHeight = mapHeight / numberOfLanes; - - for (int i = 0; i < numberOfLanes; i++) { - TiledMapTileLayer laneLayer = new TiledMapTileLayer(mapWidth, laneHeight, tileSize.x, tileSize.y); - fillInvisibleTiles(laneLayer, new GridPoint2(mapWidth, laneHeight)); - tiledMap.getLayers().add(laneLayer); - } + TerrainTile Tile = new TerrainTile(terrain); + TiledMapTileLayer Layer = new TiledMapTileLayer(20, 8, tileSize.x, tileSize.y); + fillInvisibleTiles(Layer, new GridPoint2(20, 8), Tile); + tiledMap.getLayers().add(Layer); return tiledMap; } + /** - * Fills a TiledMapTileLayer with invisible tiles, creating a lgaayer of transparent tiles. + * Fills the provided tile layer with invisible tiles to create a transparent layer. * - * @param layer The TiledMapTileLayer to fill with invisible tiles. - * @param mapSize The size of the layer in tiles (width and height). + * @param layer The tile layer to fill. + * @param mapSize The size of the map in tiles. + * @param tile The tile used to fill the layer. */ - private void fillInvisibleTiles(TiledMapTileLayer layer, GridPoint2 mapSize) { - for (int x = 0; x < mapSize.x; x++) { - for (int y = 0; y < mapSize.y; y++) { - Cell cell = new Cell(); - // Set an invisible tile (using a transparent texture) - StaticTiledMapTile invisibleTile = new StaticTiledMapTile(new TextureRegion(whiteTexture)); - cell.setTile(invisibleTile); - layer.setCell(x, y, cell); - } - } - } - -//tile class - public static class Tile { - private int row; - private int col; - private Object object; - - public Tile(int row, int col) { - this.row = row; - this.col = col; - this.object = null; // Initially, no object is placed on the tile - } - - public void setObject(Object object) { - this.object = object; - } - - public Object getObject() { - return object; - } - - public String getLogCoordinates() { - return "(" + row + ", " + col + ")"; - } - } - -// grid class -public static class Grid { - private Tile[][] tiles; - - public Grid(int numRows, int numCols) { - tiles = new Tile[numRows][numCols]; - - for (int row = 0; row < numRows; row++) { - for (int col = 0; col < numCols; col++) { - tiles[row][col] = new Tile(row,col); - } - } - } - - public void placeObject(int row, int col, Object object) { - if (isValidCoordinate(row, col)) { - tiles[row][col].setObject(object); - } else { - System.out.println("Invalid coordinates."); - } - } - - public Object getObject(int row, int col) { - if (isValidCoordinate(row, col)) { - return tiles[row][col].getObject(); - } else { - System.out.println("Invalid coordinates."); - return null; - } - } - - public String getLogCoordinates(int row, int col) { - if (isValidCoordinate(row, col)) { - return tiles[row][col].getLogCoordinates(); - } else { - return "Invalid coordinates."; - } - } - - private boolean isValidCoordinate(int row, int col) { - return row >= 0 && row < tiles.length && col >= 0 && col < tiles[0].length; - } - - public void placeEntity(int row, int col, Object existingEntity) { - } - - public Object getEntity(int row, int col) { - return null; - } -} - -// Array class 1+2 -public class Array { - public static void main(String[] args) { - int numRows = 8; - int numCols = 20; - - Grid grid = new Grid(numRows, numCols); - - // Place an existing entity in a specific tile - int row = 3; - int col = 5; - // Replace 'Object' with the type of existing entity you want to place - Object existingEntity = new YourExistingEntity(); - - grid.placeEntity(row, col, existingEntity); - - // Get the entity from a tile - Object entity = grid.getEntity(row, col); - System.out.println("Entity at " + grid.getLogCoordinates(row, col) + ": " + entity); - } - - private static class YourExistingEntity { - } -} - - - - - - private static void fillTiles(TiledMapTileLayer layer, GridPoint2 mapSize, TerrainTile tile) { - BitmapFont font = new BitmapFont(); - TextButton.TextButtonStyle textButtonStyle = new TextButton.TextButtonStyle(); - textButtonStyle.font = font; - textButtonStyle.fontColor = Color.WHITE; + private void fillInvisibleTiles(TiledMapTileLayer layer, GridPoint2 mapSize, TerrainTile tile) { for (int x = 0; x < mapSize.x; x++) { - for (int y = 0; y < mapSize.y; y++) { + for (int y = 2; y < mapSize.y; y++) { Cell cell = new Cell(); cell.setTile(tile); layer.setCell(x, y, cell); - TextButton button = new TextButton("" + x + y * 20, textButtonStyle); - stage.addActor(button); } } } public enum TerrainType { - FOREST_DEMO + ALL_DEMO } } diff --git a/source/core/src/main/com/csse3200/game/rendering/Renderer.java b/source/core/src/main/com/csse3200/game/rendering/Renderer.java index 1f877d45f..5497f955a 100644 --- a/source/core/src/main/com/csse3200/game/rendering/Renderer.java +++ b/source/core/src/main/com/csse3200/game/rendering/Renderer.java @@ -95,7 +95,6 @@ public void render() { Matrix4 projMatrix = camera.getProjectionMatrix(); camera.update(); batch.setProjectionMatrix(projMatrix); - Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); batch.begin(); renderService.render(batch); diff --git a/source/core/src/main/com/csse3200/game/screens/LevelSelectScreen.java b/source/core/src/main/com/csse3200/game/screens/LevelSelectScreen.java index c92579e5f..93a78401c 100644 --- a/source/core/src/main/com/csse3200/game/screens/LevelSelectScreen.java +++ b/source/core/src/main/com/csse3200/game/screens/LevelSelectScreen.java @@ -103,16 +103,17 @@ private void spawnPlanetBorders() { dispose(); logger.info("Loading level {}", planet[4]); GameLevelData.setSelectedLevel(planet[4]); - if (planet[4] == 0) { - handleDesertPlanetClick(); - game.setScreen(new TurretSelectionScreen(game)); - } else if (planet[4] == 1) { - handleIcePlanetClick(); - game.setScreen(new TurretSelectionScreen(game)); - } else if (planet[4] == 2) { - handleLavaPlanetClick(); - game.setScreen(new TurretSelectionScreen(game)); - } + game.setScreen(new TurretSelectionScreen(game)); +// if (planet[4] == 0) { +// handleDesertPlanetClick(); +// game.setScreen(new TurretSelectionScreen(game)); +// } else if (planet[4] == 1) { +// handleIcePlanetClick(); +// game.setScreen(new TurretSelectionScreen(game)); +// } else if (planet[4] == 2) { +// handleLavaPlanetClick(); +// game.setScreen(new TurretSelectionScreen(game)); +// } } } } diff --git a/source/core/src/main/com/csse3200/game/screens/MainGameScreen.java b/source/core/src/main/com/csse3200/game/screens/MainGameScreen.java index 88b2150e1..4cadb1db3 100644 --- a/source/core/src/main/com/csse3200/game/screens/MainGameScreen.java +++ b/source/core/src/main/com/csse3200/game/screens/MainGameScreen.java @@ -2,6 +2,7 @@ import com.badlogic.gdx.Gdx; import com.badlogic.gdx.ScreenAdapter; +import com.badlogic.gdx.graphics.GL20; import com.badlogic.gdx.graphics.OrthographicCamera; import com.badlogic.gdx.graphics.Texture; import com.badlogic.gdx.graphics.g2d.SpriteBatch; @@ -40,7 +41,7 @@ */ public class MainGameScreen extends ScreenAdapter { private static final Logger logger = LoggerFactory.getLogger(MainGameScreen.class); - private static final String[] mainGameTextures = {"images/heart.png"}; + private static final String[] mainGameTextures = {"images/heart.png","images/ice_bg.png","images/lava_bg.png","images/desert_bg.png"}; private static final Vector2 CAMERA_POSITION = new Vector2(10f, 5.64f); private final GdxGame game; @@ -56,7 +57,7 @@ public class MainGameScreen extends ScreenAdapter { public static int viewportWidth = screenWidth; public static int viewportHeight= screenHeight; - + int selectedLevel = GameLevelData.getSelectedLevel(); private OrthographicCamera camera; private SpriteBatch batch; @@ -71,9 +72,7 @@ public MainGameScreen(GdxGame game) { batch = new SpriteBatch(); - Viewport viewport = new ScreenViewport(camera); - stage = new Stage(viewport, new SpriteBatch()); - + stage = new Stage(new ScreenViewport()); logger.debug("Initialising main game screen services"); @@ -108,8 +107,57 @@ public MainGameScreen(GdxGame game) { ForestGameArea forestGameArea = new ForestGameArea(terrainFactory); forestGameArea.create(); } + + /** + * Retrieves the background texture based on the currently selected game level. + * + *

The method returns different textures for each game level: + *

+ * + * @return The background {@link Texture} corresponding to the selected level. + */ + public Texture getBackgroundTexture() { + Texture background; + switch (selectedLevel) { + // Desert + case 1: // Ice + background = ServiceLocator.getResourceService().getAsset("images/ice_bg.png", Texture.class); + break; + case 2: // Lava + background = ServiceLocator.getResourceService().getAsset("images/lava_bg.png", Texture.class); + break; + default: + // Use a default background for other levels or planets + background = ServiceLocator.getResourceService().getAsset("images/desert_bg.png", Texture.class); + break; + } + return background; + } + @Override public void render(float delta) { + // Clear the screen + Gdx.gl.glClearColor(0, 0, 0, 1); + Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); + + // Update the camera and set the batch's projection matrix + camera.update(); + batch.setProjectionMatrix(camera.combined); + + // Begin the batch + batch.begin(); + + // Draw the background texture. + batch.draw(backgroundTexture, 0, 0, viewportWidth, viewportHeight); + + // End the batch + batch.end(); + + // Continue with other rendering logic physicsEngine.update(); ServiceLocator.getEntityService().update(); @@ -118,19 +166,9 @@ public void render(float delta) { ui.getEvents().trigger("lose"); } - batch.setProjectionMatrix(camera.combined); - batch.begin(); - batch.draw(backgroundTexture, 0, 0, viewportWidth, viewportHeight); - batch.end(); - renderer.render(); - stage.act(Math.min(Gdx.graphics.getDeltaTime(), 1 / 30f)); - stage.draw(); } - - - @Override public void resize(int width, int height) { renderer.resize(width, height); @@ -165,8 +203,8 @@ private void loadAssets() { logger.debug("Loading assets"); ResourceService resourceService = ServiceLocator.getResourceService(); resourceService.loadTextures(mainGameTextures); - backgroundTexture = new Texture("images/Dusty_MoonBG.png"); // Load the background image ServiceLocator.getResourceService().loadAll(); + backgroundTexture = getBackgroundTexture(); // Load the background image } private void unloadAssets() {