From 6039562bd2c4ffbae75dc4ff6c9c1d2078915725 Mon Sep 17 00:00:00 2001 From: JSLLW Date: Wed, 11 Oct 2023 16:44:18 +1000 Subject: [PATCH] refactor: Code clean up in MobBossFactory. --- source/core/assets/configs/Boss.json | 4 +- .../csse3200/game/areas/ForestGameArea.java | 29 ---- .../npc/Boss1AnimationController.java | 49 ------- .../npc/Boss2AnimationController.java | 49 ------- .../game/entities/configs/MobBossConfigs.java | 2 - .../entities/factories/MobBossFactory.java | 137 +++++------------- 6 files changed, 36 insertions(+), 234 deletions(-) delete mode 100644 source/core/src/main/com/csse3200/game/components/npc/Boss1AnimationController.java delete mode 100644 source/core/src/main/com/csse3200/game/components/npc/Boss2AnimationController.java diff --git a/source/core/assets/configs/Boss.json b/source/core/assets/configs/Boss.json index 3567235fb..6c6118fb1 100644 --- a/source/core/assets/configs/Boss.json +++ b/source/core/assets/configs/Boss.json @@ -1,7 +1,5 @@ { "mobBoss": { - "health": 100, - "baseAttack": 25, - "spookyFactor": 7 + "baseAttack": 0 } } \ No newline at end of file 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 30e33b482..01354a345 100644 --- a/source/core/src/main/com/csse3200/game/areas/ForestGameArea.java +++ b/source/core/src/main/com/csse3200/game/areas/ForestGameArea.java @@ -2,25 +2,11 @@ import com.badlogic.gdx.math.GridPoint2; import com.badlogic.gdx.math.Vector2; -import com.csse3200.game.areas.terrain.TerrainFactory; -import com.csse3200.game.areas.terrain.TerrainFactory.TerrainType; import com.csse3200.game.entities.Entity; import com.csse3200.game.entities.factories.*; -import com.csse3200.game.physics.PhysicsLayer; import com.badlogic.gdx.audio.Music; -import com.badlogic.gdx.math.GridPoint2; -import com.badlogic.gdx.math.Vector2; -import com.csse3200.game.areas.terrain.TerrainComponent; -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.ProjectileEffects; -import com.csse3200.game.entities.Entity; -import com.csse3200.game.entities.factories.*; - -import com.csse3200.game.physics.PhysicsLayer; -import com.csse3200.game.screens.AssetLoader; import com.csse3200.game.utils.math.RandomUtils; import com.csse3200.game.services.ResourceService; @@ -29,14 +15,9 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.security.SecureRandom; -import java.util.Random; import java.util.Timer; -import static com.csse3200.game.entities.factories.NPCFactory.createGhost; import static com.csse3200.game.screens.AssetLoader.loadAllAssets; -import java.util.ArrayList; - -import java.util.TimerTask; /** Forest area for the demo game with trees, a player, and some enemies. */ public class ForestGameArea extends GameArea { @@ -46,10 +27,6 @@ public class ForestGameArea extends GameArea { private static final int NUM_GRUNTS = 5; private static final int NUM_BOSS = 4; - - private static final int NUM_MOBBOSS2=3; - private static final int NUM_MOBBOSS1=1; - private SecureRandom rand = new SecureRandom(); private int wave = 0; @@ -237,12 +214,6 @@ public class ForestGameArea extends GameArea { private Entity player; private Entity waves; - // Variables to be used with spawn projectile methods. This is the variable - // that should occupy the direction param. - private static final int towardsMobs = 100; - private Entity mobBoss2; - private Entity mobBoss1; - /** * Initialise this ForestGameArea to use the provided TerrainFactory. * diff --git a/source/core/src/main/com/csse3200/game/components/npc/Boss1AnimationController.java b/source/core/src/main/com/csse3200/game/components/npc/Boss1AnimationController.java deleted file mode 100644 index 85759befd..000000000 --- a/source/core/src/main/com/csse3200/game/components/npc/Boss1AnimationController.java +++ /dev/null @@ -1,49 +0,0 @@ -package com.csse3200.game.components.npc; - -import com.csse3200.game.components.Component; -import com.csse3200.game.rendering.AnimationRenderComponent; - -/** - * This class listens to events relevant to a ghost entity's state and plays the animation when one - * of the events is triggered. - */ -public class Boss1AnimationController extends Component { - AnimationRenderComponent animator; - - @Override - public void create() { - super.create(); - animator = this.entity.getComponent(AnimationRenderComponent.class); - entity.getEvents().addListener("walkStart", this::animateWalk); - entity.getEvents().addListener("deadStart", this::animateDead); - entity.getEvents().addListener("idleStart", this::animateIdle); - entity.getEvents().addListener("chargingStart", this::animateCharging); - entity.getEvents().addListener("attack1Start", this::animateAttack1); - entity.getEvents().addListener("attack2Start", this::animateAttack2); - entity.getEvents().addListener("hurtStart", this::animateHurt); - } - - void animateHurt() { - animator.startAnimation("Hurt"); - } - void animateAttack2() { - animator.startAnimation("A2"); - } - void animateAttack1() { - animator.startAnimation("A1"); - } - void animateCharging() { - animator.startAnimation("Charging"); - } - void animateIdle() { - animator.startAnimation("Idle"); - } - - void animateDead() { - animator.startAnimation("boss_death"); - } - - void animateWalk() { - animator.startAnimation("Walk"); - } -} diff --git a/source/core/src/main/com/csse3200/game/components/npc/Boss2AnimationController.java b/source/core/src/main/com/csse3200/game/components/npc/Boss2AnimationController.java deleted file mode 100644 index bee80ad23..000000000 --- a/source/core/src/main/com/csse3200/game/components/npc/Boss2AnimationController.java +++ /dev/null @@ -1,49 +0,0 @@ -package com.csse3200.game.components.npc; - -import com.csse3200.game.components.Component; -import com.csse3200.game.rendering.AnimationRenderComponent; - -/** - * This class listens to events relevant to a ghost entity's state and plays the animation when one - * of the events is triggered. - */ -public class Boss2AnimationController extends Component { - AnimationRenderComponent animator; - - @Override - public void create() { - super.create(); - animator = this.entity.getComponent(AnimationRenderComponent.class); - entity.getEvents().addListener("walkStart", this::animateWalk); - entity.getEvents().addListener("deadStart", this::animateDead); - entity.getEvents().addListener("idleStart", this::animateIdle); - entity.getEvents().addListener("chargingStart", this::animateCharging); - entity.getEvents().addListener("attack1Start", this::animateAttack1); - entity.getEvents().addListener("attack2Start", this::animateAttack2); - entity.getEvents().addListener("hurtStart", this::animateHurt); - } - - void animateHurt() { - animator.startAnimation("Hurt"); - } - void animateAttack2() { - animator.startAnimation("A2"); - } - void animateAttack1() { - animator.startAnimation("A1"); - } - void animateCharging() { - animator.startAnimation("Charging"); - } - void animateIdle() { - animator.startAnimation("Idle"); - } - - void animateDead() { - animator.startAnimation("boss_death"); - } - - void animateWalk() { - animator.startAnimation("Walk"); - } -} diff --git a/source/core/src/main/com/csse3200/game/entities/configs/MobBossConfigs.java b/source/core/src/main/com/csse3200/game/entities/configs/MobBossConfigs.java index c17389da6..54bd8201f 100644 --- a/source/core/src/main/com/csse3200/game/entities/configs/MobBossConfigs.java +++ b/source/core/src/main/com/csse3200/game/entities/configs/MobBossConfigs.java @@ -4,7 +4,5 @@ * Defines the properties stored in ghost king config files to be loaded by the NPC Factory. */ public class MobBossConfigs extends BaseEntityConfig { - public int spookyFactor = 0; - public int health = 1; public int baseAttack = 0; } diff --git a/source/core/src/main/com/csse3200/game/entities/factories/MobBossFactory.java b/source/core/src/main/com/csse3200/game/entities/factories/MobBossFactory.java index 319738449..1e16adaa4 100644 --- a/source/core/src/main/com/csse3200/game/entities/factories/MobBossFactory.java +++ b/source/core/src/main/com/csse3200/game/entities/factories/MobBossFactory.java @@ -7,15 +7,11 @@ import com.csse3200.game.components.bosses.DemonAnimationController; import com.csse3200.game.components.bosses.PatrickAnimationController; import com.csse3200.game.components.bosses.IceBabyAnimationController; -import com.csse3200.game.components.npc.Boss1AnimationController; -import com.csse3200.game.components.npc.Boss2AnimationController; import com.csse3200.game.components.tasks.bosstask.*; import com.csse3200.game.entities.Entity; -import com.csse3200.game.entities.configs.MobBossConfigs; import com.csse3200.game.entities.configs.NPCConfigs; import com.csse3200.game.files.FileLoader; import com.csse3200.game.physics.PhysicsLayer; -import com.csse3200.game.physics.PhysicsUtils; import com.csse3200.game.physics.components.*; import com.csse3200.game.rendering.AnimationRenderComponent; import com.csse3200.game.services.ServiceLocator; @@ -26,26 +22,18 @@ public class MobBossFactory { private static final NPCConfigs configs = FileLoader.readClass(NPCConfigs.class, "configs/Boss.json"); - private static final int PRIORITY = 1; - private static final int BOSS_MOB_AGRO_RANGE = 10; - private static final int DEMON_HEALTH = 5000; - private static final int DEMON_ATTACK = 0; - private static final int PATRICK_ATTACK = 0; - private static final int PATRICK_HEALTH = 2500; - private static final int ICEBABY_ATTACK = 0; - private static final int ICEBABY_HEALTH = 3000; + private static final int ATTACK = configs.mobBoss.baseAttack; /** - * Creates new Demon boss with its correlating tasks and animations - * - * @return Demon boss + * Creates new Demon Boss with tasks and animations. + * + * @param health value for the Demon Boss's health + * @return a Demon Boss Entity */ -// public static Entity createDemonBoss() { - // Create Demon Boss public static Entity createDemonBoss(int health) { Entity demon = createBaseBoss(); - // Animation addition + // Animation AnimationRenderComponent animator = new AnimationRenderComponent( ServiceLocator.getResourceService().getAsset("images/mobboss/demon.atlas", TextureAtlas.class)); @@ -59,19 +47,18 @@ public static Entity createDemonBoss(int health) { animator.addAnimation("demon_walk", 0.2f, Animation.PlayMode.LOOP); animator.addAnimation("transform", 0.2f, Animation.PlayMode.NORMAL); - // AI task addition + // Adds AI task AITaskComponent aiTaskComponent = new AITaskComponent() .addTask(new DemonBossTask()); - // Component addition + // Adds components demon .addComponent(animator) .addComponent(new DemonAnimationController()) .addComponent(aiTaskComponent) - .addComponent(new CombatStatsComponent(health, DEMON_ATTACK)); -// .addComponent(new CombatStatsComponent(DEMON_HEALTH, DEMON_ATTACK)); + .addComponent(new CombatStatsComponent(health, ATTACK)); - // Scale demon + // Scale Demon Boss demon.getComponent(AnimationRenderComponent.class).scaleEntity(); demon.scaleHeight(5f); demon.scaleWidth(5f); @@ -81,7 +68,8 @@ public static Entity createDemonBoss(int health) { /** * Creates end state of demon boss * - * @return Slimey Boy + * @param health value for Slimey Boy's health + * @return a Slimey Boy Entity */ public static Entity createSlimeyBoy(int health) { Entity slimeyBoy = createBaseBoss(); @@ -97,18 +85,18 @@ public static Entity createSlimeyBoy(int health) { animator.addAnimation("take_hit", 0.2f, Animation.PlayMode.LOOP); animator.addAnimation("transform", 0.2f, Animation.PlayMode.REVERSED); - // AI task addition + // Adds AI task AITaskComponent aiTaskComponent = new AITaskComponent() .addTask(new SlimeyBoyTask()); - // Component addition + // Adds components slimeyBoy .addComponent(animator) .addComponent(new DemonAnimationController()) .addComponent(aiTaskComponent) .addComponent(new CombatStatsComponent(health, 0)); - // Scale demon + // Scale Slimey Boy slimeyBoy.getComponent(AnimationRenderComponent.class).scaleEntity(); slimeyBoy.scaleHeight(5f); slimeyBoy.scaleWidth(5f); @@ -118,13 +106,13 @@ public static Entity createSlimeyBoy(int health) { /** * Creates new Patrick boss with correlating tasks and animations * - * @param health - health of the boss - * @return Patrick Boss + * @param health value for the Patrick Boss's health + * @return a Patrick Boss */ public static Entity createPatrickBoss(int health) { Entity patrick = createBaseBoss(); - // Animation addition + // Animation AnimationRenderComponent animator = new AnimationRenderComponent( ServiceLocator.getResourceService().getAsset("images/mobboss/patrick.atlas", TextureAtlas.class)); animator.addAnimation("patrick_attack", 0.2f, Animation.PlayMode.NORMAL); @@ -135,18 +123,18 @@ public static Entity createPatrickBoss(int health) { animator.addAnimation("patrick_spell", 0.2f, Animation.PlayMode.NORMAL); animator.addAnimation("patrick_walk", 0.2f, Animation.PlayMode.LOOP); - // AI task addition + // Adds AI task AITaskComponent aiTaskComponent = new AITaskComponent() .addTask(new PatrickTask()); - // Component addition + // Adds components patrick .addComponent(animator) .addComponent(new PatrickAnimationController()) .addComponent(aiTaskComponent) - .addComponent(new CombatStatsComponent(health, PATRICK_ATTACK)); + .addComponent(new CombatStatsComponent(health, ATTACK)); - // Scale demon + // Scale Patrick Boss patrick.getComponent(AnimationRenderComponent.class).scaleEntity(); patrick.scaleHeight(4f); patrick.scaleWidth(4f); @@ -154,29 +142,30 @@ public static Entity createPatrickBoss(int health) { } /** - * Creates a patrick entity whose sole purpose is to display death animation - * @return patrick death entity + * Creates a Patrick Boss Entity whose sole purpose is to display the Patrick death animation. + * + * @return a Patrick Death Entity */ public static Entity patrickDead() { Entity patrick = createBaseBoss(); - // Animation addition + // Animation AnimationRenderComponent animator = new AnimationRenderComponent( ServiceLocator.getResourceService().getAsset("images/mobboss/patrick.atlas", TextureAtlas.class)); animator.addAnimation("patrick_death", 0.2f, Animation.PlayMode.NORMAL); - // AI task addition + // Adds AI task AITaskComponent aiTaskComponent = new AITaskComponent() .addTask(new PatrickDeathTask()); - // Component addition + // Adds components patrick .addComponent(animator) .addComponent(new PatrickAnimationController()) .addComponent(aiTaskComponent) .addComponent(new CombatStatsComponent(1, 0)); - // Scale patrick + // Scale Patrick Boss patrick.getComponent(AnimationRenderComponent.class).scaleEntity(); patrick.scaleHeight(4f); patrick.scaleWidth(4f); @@ -186,7 +175,8 @@ public static Entity patrickDead() { /** * Creates a new ice boss and adds its correlating animations and tasks * - * @return - Ice Baby Boss + * @param health value for the Ice Boss's health + * @return an Ice Baby Boss Entity */ public static Entity createIceBoss(int health) { Entity iceBaby = createBaseBoss(); @@ -211,7 +201,7 @@ public static Entity createIceBoss(int health) { .addComponent(animator) .addComponent(new IceBabyAnimationController()) .addComponent(aiTaskComponent) - .addComponent(new CombatStatsComponent(health, ICEBABY_ATTACK)); + .addComponent(new CombatStatsComponent(health, ATTACK)); iceBaby.getComponent(AnimationRenderComponent.class).scaleEntity(); iceBaby.scaleHeight(4f); @@ -220,67 +210,10 @@ public static Entity createIceBoss(int health) { return iceBaby; } - // Create Boss King 1 - public static Entity createMobBoss1(int numLane) { - MobBossConfigs config = configs.mobBoss; - Entity mobBoss1 = createBaseBoss(); - - AITaskComponent aiTaskComponent1 = new AITaskComponent() - .addTask(new FinalBossMovementTask(1f, numLane)) - .addTask(new MobBossDeathTask(1));; - - // Animation section - AnimationRenderComponent animator1 = new AnimationRenderComponent( - ServiceLocator.getResourceService().getAsset("images/mobs/robot.atlas", TextureAtlas.class)); - animator1.addAnimation("Walk", 0.3f, Animation.PlayMode.LOOP_REVERSED); - - mobBoss1.addComponent(new CombatStatsComponent(config.health, config.baseAttack)) - .addComponent(animator1) - .addComponent(aiTaskComponent1) - .addComponent(new Boss1AnimationController()); - - mobBoss1.getComponent(AnimationRenderComponent.class).scaleEntity(); - mobBoss1.setScale(1f, 1f); - - return mobBoss1; - } - - // Create Boss King 2 - public static Entity createMobBoss2() { - MobBossConfigs config = configs.mobBoss; - Entity mobBoss2 = createBaseBoss(); - - AITaskComponent aiTaskComponent2 = new AITaskComponent() - .addTask(new RangeBossTask(2f)); - - // Animation section - AnimationRenderComponent animator2 = new AnimationRenderComponent( - ServiceLocator.getResourceService().getAsset("images/mobs/boss2.atlas", TextureAtlas.class)); - animator2.addAnimation("boss_death", 0.3f, Animation.PlayMode.LOOP); - animator2.addAnimation("Idle", 0.3f, Animation.PlayMode.LOOP); - animator2.addAnimation("Walk", 0.3f, Animation.PlayMode.LOOP); - animator2.addAnimation("Charging", 0.3f, Animation.PlayMode.LOOP_REVERSED); - animator2.addAnimation("A1", 0.3f, Animation.PlayMode.LOOP); - animator2.addAnimation("A2", 0.3f, Animation.PlayMode.LOOP); - animator2.addAnimation("Hurt", 0.3f, Animation.PlayMode.LOOP); - - mobBoss2.addComponent(new CombatStatsComponent(config.health, config.baseAttack)) - .addComponent(animator2) - .addComponent(aiTaskComponent2) - .addComponent(new Boss2AnimationController()) - .addComponent(new PhysicsComponent()); - - mobBoss2.getComponent(AnimationRenderComponent.class).scaleEntity(); - mobBoss2.scaleHeight(3f); - mobBoss2.scaleWidth(3f); - - return mobBoss2; - } - - /** - * Create base boss entity that all boss mobs will inherit - * @return base mob boss entity + * Creates a base boss entity with Components that all Mob Bosses will inherit. + * + * @return a base mob boss entity */ public static Entity createBaseBoss() { Entity boss = new Entity()