Skip to content

Commit

Permalink
Merge branch 'main' into Team-1--Projectiles
Browse files Browse the repository at this point in the history
  • Loading branch information
MiniSoda17 committed Sep 10, 2023
2 parents 1730433 + 456a6d7 commit aba48cc
Show file tree
Hide file tree
Showing 21 changed files with 969 additions and 182 deletions.
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(1, 4);
Expand Down Expand Up @@ -185,6 +189,8 @@ public void create() {
displayUI();
spawnTerrain();

// Set up infrastructure for end game tracking

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

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


Expand Down Expand Up @@ -308,7 +314,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 @@ -612,12 +618,30 @@ 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);
}
}

// 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 @@ -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.45f, 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);
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
import com.badlogic.gdx.math.Vector2;
import com.csse3200.game.ai.tasks.DefaultTask;
import com.csse3200.game.ai.tasks.PriorityTask;
import com.csse3200.game.entities.Entity;
import com.csse3200.game.entities.EntityService;
import com.csse3200.game.physics.PhysicsEngine;
import com.csse3200.game.physics.PhysicsLayer;
import com.csse3200.game.physics.raycast.RaycastHit;
Expand All @@ -22,10 +20,10 @@ public class TNTTowerCombatTask 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 DIG = "digStart";
private static final String EXPLOSION = "explodeStart";
private static final String DEFAULT = "defaultStart";
private static final String DAMAGE = "TNTDamageStart";
public static final String DIG = "digStart";
public static final String EXPLOSION = "explodeStart";
public static final String DEFAULT = "defaultStart";
public static final String DAMAGE = "TNTDamageStart";


// class attributes
Expand All @@ -37,9 +35,9 @@ public class TNTTowerCombatTask extends DefaultTask implements PriorityTask {
private final GameTime timeSource;
private long endTime;
private final RaycastHit hit = new RaycastHit();
private boolean readToDelete = false;
public boolean readToDelete = false;

private enum STATE {
public enum STATE {
IDLE, EXPLODE, REMOVE
}
private STATE towerState = STATE.IDLE;
Expand Down Expand Up @@ -136,36 +134,29 @@ public int getPriority() {
}

/**
* Fetches the active priority of the Task if a target is visible.
* @return (int) active priority if a target is visible, -1 otherwise
* Returns the current state of the tower.
*
* @return the current state of the tower.
*/
private int getActivePriority() {

return !isTargetVisible() ? 0 : priority;
}

/**
* Fetches the inactive priority of the Task if a target is not visible.
* @return (int) -1 if a target is not visible, active priority otherwise
*/
private int getInactivePriority() {

return isTargetVisible() ? priority : 0;
public STATE getState() {
return this.towerState;
}

/**
* 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);
}

private boolean isReadyToDelete() {
public boolean isReadyToDelete() {

return readToDelete;
}


}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import org.slf4j.LoggerFactory;

/**
* Move to a given position, finishing when you get close enough. Requires an entity with a
* Move a human entity to a given position, finishing when you get close enough. Requires an entity with a
* PhysicsMovementComponent.
*/
public class HumanMovementTask extends DefaultTask {
Expand Down
Loading

0 comments on commit aba48cc

Please sign in to comment.