From 4851a1e63e620ebf42e91575f3125bcbaed39164 Mon Sep 17 00:00:00 2001 From: cindyle1 Date: Fri, 29 Sep 2023 10:19:16 +1000 Subject: [PATCH] Added javadocs to IceBabyTask and MobBossFactory --- .../tasks/bosstask/IceBabyTask.java | 57 +++++++++++++++++-- .../entities/factories/MobBossFactory.java | 28 ++++++++- 2 files changed, 79 insertions(+), 6 deletions(-) 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 fc8cb7619..5591a4b48 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 @@ -26,6 +26,7 @@ import java.text.DecimalFormat; 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; @@ -37,6 +38,7 @@ public class IceBabyTask extends DefaultTask implements PriorityTask { private static final int Y_TOP_BOUNDARY = 6; private static final int Y_BOT_BOUNDARY = 1; private static final Logger logger = LoggerFactory.getLogger(IceBabyTask.class); + /** Variable names */ private PhysicsEngine physics; private GameTime gameTime; private STATE prevState; @@ -50,6 +52,7 @@ public class IceBabyTask extends DefaultTask implements PriorityTask { private boolean aoe = true; private boolean startFlag = false; private boolean isWalking; + /** Animation constants */ private static final String IDLE = "startIdle"; private static final String ATK1 = "start1_atk"; private static final String ATK2 = "start2_atk"; @@ -64,6 +67,9 @@ private enum STATE { } private STATE iceBabyState = STATE.IDLE; + /** + * Constructor for IceBabyTask + */ public IceBabyTask() { physics = ServiceLocator.getPhysicsService().getPhysics(); gameTime = ServiceLocator.getTimeSource(); @@ -73,6 +79,9 @@ public IceBabyTask() { //ice baby can also do aoe attack based on the animation //ice baby does punches to towers once it is close + /** + * Starts the Task and triggers for Ice Baby to be spawned + */ @Override public void start() { super.start(); @@ -102,6 +111,9 @@ public void run() { } + /** + * Updates the boss to start attacking and spawning new mobs + */ @Override public void update() { if (!startFlag) { @@ -131,7 +143,7 @@ public void update() { } case ATK1, ATK2 -> { if (animation.isFinished()) { - changeState(STATE.ATK3); + ATK3(); } } case ATK3 -> { @@ -142,11 +154,18 @@ public void update() { } } + /** + * Changes the state of animation + * @param state - the new animation + */ private void changeState(STATE state) { prevState = this.iceBabyState; this.iceBabyState = state; } + /** + * Trigger the specific animation to play + */ private void animate() { // Check if same animation is being called if (prevState.equals(iceBabyState)) { @@ -168,6 +187,11 @@ private void animate() { prevState = iceBabyState; } + /** + * Changes state of Ice Baby and moves it to the desired position. + * + * @param finalPos position for demon to jump to + */ private void walk(Vector2 finalPos) { changeState(STATE.WALK); animate(); @@ -181,9 +205,9 @@ private void walk(Vector2 finalPos) { } /** - * Returns a random position 3 units away for the demon to jump to. + * Returns a random position 3 units away for the ice Baby to walk to. * - * @return a position 3 units away from the demon to jump to + * @return a position 3 units away */ private Vector2 getWalkPos() { // check if boundary has shifted causing demon to be out of bounds @@ -211,6 +235,11 @@ private Vector2 getWalkPos() { return walkPos; } + /** + * Returns a boolean to confirm whether the ice baby has completed a walk or not. + * + * @return true if demon has completed walk or not + */ private boolean walkComplete() { changeState(STATE.ATK1); animate(); @@ -223,6 +252,9 @@ private boolean walkComplete() { return false; } + /** + * Changes the state of the animation and deals damage to nearby humans + */ private void ATK3() { changeState(STATE.ATK3); animate(); @@ -238,6 +270,9 @@ public void run() { }, 2f); } + /** + * Creates a new mob triggered with the correct animation + */ private void spawnMob() { changeState(STATE.ATK2); Entity newMob = NPCFactory.createSplittingWaterSlime(); @@ -245,6 +280,11 @@ private void spawnMob() { ServiceLocator.getEntityService().register(newMob); } + /** + * Applies aoe damage to nearby human entities. + * + * @param targets array of human entities to deal damage to + */ private void applyAoeDamage(Array targets, int damage) { for (int i = 0; i < targets.size; i++) { Entity targetEntity = targets.get(i); @@ -257,6 +297,11 @@ private void applyAoeDamage(Array targets, int damage) { } } + /** + * Returns a list of nearby entities with PhysicsLayer.HUMAN. + * + * @return nearby entities with the PhysicsLayer of HUMAN + */ private Array getNearbyHumans(int radius) { Array nearbyEntities = ServiceLocator.getEntityService(). getNearbyEntities(iceBaby, radius); @@ -281,7 +326,11 @@ private Array getNearbyHumans(int radius) { return nearbyHumans; } - + /** + * Returns the priority of this task. + * + * @return priority of task + */ @Override public int getPriority() { return PRIORITY; 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 37d9d41b9..8e18bf126 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 @@ -31,7 +31,11 @@ public class MobBossFactory { private static final int ICEBABY_ATTACK = 0; private static final int ICEBABY_HEALTH = 3000; - // Create Demon Boss + /** + * Creates new Demon boss with its correlating tasks and animations + * + * @return Demon boss + */ public static Entity createDemonBoss() { Entity demon = createBaseBoss(); @@ -67,6 +71,11 @@ public static Entity createDemonBoss() { return demon; } + /** + * Creates end state of demon boss + * + * @return Slimey Boy + */ public static Entity createSlimeyBoy() { Entity slimeyBoy = createBaseBoss(); @@ -99,6 +108,12 @@ public static Entity createSlimeyBoy() { return slimeyBoy; } + /** + * Creates new Patrick boss with correlating tasks and animations + * + * @param health - health of the boss + * @return Patrick Boss + */ public static Entity createPatrickBoss(int health) { Entity demon = createBaseBoss(); @@ -131,6 +146,11 @@ public static Entity createPatrickBoss(int health) { return demon; } + /** + * Creates a new ice boss and adds its correlating animations and tasks + * + * @return - Ice Baby Boss + */ public static Entity createIceBoss() { Entity iceBaby = createBaseBoss(); AITaskComponent aiTaskComponent = new AITaskComponent() @@ -220,7 +240,11 @@ public static Entity createMobBoss2() { return mobBoss2; } - // Create the base boss entity + /** + * Creates the base boss with the reqired components + * + * @return - boss + */ public static Entity createBaseBoss() { Entity boss = new Entity() .addComponent(new PhysicsComponent())