Skip to content

Commit

Permalink
Fixed merge conflicts after merging main.
Browse files Browse the repository at this point in the history
  • Loading branch information
BlairCannon97 committed Sep 11, 2023
2 parents e075616 + 456a6d7 commit 24a9daf
Show file tree
Hide file tree
Showing 23 changed files with 1,074 additions and 182 deletions.
Binary file modified source/core/assets/images/ingamebg.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
42 changes: 33 additions & 9 deletions source/core/src/main/com/csse3200/game/areas/ForestGameArea.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
import com.badlogic.gdx.math.GridPoint2;
import com.badlogic.gdx.math.MathUtils;
import com.badlogic.gdx.math.Vector2;
import com.csse3200.game.components.CombatStatsComponent;
import com.csse3200.game.components.ProjectileEffects;
import com.csse3200.game.areas.terrain.TerrainFactory;
import com.csse3200.game.areas.terrain.TerrainFactory.TerrainType;
import com.csse3200.game.components.player.PlayerStatsDisplay;
import com.csse3200.game.entities.Entity;
import com.csse3200.game.entities.factories.*;
import com.csse3200.game.physics.PhysicsLayer;
Expand All @@ -30,6 +32,8 @@
public class ForestGameArea extends GameArea {
private static final Logger logger = LoggerFactory.getLogger(ForestGameArea.class);

// Counts the number of humans left, if this reaches zero, game over.
private int endStateCounter = 2;
private static final int NUM_BUILDINGS = 4;

private static final int NUM_WALLS = 7;
Expand All @@ -40,10 +44,10 @@ public class ForestGameArea extends GameArea {

private static final int NUM_BOSS=4;


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, 0);
// Temporary spawn point for testing
Expand Down Expand Up @@ -177,6 +181,8 @@ public void create() {
displayUI();
spawnTerrain();

// Set up infrastructure for end game tracking

player = spawnPlayer();
player.getEvents().addListener("spawnWave", this::spawnXenoGrunts);

Expand All @@ -197,9 +203,9 @@ public void create() {
spawnWeaponTower();
spawnTNTTower();
spawnDroidTower();
spawnEngineer();
spawnGapScanners();
spawnIncome();
bossKing1 = spawnBossKing1();
// bossKing1 = spawnBossKing1();
bossKing2 = spawnBossKing2();


Expand Down Expand Up @@ -300,7 +306,7 @@ private void spawnGhosts() {
private Entity spawnBossKing1() {
GridPoint2 minPos = new GridPoint2(0, 0);
GridPoint2 maxPos = terrain.getMapBounds(0).sub(2, 2);
GridPoint2 randomPos
GridPoint2 randomPos
= new GridPoint2(0, 0);
Entity ghostKing = NPCFactory.createGhostKing(player);
spawnEntityAt(ghostKing, randomPos, true, true);
Expand Down Expand Up @@ -604,12 +610,11 @@ private void spawnIncome() {
spawnEntityAt(towerfactory, randomPos, true, true);
}
}

private void spawnEngineer() {

for (int i = 0; i < terrain.getMapBounds(0).x; i += 3) {
Entity engineer = EngineerFactory.createEngineer();
spawnEntityAt(engineer, new GridPoint2(1, i), true, true);
private void spawnGapScanners() {
for (int i = 0; i < terrain.getMapBounds(0).y; i++) {
Entity scanner = GapScannerFactory.createScanner();
spawnEntityAt(scanner, new GridPoint2(0, i), true, true);
}
// GridPoint2 minPos = new GridPoint2(0, 0);
// GridPoint2 maxPos = new GridPoint2(5, terrain.getMapBounds(0).sub(2, 2).y);
Expand All @@ -618,4 +623,23 @@ private void spawnEngineer() {
// Entity engineer = EngineerFactory.createEngineer();
// spawnEntityAt(engineer, randomPos, true, true);
}

// private void gameTrackerStart() {
// Entity endGameTracker = new Entity();
//
// endGameTracker
// .addComponent(new CombatStatsComponent(2, 0))
// .addComponent(new PlayerStatsDisplay());
//// .getEvents().addListener("engineerKilled" , this::decrementCounter);
// endGameTracker.create();
// }
//
// private void decrementCounter() {
// this.endStateCounter -= 1;
// logger.info("Engineer killed");
// if (endStateCounter <= 0) {
// // we've reached the end, game over
// this.dispose();
// }
// }
}
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,111 @@ private void fillInvisibleTiles(TiledMapTileLayer layer, GridPoint2 mapSize) {
}
}

//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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ public class HumanAnimationController extends Component {
private static final String FIRE_AUTO_SFX = "sounds/engineers/firing_auto.mp3";
private static final String FIRE_SINGLE_SFX = "sounds/engineers/firing_single.mp3";

AnimationRenderComponent animator;
Sound fireAutoSound = ServiceLocator.getResourceService().getAsset(
private AnimationRenderComponent animator;
private final Sound fireAutoSound = ServiceLocator.getResourceService().getAsset(
FIRE_AUTO_SFX, Sound.class);
Sound fireSingleSound = ServiceLocator.getResourceService().getAsset(
private final Sound fireSingleSound = ServiceLocator.getResourceService().getAsset(
FIRE_SINGLE_SFX, Sound.class);

/**
Expand All @@ -56,7 +56,7 @@ public void create() {
entity.getEvents().addListener(PREP, this::animatePrep);
entity.getEvents().addListener(WALK_PREP, this::animatePrepWalk);
entity.getEvents().addListener(FIRING_SINGLE, this::animateSingleFiring);
entity.getEvents().addListener(FIRING_AUTO, this::animateFiring);
entity.getEvents().addListener(FIRING_AUTO, this::animateFiringAuto);
entity.getEvents().addListener(HIT, this::animateHit);
entity.getEvents().addListener(DEATH, this::animateDeath);
}
Expand Down Expand Up @@ -110,7 +110,7 @@ void animateSingleFiring() {
* Callback that starts the shoot animation in auto mode and plays the auto fire sound.
* Currently unused, but intended to be incorporated as engineer functionality expands.
*/
void animateFiring() {
void animateFiringAuto() {
animator.startAnimation(FIRE_AUTO_ANIM);
fireAutoSound.play();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@
import com.csse3200.game.ai.tasks.DefaultTask;
import com.csse3200.game.ai.tasks.PriorityTask;
import com.csse3200.game.components.CombatStatsComponent;
import com.csse3200.game.components.ProjectileEffects;
import com.csse3200.game.entities.Entity;
import com.csse3200.game.entities.factories.ProjectileFactory;
import com.csse3200.game.physics.PhysicsEngine;
import com.csse3200.game.physics.PhysicsLayer;
import com.csse3200.game.physics.raycast.RaycastHit;
Expand All @@ -24,13 +21,15 @@ public class DroidCombatTask extends DefaultTask implements PriorityTask {
private static final int INTERVAL = 1; // time interval to scan for enemies in seconds
private static final short TARGET = PhysicsLayer.NPC; // The type of targets that the tower will detect
// the following four constants are the event names that will be triggered in the state machine
private static final String GO_UP = "goUpStart";
private static final String GO_DOWN = "goDownStart";
private static final String ATTACK_UP = "attackUpStart";
private static final String ATTACK_DOWN = "attackDownStart";
private static final String WALK = "walkStart";
private static final String DEATH = "deathStart";
private static final String IDLE = "idleStart";
public static final String GO_UP = "goUpStart";
public static final String GO_DOWN = "goDownStart";
public static final String ATTACK_UP = "attackUpStart";
public static final String ATTACK_DOWN = "attackDownStart";
public static final String WALK = "walkStart";
public static final String DEATH = "deathStart";
public static final String IDLE = "idleStart";
public static final String SHOOT_UP = "ShootUp";
public static final String SHOOT_DOWN = "ShootDown";


// class attributes
Expand All @@ -43,10 +42,10 @@ public class DroidCombatTask extends DefaultTask implements PriorityTask {
private long endTime;
private final RaycastHit hit = new RaycastHit();

private enum STATE {
public enum STATE {
IDLE, UP, DOWN, SHOOT_UP, SHOOT_DOWN, WALK, DIE
}
private STATE towerState = STATE.WALK;
public STATE towerState = STATE.WALK;

/**
* @param priority Task priority when targets are detected (0 when nothing detected). Must be a positive integer.
Expand Down Expand Up @@ -105,6 +104,7 @@ public void updateTowerState() {
case IDLE -> {
if (isTargetVisible()) {
owner.getEntity().getEvents().trigger(ATTACK_UP);
owner.getEntity().getEvents().trigger(SHOOT_UP);
towerState = STATE.DOWN;
} else {
owner.getEntity().getEvents().trigger(IDLE);
Expand All @@ -113,12 +113,7 @@ public void updateTowerState() {
case SHOOT_DOWN -> {
if (isTargetVisible()) {
owner.getEntity().getEvents().trigger(ATTACK_DOWN);
Entity Projectile = ProjectileFactory.createEffectProjectile(PhysicsLayer.NPC, new Vector2(100,
owner.getEntity().getPosition().y), new Vector2(2,2), ProjectileEffects.SLOW, false);
Projectile.setScale(new Vector2(0.5f,0.5f));
Projectile.setPosition((float) (owner.getEntity().getPosition().x + 0.2),
(float) (owner.getEntity().getPosition().y - 0.2));
ServiceLocator.getEntityService().register(Projectile);
owner.getEntity().getEvents().trigger(SHOOT_DOWN);
towerState = STATE.UP;
} else {
owner.getEntity().getEvents().trigger(GO_UP);
Expand All @@ -129,13 +124,8 @@ public void updateTowerState() {
if (isTargetVisible()) {

owner.getEntity().getEvents().trigger(ATTACK_UP);
owner.getEntity().getEvents().trigger(SHOOT_UP);
towerState = STATE.DOWN;
Entity Projectile = ProjectileFactory.createEffectProjectile(PhysicsLayer.NPC, new Vector2(100,
owner.getEntity().getPosition().y), new Vector2(2,2), ProjectileEffects.SLOW, false);
Projectile.setScale(new Vector2(0.5f,0.5f));
Projectile.setPosition((float) (owner.getEntity().getPosition().x + 0.2),
(float) (owner.getEntity().getPosition().y + 0.5));
ServiceLocator.getEntityService().register(Projectile);
} else {
owner.getEntity().getEvents().trigger(IDLE);
towerState = STATE.IDLE;
Expand Down Expand Up @@ -173,7 +163,15 @@ public void updateTowerState() {
@Override
public void stop() {
super.stop();
// owner.getEntity().getEvents().trigger(STOW);
}

/**
* Returns the current state of the tower.
*
* @return the current state of the tower.
*/
public STATE getState() {
return this.towerState;
}

/**
Expand All @@ -189,8 +187,10 @@ public int getPriority() {
* Uses a raycast to determine whether there are any targets in detection range
* @return true if a target is visible, false otherwise
*/
private boolean isTargetVisible() {
public boolean isTargetVisible() {
// If there is an obstacle in the path to the max range point, mobs visible.
return physics.raycast(towerPosition, maxRangePosition, TARGET, hit);
}


}
Loading

0 comments on commit 24a9daf

Please sign in to comment.