Skip to content

Commit

Permalink
added BG's, created global method to access different level(Game leve…
Browse files Browse the repository at this point in the history
…l data)
  • Loading branch information
Gaganx0 committed Sep 10, 2023
1 parent 0eda890 commit d872e4f
Show file tree
Hide file tree
Showing 7 changed files with 92 additions and 57 deletions.
File renamed without changes
Binary file added source/core/assets/images/ice_bg.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added 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 @@ -55,7 +55,9 @@ public class ForestGameArea extends GameArea {

// Required to load assets before using them
private static final String[] forestTextures = {
"images/ingamebg.png",
"images/desert_bg.png",
"images/ice_bg.png",
"images/lava_bg.png",
"images/box_boy_leaf.png",
"images/background/building1.png",
"images/ghost_1.png",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
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.screens.GameLevelData;
import com.csse3200.game.services.ResourceService;
import com.csse3200.game.services.ServiceLocator;

Expand All @@ -33,6 +34,7 @@ public class TerrainFactory {
private static OrthographicCamera camera;
private final TerrainOrientation orientation;
private static Stage stage;
int selectedLevel = GameLevelData.getSelectedLevel();
private Texture whiteTexture;

/**
Expand Down Expand Up @@ -109,7 +111,23 @@ private TiledMap createForestDemoTiles(GridPoint2 tileSize, TextureRegion grass)

// Create a background layer
TiledMapTileLayer backgroundLayer = new TiledMapTileLayer(20, 8, tileSize.x, tileSize.y);
TextureRegion backgroundTextureRegion = new TextureRegion(ServiceLocator.getResourceService().getAsset("images/ingamebg.png", Texture.class));
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;
}

// Create a single cell for the entire background image
Cell cell = new Cell();
Expand Down Expand Up @@ -152,7 +170,7 @@ private void fillInvisibleTiles(TiledMapTileLayer layer, GridPoint2 mapSize) {
}
}

//tile class
//tile class
public static class Tile {
private int row;
private int col;
Expand All @@ -177,81 +195,81 @@ public String getLogCoordinates() {
}
}

// grid class
public static class Grid {
private Tile[][] tiles;
// grid class
public static class Grid {
private Tile[][] tiles;

public Grid(int numRows, int numCols) {
tiles = new Tile[numRows][numCols];
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);
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 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 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.";
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;
}
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 void placeEntity(int row, int col, Object existingEntity) {
}

public Object getEntity(int row, int col) {
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;
// 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);
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();
// 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);
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);
}
// 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 class YourExistingEntity {
}
}
}

private static void fillTiles(TiledMapTileLayer layer, GridPoint2 mapSize, TerrainTile tile) {
BitmapFont font = new BitmapFont();
Expand All @@ -272,4 +290,4 @@ private static void fillTiles(TiledMapTileLayer layer, GridPoint2 mapSize, Terra
public enum TerrainType {
FOREST_DEMO
}
}
}
13 changes: 13 additions & 0 deletions source/core/src/main/com/csse3200/game/screens/GameLevelData.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.csse3200.game.screens;

public class GameLevelData {
private static int selectedLevel = -1;

public static int getSelectedLevel() {
return selectedLevel;
}

public static void setSelectedLevel(int level) {
selectedLevel = level;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public class LevelSelectScreen extends ScreenAdapter {
Logger logger = LoggerFactory.getLogger(LevelSelectScreen.class);
private final GdxGame game;
private SpriteBatch batch;
private int selectedLevel = -1;

private static final String INTRO_TEXT = "Select a Planet for Conquest";

Expand Down Expand Up @@ -100,6 +101,7 @@ private void spawnPlanetBorders() {
if (Gdx.input.justTouched()) {
dispose();
logger.info("Loading level {}", planet[4]);
GameLevelData.setSelectedLevel(planet[4]);
if (planet[4] == 0) {
handleDesertPlanetClick();
} else if (planet[4] == 1) {
Expand Down

0 comments on commit d872e4f

Please sign in to comment.