Skip to content

Commit

Permalink
Merge branch 'Team-3-maps-main' into Team-5--Economy
Browse files Browse the repository at this point in the history
  • Loading branch information
Hasakev committed Sep 5, 2023
2 parents a8027cd + 05b5467 commit 643c705
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 90 deletions.
Binary file added source/core/assets/images/Dusty_MoonBG.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/terrain_use.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 13 additions & 6 deletions source/core/src/main/com/csse3200/game/areas/ForestGameArea.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,21 @@
public class ForestGameArea extends GameArea {
private static final Logger logger = LoggerFactory.getLogger(ForestGameArea.class);

private static final int NUM_BUILDINGS = 4;

private static final int NUM_WALLS = 7;
private static final GridPoint2 MAP_SIZE = new GridPoint2(16, 10);

private static final int NUM_TREES = 0;
private static final int NUM_GHOSTS = 0;
private static final int NUM_GRUNTS = 5;
private static final int NUM_BUILDINGS = 4;

private static final int NUM_BOSS=4;
private static final int NUM_WALLS = 7;

private Timer bossSpawnTimer;
private int bossSpawnInterval = 10000; // 1 minute in milliseconds


private static final int NUM_WEAPON_TOWERS = 3;
private static final GridPoint2 PLAYER_SPAWN = new GridPoint2(0, 15);
// Temporary spawn point for testing
Expand Down Expand Up @@ -84,8 +90,13 @@ public class ForestGameArea extends GameArea {
"images/towers/wallTower.png",
"images/background/building2.png",
"images/iso_grass_3.png",

"images/terrain_use.png",
"images/Dusty_MoonBG.png",

"images/economy/scrap.png",
"images/towers/mine_tower.png"

};
private static final String[] forestTextureAtlases = {
"images/terrain_iso_grass.atlas",
Expand Down Expand Up @@ -220,10 +231,6 @@ private void spawnBuilding2() {
private void spawnMountains() {
ArrayList<GridPoint2> fixedPositions = new ArrayList<>(); //Generating ArrayList

fixedPositions.add(new GridPoint2(5, 8));
fixedPositions.add(new GridPoint2(12, 4));
fixedPositions.add(new GridPoint2(20, 10));
fixedPositions.add(new GridPoint2(33, 17));

for (GridPoint2 fixedPos : fixedPositions) {
Entity tree = ObstacleFactory.createMountain();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,38 +1,49 @@
package com.csse3200.game.areas.terrain;

import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.OrthographicCamera;
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.HexagonalTiledMapRenderer;
import com.badlogic.gdx.maps.tiled.renderers.IsometricTiledMapRenderer;
import com.badlogic.gdx.maps.tiled.renderers.OrthogonalTiledMapRenderer;
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.utils.math.RandomUtils;
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;

/** Factory for creating game terrains. */
public class TerrainFactory {
private static final GridPoint2 MAP_SIZE = new GridPoint2(40, 26);
private static final int TUFT_TILE_COUNT = 0;
private static final int ROCK_TILE_COUNT = 0;
public class TerrainFactory {
public static final GridPoint2 MAP_SIZE = new GridPoint2(20, 8);

private final OrthographicCamera camera;
private static OrthographicCamera camera;
private final TerrainOrientation orientation;

private static Stage stage;
/**
* Create a terrain factory with Orthogonal orientation
*
* @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();
}

/**
Expand All @@ -44,8 +55,12 @@ public TerrainFactory(CameraComponent cameraComponent) {
public TerrainFactory(CameraComponent cameraComponent, 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.
Expand All @@ -58,39 +73,18 @@ public TerrainComponent createTerrain(TerrainType terrainType) {
switch (terrainType) {
case FOREST_DEMO:
TextureRegion orthoGrass =
new TextureRegion(resourceService.getAsset("images/terrain 2 normal.png", Texture.class));
TextureRegion orthoTuft =
new TextureRegion(resourceService.getAsset("images/grass_2.png", Texture.class));
TextureRegion orthoRocks =
new TextureRegion(resourceService.getAsset("images/grass_3.png", Texture.class));
return createForestDemoTerrain(0.5f, orthoGrass, orthoTuft, orthoRocks);
case FOREST_DEMO_ISO:

TextureRegion isoGrass =
new TextureRegion(resourceService.getAsset("images/iso_grass_1.png", Texture.class));
TextureRegion isoTuft =
new TextureRegion(resourceService.getAsset("images/iso_grass_2.png", Texture.class));
TextureRegion isoRocks =
new TextureRegion(resourceService.getAsset("images/iso_grass_3.png", Texture.class));
return createForestDemoTerrain(1f, isoGrass, isoTuft, isoRocks );
case FOREST_DEMO_HEX:

TextureRegion hexGrass =
new TextureRegion(resourceService.getAsset("images/terrain 2 hex.png", Texture.class));
TextureRegion hexTuft =
new TextureRegion(resourceService.getAsset("images/hex_grass_2.png", Texture.class));
TextureRegion hexRocks =
new TextureRegion(resourceService.getAsset("images/hex_grass_3.png", Texture.class));
return createForestDemoTerrain(1f , hexGrass, hexTuft, hexRocks);
new TextureRegion(resourceService.getAsset("images/terrain_use.png", Texture.class));
return createForestDemoTerrain(1f, orthoGrass);

default:
return null;
}
}

private TerrainComponent createForestDemoTerrain(
float tileWorldSize, TextureRegion grass, TextureRegion grassTuft, TextureRegion rocks) {
float tileWorldSize, TextureRegion grass) {
GridPoint2 tilePixelSize = new GridPoint2(grass.getRegionWidth(), grass.getRegionHeight());
TiledMap tiledMap = createForestDemoTiles(tilePixelSize, grass, grassTuft, rocks);
TiledMap tiledMap = createForestDemoTiles(tilePixelSize, grass);
TiledMapRenderer renderer = createRenderer(tiledMap, tileWorldSize / tilePixelSize.x);
return new TerrainComponent(camera, tiledMap, renderer, orientation, tileWorldSize);
}
Expand All @@ -99,64 +93,40 @@ private TiledMapRenderer createRenderer(TiledMap tiledMap, float tileScale) {
switch (orientation) {
case ORTHOGONAL:
return new OrthogonalTiledMapRenderer(tiledMap, tileScale);
case ISOMETRIC:
return new IsometricTiledMapRenderer(tiledMap, tileScale);
case HEXAGONAL:
return new HexagonalTiledMapRenderer(tiledMap, tileScale);
default:
return null;
}
}

private TiledMap createForestDemoTiles(
GridPoint2 tileSize, TextureRegion grass, TextureRegion grassTuft, TextureRegion rocks) {
GridPoint2 tileSize, TextureRegion grass) {
TiledMap tiledMap = new TiledMap();
TerrainTile grassTile = new TerrainTile(grass);
TerrainTile grassTuftTile = new TerrainTile(grassTuft);
TerrainTile rockTile = new TerrainTile(rocks);
TiledMapTileLayer layer = new TiledMapTileLayer(MAP_SIZE.x, MAP_SIZE.y, tileSize.x, tileSize.y);

// Create base grass
fillTiles(layer, MAP_SIZE, grassTile);

// Add some grass and rocks
fillTilesAtRandom(layer, MAP_SIZE, grassTuftTile, TUFT_TILE_COUNT);
fillTilesAtRandom(layer, MAP_SIZE, rockTile, ROCK_TILE_COUNT);

tiledMap.getLayers().add(layer);
return tiledMap;
}

private static void fillTilesAtRandom(
TiledMapTileLayer layer, GridPoint2 mapSize, TerrainTile tile, int amount) {
GridPoint2 min = new GridPoint2(0, 0);
GridPoint2 max = new GridPoint2(mapSize.x - 1, mapSize.y - 1);

for (int i = 0; i < amount; i++) {
GridPoint2 tilePos = RandomUtils.random(min, max);
Cell cell = layer.getCell(tilePos.x, tilePos.y);
cell.setTile(tile);
}
}

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;
for (int x = 0; x < mapSize.x; x++) {
for (int y = 0; 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);
}
}
}

/**
* This enum should contain the different terrains in your game, e.g. forest, cave, home, all with
* the same oerientation. But for demonstration purposes, the base code has the same level in 3
* different orientations.
*/
public enum TerrainType {
FOREST_DEMO,
FOREST_DEMO_ISO,
FOREST_DEMO_HEX
FOREST_DEMO
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package com.csse3200.game.areas.terrain;

public class TerrainGrid {
}
34 changes: 16 additions & 18 deletions source/core/src/main/com/csse3200/game/screens/MainGameScreen.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package com.csse3200.game.screens;
import com.badlogic.gdx.graphics.Pixmap;
import com.badlogic.gdx.graphics.Pixmap;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.ScreenAdapter;
Expand All @@ -13,6 +13,7 @@
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
import com.badlogic.gdx.utils.viewport.FitViewport;
import com.badlogic.gdx.utils.viewport.ScreenViewport;
import com.badlogic.gdx.utils.viewport.Viewport;
import com.csse3200.game.GdxGame;
Expand Down Expand Up @@ -50,7 +51,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 Vector2 CAMERA_POSITION = new Vector2(10f, 7.5f);
private static final Vector2 CAMERA_POSITION = new Vector2(10f, 5f);

private final GdxGame game;
private final Renderer renderer;
Expand All @@ -59,6 +60,8 @@ public class MainGameScreen extends ScreenAdapter {
private final Stage stage;
static int screenWidth = Gdx.graphics.getWidth();
static int screenHeight = Gdx.graphics.getHeight();
Viewport viewport = new FitViewport(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());


public static int viewportWidth = screenWidth;
public static int viewportHeight= screenHeight;
Expand All @@ -72,31 +75,22 @@ public class MainGameScreen extends ScreenAdapter {

public MainGameScreen(GdxGame game) {
this.game = game;
camera = new OrthographicCamera();
camera.setToOrtho(false, viewportWidth, viewportHeight);
camera.position.set(viewportWidth / 2, viewportHeight / 2, 0);

batch = new SpriteBatch();

Pixmap pixmap = new Pixmap(1, 1, Pixmap.Format.RGBA8888);
pixmap.setColor(1, 1, 1, 1);
pixmap.fill();
whiteTexture = new Texture(pixmap);
pixmap.dispose();

camera = new OrthographicCamera();
camera.setToOrtho(false, viewportWidth, viewportHeight);
camera.position.set(viewportWidth / 2, viewportHeight / 2, 0);
Viewport viewport = new ScreenViewport(camera);
stage = new Stage(viewport, new SpriteBatch());


BitmapFont font = new BitmapFont();
TextButton.TextButtonStyle textButtonStyle = new TextButton.TextButtonStyle();
textButtonStyle.font = font;
textButtonStyle.fontColor = Color.WHITE;
for (int y = 0; y < 8; y++) {
for (int x = 0; x < 20; x++) {
TextButton button = new TextButton("" + x + y * 20, textButtonStyle);
stage.addActor(button);
}
}


logger.debug("Initialising main game screen services");
ServiceLocator.registerTimeSource(new GameTime());
Expand Down Expand Up @@ -132,14 +126,18 @@ public MainGameScreen(GdxGame game) {
public void render(float delta) {
physicsEngine.update();
ServiceLocator.getEntityService().update();

batch.setProjectionMatrix(camera.combined);
batch.begin();
batch.draw(backgroundTexture, 0, 0, viewportWidth, viewportHeight);
batch.end();


batch.setProjectionMatrix(camera.combined);
batch.begin();
for (int i = 0; i < NUM_LANES; i++) {
float yPosition = i * LANE_HEIGHT;
batch.draw(whiteTexture, 0, yPosition, viewportWidth, 2);
batch.draw(whiteTexture, 0, yPosition, viewportWidth, 5);
}
batch.end();

Expand Down Expand Up @@ -185,7 +183,7 @@ private void loadAssets() {
logger.debug("Loading assets");
ResourceService resourceService = ServiceLocator.getResourceService();
resourceService.loadTextures(mainGameTextures);
backgroundTexture = new Texture("images/background/background1.png"); // Load the background image
backgroundTexture = new Texture("images/Dusty_MoonBG.png"); // Load the background image
ServiceLocator.getResourceService().loadAll();
}

Expand Down

0 comments on commit 643c705

Please sign in to comment.