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 9d384f95a..edade1e2a 100644 --- a/source/core/src/main/com/csse3200/game/areas/ForestGameArea.java +++ b/source/core/src/main/com/csse3200/game/areas/ForestGameArea.java @@ -87,17 +87,15 @@ 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/economy/crystal.png", "images/economy/econ-tower.png", - - "images/towers/mine_tower.png", "images/towers/TNTTower.png" + "images/economy/scrap.png", + "images/towers/mine_tower.png" }; private static final String[] forestTextureAtlases = { "images/economy/econ-tower.atlas", @@ -112,6 +110,7 @@ public class ForestGameArea extends GameArea { "images/towers/TNTTower.atlas", "images/projectiles/basic_projectile.atlas", "images/projectiles/mobProjectile.atlas" + "images/mobs/rangeBossRight.atlas" }; private static final String[] forestSounds = { "sounds/Impact4.ogg", @@ -153,7 +152,9 @@ public void create() { loadAssets(); displayUI(); spawnTerrain(); - + spawnBuilding1(); + spawnBuilding2(); + spawnMountains(); player = spawnPlayer(); player.getEvents().addListener("spawnWave", this::spawnXenoGrunts); @@ -166,6 +167,10 @@ public void create() { spawnGhosts(); spawnWeaponTower(); spawnEngineer(); + spawnWeaponTower(); + spawnIncome(); + spawnScrap(); + bossKing1 = spawnBossKing1(); bossKing2 = spawnBossKing2(); spawnTNTTower(); diff --git a/source/core/src/main/com/csse3200/game/components/tasks/MobAttackTask.java b/source/core/src/main/com/csse3200/game/components/tasks/MobAttackTask.java index 835786ea0..3fcf0692d 100644 --- a/source/core/src/main/com/csse3200/game/components/tasks/MobAttackTask.java +++ b/source/core/src/main/com/csse3200/game/components/tasks/MobAttackTask.java @@ -8,6 +8,7 @@ import com.badlogic.gdx.math.Vector2; import com.csse3200.game.physics.PhysicsEngine; import com.csse3200.game.physics.PhysicsLayer; +import com.csse3200.game.physics.components.PhysicsMovementComponent; import com.csse3200.game.physics.raycast.RaycastHit; import com.csse3200.game.services.ServiceLocator; import com.csse3200.game.services.GameTime; @@ -65,9 +66,11 @@ public void start() { super.start(); startTime = timeSource.getTime(); this.mobPosition = owner.getEntity().getCenterPosition(); - this.maxRangePosition.set(0, mobPosition.y); -// owner.getEntity().getEvents().trigger(IDLE); + this.maxRangePosition.set(4, mobPosition.y); + owner.getEntity().getEvents().trigger(IDLE); endTime = timeSource.getTime() + (INTERVAL * 500); + owner.getEntity().getEvents().trigger("shootStart"); + System.out.println("mob attack started for " + owner.getEntity().getId()); } /** @@ -105,21 +108,27 @@ public void updateMobState() { mobState = STATE.FIRING; owner.getEntity().getEvents().trigger(FIRING); } + System.out.println("idle for " + owner.getEntity().getId()); + } -// case DEPLOY -> { -// // currently deploying, -// if (isTargetVisible()) { -// //owner.getEntity().getEvents().trigger(FIRING); -// mobState = STATE.FIRING; -// owner.getEntity().getEvents().trigger("shootStart"); -// } else { -// //owner.getEntity().getEvents().trigger(STOW); -// mobState = STATE.STOW; -// } -// } + case DEPLOY -> { + // currently deploying, + if (isTargetVisible()) { + owner.getEntity().getEvents().trigger(FIRING); + mobState = STATE.FIRING; + owner.getEntity().getComponent(PhysicsMovementComponent.class).setEnabled(false); + } else { + owner.getEntity().getEvents().trigger(STOW); + mobState = STATE.STOW; + + } + System.out.println("deploying for " + owner.getEntity().getId()); + + } case FIRING -> { +// owner.getEntity().getComponent(PhysicsMovementComponent.class).setEnabled(false); // targets gone - stop firing if (!isTargetVisible()) { //owner.getEntity().getEvents().trigger(STOW); @@ -131,18 +140,23 @@ public void updateMobState() { ServiceLocator.getEntityService().register(newProjectile); owner.getEntity().getEvents().trigger(FIRING); } + System.out.println("firing for " + owner.getEntity().getId()); + owner.getEntity().getComponent(PhysicsMovementComponent.class).setEnabled(true); + } -// case STOW -> { -// // currently stowing -// if (isTargetVisible()) { -// //owner.getEntity().getEvents().trigger(DEPLOY); -// mobState = STATE.DEPLOY; -// } else { -// //owner.getEntity().getEvents().trigger(IDLE); -// mobState = STATE.IDLE; -// } -// } + case STOW -> { + // currently stowing + if (isTargetVisible()) { + owner.getEntity().getEvents().trigger(DEPLOY); + mobState = STATE.DEPLOY; + } else { + owner.getEntity().getEvents().trigger(IDLE); + mobState = STATE.IDLE; + } + System.out.println("stowing for " + owner.getEntity().getId()); + + } } } @@ -151,8 +165,14 @@ public void updateMobState() { */ @Override public void stop() { - super.stop(); - owner.getEntity().getEvents().trigger(IDLE); + if (mobState == STATE.FIRING || mobState == STATE.DEPLOY) { + this.updateMobState(); + } else { +// owner.getEntity().getComponent(PhysicsMovementComponent.class).setEnabled(true); + System.out.println("mob attack stopped for " + owner.getEntity().getId()); + super.stop(); + owner.getEntity().getEvents().trigger(STOW); + } } /** @@ -174,7 +194,7 @@ public int getPriority() { * @return (int) active priority if a target is visible, -1 otherwise */ private int getActivePriority() { - if ((startTime + delay) < timeSource.getTime()) { + if ((startTime + delay) < timeSource.getTime() && isTargetVisible()) { // if (isTargetVisible() && (startTime + delay) > timeSource.getTime()) { // System.out.println("ready to fire while active"); return priority; @@ -190,7 +210,7 @@ private int getActivePriority() { */ private int getInactivePriority() { // return isTargetVisible() ? priority : 0; - if ((startTime + delay) < timeSource.getTime()) { + if ((startTime + delay) < timeSource.getTime() && isTargetVisible()) { // if (isTargetVisible() && (startTime + delay) > timeSource.getTime()) { // System.out.println("ready to fire while inactive"); return priority; @@ -205,6 +225,10 @@ private int getInactivePriority() { * @return true if a target is visible, false otherwise */ private boolean isTargetVisible() { - return physics.raycast(mobPosition, maxRangePosition, TARGET, hit); + Vector2 newVector = new Vector2(owner.getEntity().getPosition().x - 10f, owner.getEntity().getPosition().y - 2f); + return physics.raycast(owner.getEntity().getPosition(), newVector, TARGET, hit); } + +// private boolean meleeOrProjectile() { +// } }