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 900bbeb30..db2890793 100644 --- a/source/core/src/main/com/csse3200/game/areas/ForestGameArea.java +++ b/source/core/src/main/com/csse3200/game/areas/ForestGameArea.java @@ -244,37 +244,6 @@ private void stopWaveTimer() { } } - /** - * Cases to spawn a wave - */ -// private void spawnWave() { -// wave++; -// switch (wave) { -// case 1: -// case 2: -// spawnFireWorm(); -// spawnDragonKnight(); -// -// break; -// case 3: -// spawnSkeleton(); -// spawnWizard(); -// // mobBoss2 = spawnMobBoss2(); -// break; -// case 4: -// spawnWaterQueen(); -// spawnWaterSlime(); -// // mobBoss2 = spawnMobBoss2(); -// -// break; -// case 5: -// spawnDemonBoss(); -// default: -// // Handle other wave scenarios if needed -// break; -// } -// } - /** * Create the game area, including terrain, static entities (trees), dynamic entities (player) */ diff --git a/source/core/src/main/com/csse3200/game/components/EffectComponent.java b/source/core/src/main/com/csse3200/game/components/EffectComponent.java index 4e13ba09a..6d3df3bdc 100644 --- a/source/core/src/main/com/csse3200/game/components/EffectComponent.java +++ b/source/core/src/main/com/csse3200/game/components/EffectComponent.java @@ -2,14 +2,8 @@ import com.badlogic.gdx.math.Vector2; import com.csse3200.game.ai.tasks.AITaskComponent; -import com.csse3200.game.components.CombatStatsComponent; -import com.csse3200.game.components.Component; -import com.csse3200.game.components.ProjectileEffects; -import com.csse3200.game.components.tasks.MovementTask; import com.csse3200.game.components.tower.TowerUpgraderComponent; import com.csse3200.game.entities.Entity; -import com.csse3200.game.physics.PhysicsLayer; -import com.csse3200.game.physics.components.HitboxComponent; import com.csse3200.game.physics.components.PhysicsMovementComponent; import com.csse3200.game.services.GameTime; import com.csse3200.game.services.ServiceLocator; diff --git a/source/core/src/main/com/csse3200/game/components/RicochetComponent.java b/source/core/src/main/com/csse3200/game/components/RicochetComponent.java index 4203dfa6a..37c8fce6b 100644 --- a/source/core/src/main/com/csse3200/game/components/RicochetComponent.java +++ b/source/core/src/main/com/csse3200/game/components/RicochetComponent.java @@ -16,8 +16,8 @@ public class RicochetComponent extends Component { private short targetLayer; private HitboxComponent hitBoxComponent; private int bounceCount; - private static int MAX_BOUNCE_Y_DIRECTION = 250; - private static int MIN_BOUNCE_Y_DIRECTION = -250; + private static final int MAX_BOUNCE_Y_DIRECTION = 250; + private static final int MIN_BOUNCE_Y_DIRECTION = -250; /** * Initialise a RicochetComponent that spawns another projectile upon collision. @@ -60,10 +60,10 @@ private void onCollisionEnd(Fixture me, Fixture other) { // Spawning of the projectile to be above (+ve) or below (-ve) upon // collision - int up_or_down = randomDirection <= 0 ? -1 : 1; + int upOrDown = randomDirection <= 0 ? -1 : 1; float newXPosition = (float) (projectile.getPosition().x - 0.75); - float newYPosition = (float) (projectile.getPosition().y + (0.65 * up_or_down)); + float newYPosition = (float) (projectile.getPosition().y + (0.65 * upOrDown)); // Prevent spawn of new projectile if it goes out of boundaries. if (newYPosition >= 8 || newYPosition <= 1 || newXPosition >= 17 || newXPosition <= 1) diff --git a/source/core/src/main/com/csse3200/game/components/SplitFireworksComponent.java b/source/core/src/main/com/csse3200/game/components/SplitFireworksComponent.java index 0a53d7d4b..09f5fcdc3 100644 --- a/source/core/src/main/com/csse3200/game/components/SplitFireworksComponent.java +++ b/source/core/src/main/com/csse3200/game/components/SplitFireworksComponent.java @@ -17,8 +17,8 @@ public class SplitFireworksComponent extends Component { private short targetLayer; private HitboxComponent hitboxComponent; private int amount; - private static int TOTAL_RANGE = 450; - private static double SPAWN_OFFSET_X = 1.75; + private static final int TOTAL_RANGE = 450; + private static final double SPAWN_OFFSET_X = 1.75; /** * Initialises a component that splits the projectile into multiple fireballs @@ -60,9 +60,9 @@ private void onCollisionEnd(Fixture me, Fixture other) { // * RIGHT NOW TARGET IS NPC, SUBJECT TO CHANGE // Speed is a bit faster than normal but can change. Entity newProjectile = ProjectileFactory.createFireworks(PhysicsLayer.NPC, - new Vector2(100, (float) (projectile.getPosition().y + (newDirection - (double) (TOTAL_RANGE/2)))), new Vector2(3f, 3f)); + new Vector2(100, (float) (projectile.getPosition().y + (newDirection - ((double) TOTAL_RANGE) / 2))), new Vector2(3f, 3f)); - newProjectile.setPosition(newXPosition, (float) projectile.getPosition().y); + newProjectile.setPosition(newXPosition, projectile.getPosition().y); newProjectile.setScale(0.5f, 0.5f); diff --git a/source/core/src/main/com/csse3200/game/components/TouchAttackComponent.java b/source/core/src/main/com/csse3200/game/components/TouchAttackComponent.java index 64678b2c0..2ff88df7e 100644 --- a/source/core/src/main/com/csse3200/game/components/TouchAttackComponent.java +++ b/source/core/src/main/com/csse3200/game/components/TouchAttackComponent.java @@ -29,7 +29,6 @@ public class TouchAttackComponent extends Component { private short targetLayer; private float knockbackForce = 0f; private boolean disposeOnHit = false; - private int aoeSize = 0; private CombatStatsComponent combatStats; private HitboxComponent hitboxComponent; diff --git a/source/core/src/main/com/csse3200/game/components/bosses/IceBabyAnimationController.java b/source/core/src/main/com/csse3200/game/components/bosses/IceBabyAnimationController.java index 96672a688..b12817cb9 100644 --- a/source/core/src/main/com/csse3200/game/components/bosses/IceBabyAnimationController.java +++ b/source/core/src/main/com/csse3200/game/components/bosses/IceBabyAnimationController.java @@ -38,7 +38,7 @@ public class IceBabyAnimationController extends Component { Sound mobSpawnSound = ServiceLocator.getResourceService().getAsset( MOB_SPAWN_SOUND, Sound.class); private static final String AOE_SOUND = "sounds/mobBoss/iceBabyAOE.mp3"; - Sound AOESound = ServiceLocator.getResourceService().getAsset( + Sound aoeSound = ServiceLocator.getResourceService().getAsset( AOE_SOUND, Sound.class); @Override @@ -70,8 +70,8 @@ void animateATK2() { } void animateATK3() { animator.startAnimation(ATK3_ANIM); - AOESound.setVolume(1000, 5.5f); - AOESound.play(); + aoeSound.setVolume(1000, 5.5f); + aoeSound.play(); } void animateDeath() { animator.startAnimation(DEATH_ANIM); diff --git a/source/core/src/main/com/csse3200/game/components/npc/ArcaneArcherAnimationController.java b/source/core/src/main/com/csse3200/game/components/npc/ArcaneArcherAnimationController.java index 1ea7d98be..71fa5359d 100644 --- a/source/core/src/main/com/csse3200/game/components/npc/ArcaneArcherAnimationController.java +++ b/source/core/src/main/com/csse3200/game/components/npc/ArcaneArcherAnimationController.java @@ -4,6 +4,7 @@ import com.csse3200.game.components.Component; import com.csse3200.game.rendering.AnimationRenderComponent; import com.csse3200.game.services.ServiceLocator; + import java.security.SecureRandom; /** diff --git a/source/core/src/main/com/csse3200/game/components/npc/CoatAnimationController.java b/source/core/src/main/com/csse3200/game/components/npc/CoatAnimationController.java index 3b04ec800..e9bf8170e 100644 --- a/source/core/src/main/com/csse3200/game/components/npc/CoatAnimationController.java +++ b/source/core/src/main/com/csse3200/game/components/npc/CoatAnimationController.java @@ -4,6 +4,7 @@ import com.csse3200.game.components.Component; import com.csse3200.game.rendering.AnimationRenderComponent; import com.csse3200.game.services.ServiceLocator; + import java.security.SecureRandom; /** diff --git a/source/core/src/main/com/csse3200/game/components/npc/DragonKnightAnimationController.java b/source/core/src/main/com/csse3200/game/components/npc/DragonKnightAnimationController.java index 8466e1e23..6d9d54215 100644 --- a/source/core/src/main/com/csse3200/game/components/npc/DragonKnightAnimationController.java +++ b/source/core/src/main/com/csse3200/game/components/npc/DragonKnightAnimationController.java @@ -1,9 +1,7 @@ package com.csse3200.game.components.npc; -import com.badlogic.gdx.audio.Sound; import com.csse3200.game.components.Component; import com.csse3200.game.rendering.AnimationRenderComponent; -import com.csse3200.game.services.ServiceLocator; import java.security.SecureRandom; /** diff --git a/source/core/src/main/com/csse3200/game/components/npc/NightBorneAnimationController.java b/source/core/src/main/com/csse3200/game/components/npc/NightBorneAnimationController.java index 53bad45c2..d821f6cca 100644 --- a/source/core/src/main/com/csse3200/game/components/npc/NightBorneAnimationController.java +++ b/source/core/src/main/com/csse3200/game/components/npc/NightBorneAnimationController.java @@ -1,9 +1,7 @@ package com.csse3200.game.components.npc; -import com.badlogic.gdx.audio.Sound; import com.csse3200.game.components.Component; import com.csse3200.game.rendering.AnimationRenderComponent; -import com.csse3200.game.services.ServiceLocator; import java.security.SecureRandom; /** diff --git a/source/core/src/main/com/csse3200/game/components/npc/SplitMoblings.java b/source/core/src/main/com/csse3200/game/components/npc/SplitMoblings.java index c6de1bb5d..5896c2f10 100644 --- a/source/core/src/main/com/csse3200/game/components/npc/SplitMoblings.java +++ b/source/core/src/main/com/csse3200/game/components/npc/SplitMoblings.java @@ -1,7 +1,7 @@ package com.csse3200.game.components.npc; import com.csse3200.game.components.Component; -import com.csse3200.game.components.tasks.MobTask.MobType; +import com.csse3200.game.components.tasks.mobtask.MobType; import com.csse3200.game.entities.Entity; import com.csse3200.game.entities.factories.NPCFactory; import com.csse3200.game.services.ServiceLocator; @@ -20,7 +20,8 @@ public class SplitMoblings extends Component { private int amount; private MobType mobType; private int baseMoblingHealth = 60; - private float scaleX, scaleY; + private float scaleX; + private float scaleY; public static final float DEFAULT_MINIFIED_SCALE = 0.75f; public static final double OFFSET_DISTANCE = 1.5; public static final int FULL_CIRCLE_ANGLE = 360; @@ -106,7 +107,7 @@ private void onDeath() { // Inspired by: // https://stackoverflow.com/questions/37145768/distribute-points-evenly-on-circle-circumference-in-quadrants-i-and-iv-only for (int i = 0; i < amount; i++) { - float currAngle = (float) (360 / amount) * i; + float currAngle = FULL_CIRCLE_ANGLE / (float) amount * i; double radians = currAngle * Math.PI / 180; float newX = entity.getPosition().x + (float) OFFSET_DISTANCE * @@ -186,7 +187,6 @@ private boolean withinBounds(float currX, float currY) { && currY <= MAX_Y_BOUNDS) { return true; } - ; return false; } } diff --git a/source/core/src/main/com/csse3200/game/components/npc/WaterSlimeAnimationController.java b/source/core/src/main/com/csse3200/game/components/npc/WaterSlimeAnimationController.java index 03adc1466..6909dad10 100644 --- a/source/core/src/main/com/csse3200/game/components/npc/WaterSlimeAnimationController.java +++ b/source/core/src/main/com/csse3200/game/components/npc/WaterSlimeAnimationController.java @@ -1,9 +1,7 @@ package com.csse3200.game.components.npc; -import com.badlogic.gdx.audio.Sound; import com.csse3200.game.components.Component; import com.csse3200.game.rendering.AnimationRenderComponent; -import com.csse3200.game.services.ServiceLocator; import java.security.SecureRandom; /** diff --git a/source/core/src/main/com/csse3200/game/components/npc/XenoAnimationController.java b/source/core/src/main/com/csse3200/game/components/npc/XenoAnimationController.java index 6c0d80159..d07dc4683 100644 --- a/source/core/src/main/com/csse3200/game/components/npc/XenoAnimationController.java +++ b/source/core/src/main/com/csse3200/game/components/npc/XenoAnimationController.java @@ -1,9 +1,7 @@ package com.csse3200.game.components.npc; -import com.badlogic.gdx.audio.Sound; import com.csse3200.game.components.Component; import com.csse3200.game.rendering.AnimationRenderComponent; -import com.csse3200.game.services.ServiceLocator; import java.security.SecureRandom; /** 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 141317b91..c5fc7f0bf 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 @@ -22,7 +22,7 @@ */ public class MobAttackTask extends DefaultTask implements PriorityTask { private static final int INTERVAL = 1; // time interval to scan for towers in - private static final short TARGET = PhysicsLayer.HUMANS; // mobs detecting for towers + private static final short TARGET_LAYER = PhysicsLayer.HUMANS; // mobs detecting for towers // ^ fix this private static final String STOW = "wanderStart"; @@ -33,15 +33,13 @@ public class MobAttackTask extends DefaultTask implements PriorityTask { private Fixture target; private final int priority; - private final float maxRange; - private Vector2 mobPosition = new Vector2(10f,10f); private final Vector2 maxRangePosition = new Vector2(); private final PhysicsEngine physics; private GameTime timeSource; private long endTime; private final RaycastHit hit = new RaycastHit(); - private final long delay = 1000; // delay between shots + private static final long DELAY = 1000; // delay between shots private long startTime; private enum STATE { @@ -54,9 +52,8 @@ private enum STATE { * @param priority Task priority when targets are detected (0 when nothing detected). Must be a positive integer. * @param maxRange Maximum effective range of the weapon mob. This determines the detection distance of targets */ - public MobAttackTask(int priority, float maxRange) { + public MobAttackTask(int priority) { this.priority = priority; - this.maxRange = maxRange; startTime = 0; physics = ServiceLocator.getPhysicsService().getPhysics(); @@ -70,7 +67,7 @@ public MobAttackTask(int priority, float maxRange) { public void start() { super.start(); startTime = timeSource.getTime(); - this.mobPosition = owner.getEntity().getCenterPosition(); + Vector2 mobPosition = owner.getEntity().getCenterPosition(); this.maxRangePosition.set(0, mobPosition.y); //owner.getEntity().getEvents().trigger(IDLE); endTime = timeSource.getTime() + (INTERVAL * 500); @@ -122,25 +119,22 @@ public void updateMobState() { if (!isTargetVisible() || this.meleeOrProjectile() == null) { this.owner.getEntity().getEvents().trigger(STOW); mobState = STATE.STOW; - } else { - if (this.meleeOrProjectile() instanceof Melee) { + } else if (this.meleeOrProjectile() instanceof Melee) { TouchAttackComponent attackComp = owner.getEntity().getComponent(TouchAttackComponent.class); HitboxComponent hitboxComp = owner.getEntity().getComponent(HitboxComponent.class); attackComp.onCollisionStart(hitboxComp.getFixture(), target); this.owner.getEntity().getEvents().trigger("meleeStart"); - } else { + } else { Entity newProjectile = ProjectileFactory.createMobBall(PhysicsLayer.HUMANS, new Vector2(0, owner.getEntity().getPosition().y), new Vector2(2f,2f)); - newProjectile.setPosition((float) (owner.getEntity().getPosition().x), (float) (owner.getEntity().getPosition().y)); + newProjectile.setPosition(owner.getEntity().getPosition().x, owner.getEntity().getPosition().y); newProjectile.setScale(-1f, 1f); ServiceLocator.getEntityService().register(newProjectile); // System.out.printf("ANIMATION: " + owner.getEntity().getComponent(AnimationRenderComponent.class).getCurrentAnimation() + "\n"); this.owner.getEntity().getEvents().trigger(FIRING); mobState = STATE.STOW; - } } owner.getEntity().getComponent(PhysicsMovementComponent.class).setEnabled(true); - } case STOW -> { @@ -175,41 +169,20 @@ public void stop() { */ @Override public int getPriority() { - if (status == Status.ACTIVE) { - return getActivePriority(); - } - return getInactivePriority(); - } - - /** - * Fetches the active priority of the Task if a target is visible. - * @return (int) active priority if a target is visible, -1 otherwise - */ - private int getActivePriority() { - if ((startTime + delay) < timeSource.getTime() && isTargetVisible() && this.meleeOrProjectile() != null) { - return priority; - } - return -1; - } - - /** - * 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() { - if ((startTime + delay) < timeSource.getTime() && isTargetVisible() && this.meleeOrProjectile() != null) { + if ((startTime + DELAY) < timeSource.getTime() && isTargetVisible() && this.meleeOrProjectile() != null) { return priority; } return -1; } /** - * Uses a raycast to determine whether there are any targets in detection range + * 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() { Vector2 newVector = new Vector2(owner.getEntity().getPosition().x - 10f, owner.getEntity().getPosition().y - 2f); - return physics.raycast(owner.getEntity().getPosition(), newVector, TARGET, hit); + return physics.raycast(owner.getEntity().getPosition(), newVector, TARGET_LAYER, hit); } /** @@ -237,6 +210,6 @@ private Weapon meleeOrProjectile() { private void setTarget() { Vector2 newVector = new Vector2(owner.getEntity().getPosition().x - 10f, owner.getEntity().getPosition().y - 2f); - target = physics.raycastGetHit(owner.getEntity().getPosition(), newVector, TARGET); + target = physics.raycastGetHit(owner.getEntity().getPosition(), newVector, TARGET_LAYER); } } diff --git a/source/core/src/main/com/csse3200/game/components/tasks/MobDeathTask.java b/source/core/src/main/com/csse3200/game/components/tasks/MobDeathTask.java index 615f0e1ff..478623bcf 100644 --- a/source/core/src/main/com/csse3200/game/components/tasks/MobDeathTask.java +++ b/source/core/src/main/com/csse3200/game/components/tasks/MobDeathTask.java @@ -24,7 +24,6 @@ public class MobDeathTask extends DefaultTask implements PriorityTask { private final PhysicsEngine physics; private GameTime timeSource; private long endTime; - private final RaycastHit hit = new RaycastHit(); private int mobHealth; @@ -70,11 +69,6 @@ public void updateBossState() { } - @Override - public void stop() { - super.stop(); - } - @Override public int getPriority() { if (status == Status.ACTIVE) { @@ -98,11 +92,7 @@ private int getInactivePriority() { return -1; } private boolean mobIsDead(int mobhealth) { - - if (mobhealth <= 0) { - return true; - } - return false; + return mobhealth <= 0; } private void killMob() { diff --git a/source/core/src/main/com/csse3200/game/components/tasks/MobDodgeTask.java b/source/core/src/main/com/csse3200/game/components/tasks/MobDodgeTask.java index 353e96a19..f50ca2ebd 100644 --- a/source/core/src/main/com/csse3200/game/components/tasks/MobDodgeTask.java +++ b/source/core/src/main/com/csse3200/game/components/tasks/MobDodgeTask.java @@ -1,8 +1,7 @@ package com.csse3200.game.components.tasks; -import com.badlogic.gdx.math.Vector2; -import com.csse3200.game.components.tasks.MobTask.MobTask; -import com.csse3200.game.components.tasks.MobTask.MobType; +import com.csse3200.game.components.tasks.mobtask.MobTask; +import com.csse3200.game.components.tasks.mobtask.MobType; import com.csse3200.game.services.GameTime; import com.csse3200.game.services.ServiceLocator; @@ -24,7 +23,7 @@ public class MobDodgeTask extends MobTask { private long endTime; // Helps task wait between each interval. - private final int DELAY_INTERVAL = 500; + private static final int DELAY_INTERVAL = 500; /** * Initialises a mob dodge task with a specified wander range, wait time, and diff --git a/source/core/src/main/com/csse3200/game/components/tasks/MobMeleeAttackTask.java b/source/core/src/main/com/csse3200/game/components/tasks/MobMeleeAttackTask.java index 3ac8c6c3c..b76de16a4 100644 --- a/source/core/src/main/com/csse3200/game/components/tasks/MobMeleeAttackTask.java +++ b/source/core/src/main/com/csse3200/game/components/tasks/MobMeleeAttackTask.java @@ -22,7 +22,7 @@ */ public class MobMeleeAttackTask extends DefaultTask implements PriorityTask { private static final int INTERVAL = 1; // time interval to scan for towers in - private static final short TARGET = PhysicsLayer.HUMANS; // mobs detecting for towers + private static final short TARGET_LAYER = PhysicsLayer.HUMANS; // mobs detecting for towers // ^ fix this private static final String STOW = "wanderStart"; @@ -33,15 +33,13 @@ public class MobMeleeAttackTask extends DefaultTask implements PriorityTask { private Fixture target; private final int priority; - private final float maxRange; - private Vector2 mobPosition = new Vector2(10f,10f); private final Vector2 maxRangePosition = new Vector2(); private final PhysicsEngine physics; private GameTime timeSource; private long endTime; private final RaycastHit hit = new RaycastHit(); - private final long delay = 1000; // delay between shots + private static final long DELAY = 1000; // delay between shots private long startTime; private enum STATE { @@ -54,9 +52,8 @@ private enum STATE { * @param priority Task priority when targets are detected (0 when nothing detected). Must be a positive integer. * @param maxRange Maximum effective range of the weapon mob. This determines the detection distance of targets */ - public MobMeleeAttackTask(int priority, float maxRange) { + public MobMeleeAttackTask(int priority) { this.priority = priority; - this.maxRange = maxRange; startTime = 0; physics = ServiceLocator.getPhysicsService().getPhysics(); @@ -70,11 +67,11 @@ public MobMeleeAttackTask(int priority, float maxRange) { public void start() { super.start(); startTime = timeSource.getTime(); - this.mobPosition = owner.getEntity().getCenterPosition(); + Vector2 mobPosition = owner.getEntity().getCenterPosition(); this.maxRangePosition.set(0, mobPosition.y); //owner.getEntity().getEvents().trigger(IDLE); endTime = timeSource.getTime() + (INTERVAL * 500); -// owner.getEntity().getEvents().trigger("shootStart"); +// owner.getEntity().getEvents().trigger(FIRING); } /** @@ -122,25 +119,22 @@ public void updateMobState() { if (!isTargetVisible() || this.meleeOrProjectile() == null) { this.owner.getEntity().getEvents().trigger(STOW); mobState = STATE.STOW; + } else if (this.meleeOrProjectile() instanceof Melee) { + TouchAttackComponent attackComp = owner.getEntity().getComponent(TouchAttackComponent.class); + HitboxComponent hitboxComp = owner.getEntity().getComponent(HitboxComponent.class); + attackComp.onCollisionStart(hitboxComp.getFixture(), target); + this.owner.getEntity().getEvents().trigger(FIRING); } else { - if (this.meleeOrProjectile() instanceof Melee) { - TouchAttackComponent attackComp = owner.getEntity().getComponent(TouchAttackComponent.class); - HitboxComponent hitboxComp = owner.getEntity().getComponent(HitboxComponent.class); - attackComp.onCollisionStart(hitboxComp.getFixture(), target); - this.owner.getEntity().getEvents().trigger("shootStart"); - } else { - Entity newProjectile = ProjectileFactory.createMobBall(PhysicsLayer.HUMANS, new Vector2(0, owner.getEntity().getPosition().y), new Vector2(2f,2f)); - newProjectile.setPosition((float) (owner.getEntity().getPosition().x), (float) (owner.getEntity().getPosition().y)); - newProjectile.setScale(-0.0f, 0.0f); - ServiceLocator.getEntityService().register(newProjectile); + Entity newProjectile = ProjectileFactory.createMobBall(PhysicsLayer.HUMANS, new Vector2(0, owner.getEntity().getPosition().y), new Vector2(2f,2f)); + newProjectile.setPosition(owner.getEntity().getPosition().x, owner.getEntity().getPosition().y); + newProjectile.setScale(-0.0f, 0.0f); + ServiceLocator.getEntityService().register(newProjectile); // System.out.printf("ANIMATION: " + owner.getEntity().getComponent(AnimationRenderComponent.class).getCurrentAnimation() + "\n"); - this.owner.getEntity().getEvents().trigger(FIRING); - mobState = STATE.STOW; - } + this.owner.getEntity().getEvents().trigger(FIRING); + mobState = STATE.STOW; } owner.getEntity().getComponent(PhysicsMovementComponent.class).setEnabled(true); - } case STOW -> { @@ -175,29 +169,7 @@ public void stop() { */ @Override public int getPriority() { - if (status == Status.ACTIVE) { - return getActivePriority(); - } - return getInactivePriority(); - } - - /** - * Fetches the active priority of the Task if a target is visible. - * @return (int) active priority if a target is visible, -1 otherwise - */ - private int getActivePriority() { - if ((startTime + delay) < timeSource.getTime() && isTargetVisible() && this.meleeOrProjectile() != null) { - return priority; - } - return -1; - } - - /** - * 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() { - if ((startTime + delay) < timeSource.getTime() && isTargetVisible() && this.meleeOrProjectile() != null) { + if ((startTime + DELAY) < timeSource.getTime() && isTargetVisible() && this.meleeOrProjectile() != null) { return priority; } return -1; @@ -209,7 +181,7 @@ private int getInactivePriority() { */ private boolean isTargetVisible() { Vector2 newVector = new Vector2(owner.getEntity().getPosition().x - 100f, owner.getEntity().getPosition().y - 2f); - return physics.raycast(owner.getEntity().getPosition(), newVector, TARGET, hit); + return physics.raycast(owner.getEntity().getPosition(), newVector, TARGET_LAYER, hit); } /** @@ -237,6 +209,6 @@ private Weapon meleeOrProjectile() { private void setTarget() { Vector2 newVector = new Vector2(owner.getEntity().getPosition().x - 100f, owner.getEntity().getPosition().y - 2f); - target = physics.raycastGetHit(owner.getEntity().getPosition(), newVector, TARGET); + target = physics.raycastGetHit(owner.getEntity().getPosition(), newVector, TARGET_LAYER); } } diff --git a/source/core/src/main/com/csse3200/game/components/tasks/MobRangedAttackTask.java b/source/core/src/main/com/csse3200/game/components/tasks/MobRangedAttackTask.java index b10dad91f..021419a05 100644 --- a/source/core/src/main/com/csse3200/game/components/tasks/MobRangedAttackTask.java +++ b/source/core/src/main/com/csse3200/game/components/tasks/MobRangedAttackTask.java @@ -22,7 +22,7 @@ */ public class MobRangedAttackTask extends DefaultTask implements PriorityTask { private static final int INTERVAL = 1; // time interval to scan for towers in - private static final short TARGET = PhysicsLayer.HUMANS; // mobs detecting for towers + private static final short TARGET_LAYER = PhysicsLayer.HUMANS; // mobs detecting for towers // ^ fix this private static final String STOW = "wanderStart"; @@ -33,15 +33,13 @@ public class MobRangedAttackTask extends DefaultTask implements PriorityTask { private Fixture target; private final int priority; - private final float maxRange; - private Vector2 mobPosition = new Vector2(10f,10f); private final Vector2 maxRangePosition = new Vector2(); private final PhysicsEngine physics; private GameTime timeSource; private long endTime; private final RaycastHit hit = new RaycastHit(); - private final long delay = 1000; // delay between shots + private static final long DELAY = 1000; // delay between shots private long startTime; private enum STATE { @@ -52,11 +50,9 @@ private enum STATE { /** * @param priority Task priority when targets are detected (0 when nothing detected). Must be a positive integer. - * @param maxRange Maximum effective range of the weapon mob. This determines the detection distance of targets */ - public MobRangedAttackTask(int priority, float maxRange) { + public MobRangedAttackTask(int priority) { this.priority = priority; - this.maxRange = maxRange; startTime = 0; physics = ServiceLocator.getPhysicsService().getPhysics(); @@ -70,7 +66,7 @@ public MobRangedAttackTask(int priority, float maxRange) { public void start() { super.start(); startTime = timeSource.getTime(); - this.mobPosition = owner.getEntity().getCenterPosition(); + Vector2 mobPosition = owner.getEntity().getCenterPosition(); this.maxRangePosition.set(0, mobPosition.y); //owner.getEntity().getEvents().trigger(IDLE); endTime = timeSource.getTime() + (INTERVAL * 500); @@ -122,31 +118,28 @@ public void updateMobState() { if (!isTargetVisible() || this.meleeOrProjectile() == null) { this.owner.getEntity().getEvents().trigger(STOW); mobState = STATE.STOW; - } else { - if (this.meleeOrProjectile() instanceof Melee) { - TouchAttackComponent attackComp = owner.getEntity().getComponent(TouchAttackComponent.class); - HitboxComponent hitboxComp = owner.getEntity().getComponent(HitboxComponent.class); - attackComp.onCollisionStart(hitboxComp.getFixture(), target); - Entity newProjectile = ProjectileFactory.createMobBall(PhysicsLayer.HUMANS, new Vector2(0, owner.getEntity().getPosition().y), new Vector2(2f,2f)); - newProjectile.setPosition((float) (owner.getEntity().getPosition().x), (float) (owner.getEntity().getPosition().y)); - newProjectile.setScale(-1f, 1f); - ServiceLocator.getEntityService().register(newProjectile); + } else if (this.meleeOrProjectile() instanceof Melee) { + TouchAttackComponent attackComp = owner.getEntity().getComponent(TouchAttackComponent.class); + HitboxComponent hitboxComp = owner.getEntity().getComponent(HitboxComponent.class); + attackComp.onCollisionStart(hitboxComp.getFixture(), target); + Entity newProjectile = ProjectileFactory.createMobBall(PhysicsLayer.HUMANS, new Vector2(0, owner.getEntity().getPosition().y), new Vector2(2f,2f)); + newProjectile.setPosition(owner.getEntity().getPosition().x, owner.getEntity().getPosition().y); + newProjectile.setScale(-1f, 1f); + ServiceLocator.getEntityService().register(newProjectile); // System.out.printf("ANIMATION: " + owner.getEntity().getComponent(AnimationRenderComponent.class).getCurrentAnimation() + "\n"); - this.owner.getEntity().getEvents().trigger(FIRING); - } else { - Entity newProjectile = ProjectileFactory.createMobBall(PhysicsLayer.HUMANS, new Vector2(0, owner.getEntity().getPosition().y), new Vector2(2f,2f)); - newProjectile.setPosition((float) (owner.getEntity().getPosition().x), (float) (owner.getEntity().getPosition().y)); - newProjectile.setScale(-1f, 1f); - ServiceLocator.getEntityService().register(newProjectile); + this.owner.getEntity().getEvents().trigger(FIRING); + } else { + Entity newProjectile = ProjectileFactory.createMobBall(PhysicsLayer.HUMANS, new Vector2(0, owner.getEntity().getPosition().y), new Vector2(2f,2f)); + newProjectile.setPosition(owner.getEntity().getPosition().x, owner.getEntity().getPosition().y); + newProjectile.setScale(-1f, 1f); + ServiceLocator.getEntityService().register(newProjectile); // System.out.printf("ANIMATION: " + owner.getEntity().getComponent(AnimationRenderComponent.class).getCurrentAnimation() + "\n"); - this.owner.getEntity().getEvents().trigger(FIRING); - mobState = STATE.STOW; - } + this.owner.getEntity().getEvents().trigger(FIRING); + mobState = STATE.STOW; } owner.getEntity().getComponent(PhysicsMovementComponent.class).setEnabled(true); - } case STOW -> { @@ -181,29 +174,7 @@ public void stop() { */ @Override public int getPriority() { - if (status == Status.ACTIVE) { - return getActivePriority(); - } - return getInactivePriority(); - } - - /** - * Fetches the active priority of the Task if a target is visible. - * @return (int) active priority if a target is visible, -1 otherwise - */ - private int getActivePriority() { - if ((startTime + delay) < timeSource.getTime() && isTargetVisible() && this.meleeOrProjectile() != null) { - return priority; - } - return -1; - } - - /** - * 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() { - if ((startTime + delay) < timeSource.getTime() && isTargetVisible() && this.meleeOrProjectile() != null) { + if ((startTime + DELAY) < timeSource.getTime() && isTargetVisible() && this.meleeOrProjectile() != null) { return priority; } return -1; @@ -215,7 +186,7 @@ private int getInactivePriority() { */ private boolean isTargetVisible() { Vector2 newVector = new Vector2(owner.getEntity().getPosition().x - 100f, owner.getEntity().getPosition().y - 2f); - return physics.raycast(owner.getEntity().getPosition(), newVector, TARGET, hit); + return physics.raycast(owner.getEntity().getPosition(), newVector, TARGET_LAYER, hit); } /** @@ -243,6 +214,6 @@ private Weapon meleeOrProjectile() { private void setTarget() { Vector2 newVector = new Vector2(owner.getEntity().getPosition().x - 100f, owner.getEntity().getPosition().y - 2f); - target = physics.raycastGetHit(owner.getEntity().getPosition(), newVector, TARGET); + target = physics.raycastGetHit(owner.getEntity().getPosition(), newVector, TARGET_LAYER); } } diff --git a/source/core/src/main/com/csse3200/game/components/tasks/MobShootTask.java b/source/core/src/main/com/csse3200/game/components/tasks/MobShootTask.java index 40c50142a..2453c4941 100644 --- a/source/core/src/main/com/csse3200/game/components/tasks/MobShootTask.java +++ b/source/core/src/main/com/csse3200/game/components/tasks/MobShootTask.java @@ -18,7 +18,7 @@ */ public class MobShootTask extends DefaultTask implements PriorityTask { private static final int INTERVAL = 1; // time interval to scan for towers in - private static final short TARGET = PhysicsLayer.HUMANS; // mobs detecting for towers + private static final short TARGET_LAYER = PhysicsLayer.HUMANS; // mobs detecting for towers // ^ fix this private static final String WALKING = "wanderStart"; @@ -29,15 +29,13 @@ public class MobShootTask extends DefaultTask implements PriorityTask { private Fixture target; private final int priority; - private final float maxRange; - private Vector2 mobPosition = new Vector2(10f,10f); private final Vector2 maxRangePosition = new Vector2(); private final PhysicsEngine physics; private GameTime timeSource; private long endTime; private final RaycastHit hit = new RaycastHit(); - private final long delay = 1000; // delay between shots + private static final long DELAY = 1000; // delay between shots private long startTime; private enum STATE { @@ -48,11 +46,9 @@ private enum STATE { /** * @param priority Task priority when targets are detected (0 when nothing detected). Must be a positive integer. - * @param maxRange Maximum effective range of the weapon mob. This determines the detection distance of targets */ - public MobShootTask(int priority, float maxRange) { + public MobShootTask(int priority) { this.priority = priority; - this.maxRange = maxRange; startTime = 0; physics = ServiceLocator.getPhysicsService().getPhysics(); @@ -66,7 +62,7 @@ public MobShootTask(int priority, float maxRange) { public void start() { super.start(); startTime = timeSource.getTime(); - this.mobPosition = owner.getEntity().getCenterPosition(); + Vector2 mobPosition = owner.getEntity().getCenterPosition(); this.maxRangePosition.set(0, mobPosition.y); //owner.getEntity().getEvents().trigger(IDLE); endTime = timeSource.getTime() + (INTERVAL * 500); @@ -103,7 +99,7 @@ public void updateMobState() { case DEPLOY -> { // currently deploying, - if (isTargetVisible() != false) { + if (isTargetVisible()) { owner.getEntity().getComponent(PhysicsMovementComponent.class).setEnabled(false); this.owner.getEntity().getEvents().trigger(FIRING); mobState = STATE.FIRING; @@ -115,13 +111,13 @@ public void updateMobState() { case FIRING -> { // targets gone or cannot be attacked - stop firing - if (!isTargetVisible() == false) { + if (isTargetVisible()) { this.owner.getEntity().getEvents().trigger(WALKING); mobState = STATE.WALKING; } else { Entity newProjectile = ProjectileFactory.createMobBall(PhysicsLayer.HUMANS, new Vector2(0, owner.getEntity().getPosition().y), new Vector2(2f,2f)); - newProjectile.setPosition((float) (owner.getEntity().getPosition().x), (float) (owner.getEntity().getPosition().y)); + newProjectile.setPosition(owner.getEntity().getPosition().x, owner.getEntity().getPosition().y); newProjectile.setScale(-1f, 1f); ServiceLocator.getEntityService().register(newProjectile); @@ -167,29 +163,7 @@ public void stop() { */ @Override public int getPriority() { - if (status == Status.ACTIVE) { - return getActivePriority(); - } - return getInactivePriority(); - } - - /** - * Fetches the active priority of the Task if a target is visible. - * @return (int) active priority if a target is visible, -1 otherwise - */ - private int getActivePriority() { - if ((startTime + delay) < timeSource.getTime() && isTargetVisible() != false) { - return priority; - } - return -1; - } - - /** - * 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() { - if ((startTime + delay) < timeSource.getTime() && isTargetVisible() != false) { + if ((startTime + DELAY) < timeSource.getTime() && isTargetVisible()) { return priority; } return -1; @@ -201,7 +175,7 @@ private int getInactivePriority() { */ private boolean isTargetVisible() { Vector2 newVector = new Vector2(owner.getEntity().getPosition().x - 10f, owner.getEntity().getPosition().y - 2f); - return physics.raycast(owner.getEntity().getPosition(), newVector, TARGET, hit); + return physics.raycast(owner.getEntity().getPosition(), newVector, TARGET_LAYER, hit); } /** @@ -229,6 +203,6 @@ private boolean isTargetVisible() { private void setTarget() { Vector2 newVector = new Vector2(owner.getEntity().getPosition().x - 10f, owner.getEntity().getPosition().y - 2f); - target = physics.raycastGetHit(owner.getEntity().getPosition(), newVector, TARGET); + target = physics.raycastGetHit(owner.getEntity().getPosition(), newVector, TARGET_LAYER); } } diff --git a/source/core/src/main/com/csse3200/game/components/tasks/MobTask/MobTask.java b/source/core/src/main/com/csse3200/game/components/tasks/MobTask/MobTask.java index 14ac9b4d2..21b38475d 100644 --- a/source/core/src/main/com/csse3200/game/components/tasks/MobTask/MobTask.java +++ b/source/core/src/main/com/csse3200/game/components/tasks/MobTask/MobTask.java @@ -1,4 +1,4 @@ -package com.csse3200.game.components.tasks.MobTask; +package com.csse3200.game.components.tasks.mobtask; import com.badlogic.gdx.math.Vector2; import com.badlogic.gdx.utils.Timer; @@ -35,7 +35,6 @@ public class MobTask extends DefaultTask implements PriorityTask { // Private variables private final MobType mobType; private State state = State.DEFAULT; - private State prevState; private Entity mob; private AnimationRenderComponent animation; private MovementTask movementTask; @@ -138,46 +137,30 @@ public void update() { animate(); runFlag = false; } - if (melee) { - if (enemyDetected()) { - if (gameTime.getTime() - lastTimeAttacked >= MELEE_ATTACK_SPEED) { - changeState(State.ATTACK); - meleeAttackFlag = true; - } - } - } else { - if (gameTime.getTime() - lastTimeAttacked >= RANGE_ATTACK_SPEED) { - changeState(State.ATTACK); - rangeAttackFlag = true; - } + if (melee && enemyDetected() && gameTime.getTime() - lastTimeAttacked >= MELEE_ATTACK_SPEED) { + changeState(State.ATTACK); + meleeAttackFlag = true; + } else if (gameTime.getTime() - lastTimeAttacked >= RANGE_ATTACK_SPEED) { + changeState(State.ATTACK); + rangeAttackFlag = true; } } case ATTACK -> { - if (melee) { - if (meleeAttackFlag) { - movementTask.stop(); - animate(); - meleeAttack(); - meleeAttackFlag = false; - } - if (animation.isFinished()) { - movementTask.start(); - changeState(State.RUN); - runFlag = true; - } + if (melee && meleeAttackFlag) { + movementTask.stop(); + animate(); + meleeAttack(); + meleeAttackFlag = false; + } else if (!melee && rangeAttackFlag) { + movementTask.stop(); + animate(); + rangeAttack(); + rangeAttackFlag = false; } - if (!melee) { - if (rangeAttackFlag) { - movementTask.stop(); - animate(); - rangeAttack(); - rangeAttackFlag = false; - } - if (animation.isFinished()) { - movementTask.start(); - changeState(State.RUN); - runFlag = true; - } + if (animation.isFinished()) { + movementTask.start(); + changeState(State.RUN); + runFlag = true; } } } @@ -260,11 +243,11 @@ private void animate() { } /** - * changes state of the mob + * Changes the state of the mob. + * * @param state state to change current state to */ private void changeState(State state) { - prevState = this.state; this.state = state; } @@ -274,19 +257,19 @@ private void changeState(State state) { */ private boolean enemyDetected() { // if there's an entity within x of - 1 of mob - Entity target = ServiceLocator.getEntityService().getEntityAtPosition( + Entity targetInFront = ServiceLocator.getEntityService().getEntityAtPosition( mob.getPosition().x - MELEE_ATTACK_RANGE, mob.getPosition().y); - if (target == null) { + if (targetInFront == null) { return false; } // layer checking - HitboxComponent targetHitbox = target.getComponent(HitboxComponent.class); + HitboxComponent targetHitbox = targetInFront.getComponent(HitboxComponent.class); if (targetHitbox == null) { return false; } if (PhysicsLayer.contains(PhysicsLayer.HUMANS, targetHitbox.getLayer())) { - this.target = target; + this.target = targetInFront; return true; } return false; diff --git a/source/core/src/main/com/csse3200/game/components/tasks/MobTask/MobType.java b/source/core/src/main/com/csse3200/game/components/tasks/MobTask/MobType.java index 335b2a7e7..8bf4e3b7e 100644 --- a/source/core/src/main/com/csse3200/game/components/tasks/MobTask/MobType.java +++ b/source/core/src/main/com/csse3200/game/components/tasks/MobTask/MobType.java @@ -1,4 +1,4 @@ -package com.csse3200.game.components.tasks.MobTask; +package com.csse3200.game.components.tasks.mobtask; public enum MobType { SKELETON(true), diff --git a/source/core/src/main/com/csse3200/game/components/tasks/MobWanderTask.java b/source/core/src/main/com/csse3200/game/components/tasks/MobWanderTask.java index 99d37afdc..e652ea84e 100644 --- a/source/core/src/main/com/csse3200/game/components/tasks/MobWanderTask.java +++ b/source/core/src/main/com/csse3200/game/components/tasks/MobWanderTask.java @@ -19,22 +19,17 @@ public class MobWanderTask extends DefaultTask implements PriorityTask { private static final Logger logger = LoggerFactory.getLogger(MobWanderTask.class); - private final Vector2 wanderRange; private final float waitTime; private Vector2 startPos; private MovementTask movementTask; private WaitTask waitTask; private Task currentTask; private boolean isDead = false; - private Vector2 mobPosition; /** - * @param wanderRange Distance in X and Y the entity can move from its position when start() is - * called. * @param waitTime How long in seconds to wait between wandering. */ - public MobWanderTask(Vector2 wanderRange, float waitTime) { - this.wanderRange = wanderRange; + public MobWanderTask(float waitTime) { this.waitTime = waitTime; } @@ -66,12 +61,12 @@ public void start() { public void update() { // Update the position of the mob - mobPosition = owner.getEntity().getPosition(); + Vector2 mobPosition = owner.getEntity().getPosition(); // If the mob is at zero health, kill the mob, // play the death animation and stop the task // This method is the idea of Ahmad who very kindly helped with section, massive props to him for his help! - if (!isDead && owner.getEntity().getComponent(CombatStatsComponent.class).isDead()) { + if (!isDead && Boolean.TRUE.equals(owner.getEntity().getComponent(CombatStatsComponent.class).isDead())) { this.owner.getEntity().getEvents().trigger("dieStart"); currentTask.stop(); isDead = true; @@ -82,7 +77,7 @@ public void update() { else if (isDead && owner.getEntity().getComponent(AnimationRenderComponent.class).isFinished()) { // Drop scrap at the mobs location Entity scrap = DropFactory.createScrapDrop(); - scrap.setPosition(mobPosition.x,mobPosition.y); + scrap.setPosition(mobPosition.x, mobPosition.y); ServiceLocator.getEntityService().register(scrap); // Delete the mob and update count for number of mobs remaining in the wave diff --git a/source/core/src/main/com/csse3200/game/components/tasks/MoveToMiddleTask.java b/source/core/src/main/com/csse3200/game/components/tasks/MoveToMiddleTask.java index d9c62e604..2ec1a5ba8 100644 --- a/source/core/src/main/com/csse3200/game/components/tasks/MoveToMiddleTask.java +++ b/source/core/src/main/com/csse3200/game/components/tasks/MoveToMiddleTask.java @@ -10,12 +10,7 @@ public class MoveToMiddleTask extends DefaultTask implements PriorityTask { private final float speed; private boolean hasReachedTarget = false; - private Status taskStatus; - - private Entity ownerEntity; // Store the owner entity - - public MoveToMiddleTask(Entity ownerEntity, Vector2 targetPosition, float speed) { - this.ownerEntity = ownerEntity; + public MoveToMiddleTask(Vector2 targetPosition, float speed) { this.targetPosition = targetPosition; this.speed = speed; } @@ -60,7 +55,7 @@ public void update() { } private void setStatus() { - Status taskStatus = Status.COMPLETED; + status = Status.COMPLETED; } } diff --git a/source/core/src/main/com/csse3200/game/components/tasks/PierceTowerCombatTask.java b/source/core/src/main/com/csse3200/game/components/tasks/PierceTowerCombatTask.java index b6c6f7619..cdefde434 100644 --- a/source/core/src/main/com/csse3200/game/components/tasks/PierceTowerCombatTask.java +++ b/source/core/src/main/com/csse3200/game/components/tasks/PierceTowerCombatTask.java @@ -4,7 +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; diff --git a/source/core/src/main/com/csse3200/game/components/tasks/RicochetTowerCombatTask.java b/source/core/src/main/com/csse3200/game/components/tasks/RicochetTowerCombatTask.java index 63c662417..7fc3e5728 100644 --- a/source/core/src/main/com/csse3200/game/components/tasks/RicochetTowerCombatTask.java +++ b/source/core/src/main/com/csse3200/game/components/tasks/RicochetTowerCombatTask.java @@ -4,7 +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; diff --git a/source/core/src/main/com/csse3200/game/components/tasks/TrajectTask.java b/source/core/src/main/com/csse3200/game/components/tasks/TrajectTask.java index 9dbc8cf5c..14cd12923 100644 --- a/source/core/src/main/com/csse3200/game/components/tasks/TrajectTask.java +++ b/source/core/src/main/com/csse3200/game/components/tasks/TrajectTask.java @@ -3,11 +3,10 @@ import com.badlogic.gdx.math.Vector2; import com.csse3200.game.ai.tasks.DefaultTask; import com.csse3200.game.ai.tasks.PriorityTask; -import com.csse3200.game.services.GameTime; /** Trajects a projectile from an entity towards the enemy entities */ public class TrajectTask extends DefaultTask implements PriorityTask { - private final int priority = 10; + private static final int PRIORITY = 10; private MovementTask movementTask; private Vector2 destination; private static final String START = "startProjectile"; @@ -18,8 +17,6 @@ private enum STATE { } private STATE projectileState = STATE.START; - private GameTime projectSpawn; - /** * @param destination The destination that the projectile will move towards. */ @@ -43,11 +40,13 @@ public void start() { this.owner.getEntity().getEvents().trigger("startMobBoss"); } + /** + * Switches the state to FINAL if it is START. + */ public void switchProjectileState() { - switch (projectileState) { - case START: - this.owner.getEntity().getEvents().trigger(FINAL); - projectileState = STATE.FINAL; + if (projectileState == STATE.START) { + this.owner.getEntity().getEvents().trigger(FINAL); + projectileState = STATE.FINAL; } } @@ -70,6 +69,6 @@ public void stop() { @Override public int getPriority() { - return priority; + return PRIORITY; } } diff --git a/source/core/src/main/com/csse3200/game/components/tasks/bosstask/DemonBossTask.java b/source/core/src/main/com/csse3200/game/components/tasks/bosstask/DemonBossTask.java index 45d482fbc..8930efde0 100644 --- a/source/core/src/main/com/csse3200/game/components/tasks/bosstask/DemonBossTask.java +++ b/source/core/src/main/com/csse3200/game/components/tasks/bosstask/DemonBossTask.java @@ -14,7 +14,6 @@ import com.csse3200.game.entities.factories.ProjectileFactory; import com.csse3200.game.physics.PhysicsEngine; import com.csse3200.game.physics.PhysicsLayer; -import com.csse3200.game.physics.components.HitboxComponent; import com.csse3200.game.physics.components.PhysicsMovementComponent; import com.csse3200.game.rendering.AnimationRenderComponent; import com.csse3200.game.services.GameTime; @@ -38,7 +37,7 @@ public class DemonBossTask extends DefaultTask implements PriorityTask { private static final double Y_BOT_BOUNDARY = 0.5; private static final int BREATH_ANIM_TIME = 2; private static final int SMASH_RADIUS = 3; - private static final int MOVE_FORWARD_DELAY = 15; + private static final float MOVE_FORWARD_DELAY = 15; private static final float BREATH_DURATION = 4.2f; private static final int SMASH_DAMAGE = 30; private static final int CLEAVE_DAMAGE = 50; diff --git a/source/core/src/main/com/csse3200/game/components/tasks/bosstask/IceBabyTask.java b/source/core/src/main/com/csse3200/game/components/tasks/bosstask/IceBabyTask.java index f89f12ed0..143a8888c 100644 --- a/source/core/src/main/com/csse3200/game/components/tasks/bosstask/IceBabyTask.java +++ b/source/core/src/main/com/csse3200/game/components/tasks/bosstask/IceBabyTask.java @@ -24,7 +24,7 @@ public class IceBabyTask extends DefaultTask implements PriorityTask { /** Constant names */ private static final int PRIORITY = 3; private static final Vector2 ICEBABY_SPEED = new Vector2(1f, 1f); - private static final int MOVE_FORWARD_DELAY = 30; + private static final float MOVE_FORWARD_DELAY = 30; private static final int SMASH_RADIUS = 3; private static final int SMASH_DAMAGE = 30; private static final int ATK3_DAMAGE = 50; diff --git a/source/core/src/main/com/csse3200/game/entities/EntityService.java b/source/core/src/main/com/csse3200/game/entities/EntityService.java index a5e6c4d6f..d9f0c2806 100644 --- a/source/core/src/main/com/csse3200/game/entities/EntityService.java +++ b/source/core/src/main/com/csse3200/game/entities/EntityService.java @@ -1,19 +1,10 @@ package com.csse3200.game.entities; -import com.badlogic.gdx.maps.tiled.TiledMap; import com.badlogic.gdx.maps.tiled.TiledMapTileLayer; -import com.badlogic.gdx.math.GridPoint2; import com.badlogic.gdx.math.Vector2; import com.badlogic.gdx.utils.Array; -import com.badlogic.gdx.math.Vector3; -import com.badlogic.gdx.utils.Array; -import com.csse3200.game.areas.terrain.TerrainComponent; -import com.csse3200.game.areas.terrain.TerrainFactory; -import com.csse3200.game.components.npc.DropComponent; -import com.csse3200.game.input.DropInputComponent; import com.csse3200.game.physics.PhysicsLayer; import com.csse3200.game.physics.components.HitboxComponent; -import com.csse3200.game.rendering.RenderService; import com.csse3200.game.services.ServiceLocator; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/source/core/src/main/com/csse3200/game/entities/PredefinedWeapons.java b/source/core/src/main/com/csse3200/game/entities/PredefinedWeapons.java index 8e20a6781..d0a2afd2c 100644 --- a/source/core/src/main/com/csse3200/game/entities/PredefinedWeapons.java +++ b/source/core/src/main/com/csse3200/game/entities/PredefinedWeapons.java @@ -1,7 +1,6 @@ package com.csse3200.game.entities; import com.csse3200.game.entities.configs.ProjectileConfig; -import com.csse3200.game.files.FileLoader; public class PredefinedWeapons { // Melee attacks diff --git a/source/core/src/main/com/csse3200/game/entities/factories/NPCFactory.java b/source/core/src/main/com/csse3200/game/entities/factories/NPCFactory.java index 90c7b0b1c..97ea42dc1 100644 --- a/source/core/src/main/com/csse3200/game/entities/factories/NPCFactory.java +++ b/source/core/src/main/com/csse3200/game/entities/factories/NPCFactory.java @@ -11,9 +11,9 @@ import com.csse3200.game.components.tasks.MobDodgeTask; import com.csse3200.game.components.tasks.MobMeleeAttackTask; import com.csse3200.game.components.tasks.MobRangedAttackTask; -import com.csse3200.game.components.tasks.MobTask.MobTask; -import com.csse3200.game.components.tasks.MobTask.MobType; import com.csse3200.game.components.tasks.MobWanderTask; +import com.csse3200.game.components.tasks.mobtask.MobTask; +import com.csse3200.game.components.tasks.mobtask.MobType; import com.csse3200.game.entities.Entity; import com.csse3200.game.entities.Melee; import com.csse3200.game.entities.PredefinedWeapons; @@ -533,8 +533,8 @@ public static Entity createBaseNPC() { public static Entity createMeleeBaseNPC() { AITaskComponent aiComponent = new AITaskComponent() - .addTask(new MobWanderTask(new Vector2(2f, 2f), 2f)) - .addTask(new MobMeleeAttackTask(2, 2f)); + .addTask(new MobWanderTask(2f)) + .addTask(new MobMeleeAttackTask(2)); // .addTask(new MobAttackTask(2, 2f)); // .addTask(new MeleeMobTask(new Vector2(2f, 2f), 2f)); @@ -558,9 +558,9 @@ public static Entity createMeleeBaseNPC() { public static Entity createRangedBaseNPC() { AITaskComponent aiComponent = new AITaskComponent() - .addTask(new MobWanderTask(new Vector2(2f, 2f), 2f)) + .addTask(new MobWanderTask(2f)) // .addTask(new MobAttackTask(2, 2f)); - .addTask(new MobRangedAttackTask(2, 2f)); + .addTask(new MobRangedAttackTask(2)); // .addTask(new MeleeMobTask(new Vector2(2f, 2f), 2f)); // .addTask(new MobAttackTask(2, 40)); diff --git a/source/core/src/test/com/csse3200/game/components/DodgingComponentTest.java b/source/core/src/test/com/csse3200/game/components/DodgingComponentTest.java index a0ac7c9fc..58bf0c9f1 100644 --- a/source/core/src/test/com/csse3200/game/components/DodgingComponentTest.java +++ b/source/core/src/test/com/csse3200/game/components/DodgingComponentTest.java @@ -14,8 +14,8 @@ import com.csse3200.game.components.npc.DodgingComponent; import com.csse3200.game.components.tasks.MobDodgeTask; import com.csse3200.game.components.tasks.MobWanderTask; -import com.csse3200.game.components.tasks.MobTask.MobTask; -import com.csse3200.game.components.tasks.MobTask.MobType; +import com.csse3200.game.components.tasks.mobtask.MobTask; +import com.csse3200.game.components.tasks.mobtask.MobType; import com.csse3200.game.entities.Entity; import com.csse3200.game.entities.EntityService; import com.csse3200.game.entities.factories.NPCFactory; diff --git a/source/core/src/test/com/csse3200/game/components/SplitMoblingsTest.java b/source/core/src/test/com/csse3200/game/components/SplitMoblingsTest.java index bee0f57c4..9b854eee1 100644 --- a/source/core/src/test/com/csse3200/game/components/SplitMoblingsTest.java +++ b/source/core/src/test/com/csse3200/game/components/SplitMoblingsTest.java @@ -19,7 +19,7 @@ import com.badlogic.gdx.math.Vector2; import com.csse3200.game.components.npc.SplitMoblings; -import com.csse3200.game.components.tasks.MobTask.MobType; +import com.csse3200.game.components.tasks.mobtask.MobType; import com.csse3200.game.entities.Entity; import com.csse3200.game.entities.EntityService; import com.csse3200.game.entities.factories.NPCFactory; diff --git a/source/core/src/test/com/csse3200/game/entities/factories/MobBossFactoryTest.java b/source/core/src/test/com/csse3200/game/entities/factories/MobBossFactoryTest.java index 6d2cdb538..23413699d 100644 --- a/source/core/src/test/com/csse3200/game/entities/factories/MobBossFactoryTest.java +++ b/source/core/src/test/com/csse3200/game/entities/factories/MobBossFactoryTest.java @@ -12,7 +12,6 @@ import com.csse3200.game.entities.Entity; import com.csse3200.game.extensions.GameExtension; import com.csse3200.game.physics.PhysicsService; -import com.csse3200.game.physics.components.ColliderComponent; import com.csse3200.game.physics.components.HitboxComponent; import com.csse3200.game.physics.components.PhysicsComponent; import com.csse3200.game.physics.components.PhysicsMovementComponent;