Skip to content

Commit

Permalink
Added javadocs to IceBabyTask and MobBossFactory
Browse files Browse the repository at this point in the history
  • Loading branch information
cindyle1 committed Sep 29, 2023
1 parent ee7786c commit 4851a1e
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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";
Expand All @@ -64,6 +67,9 @@ private enum STATE {
}
private STATE iceBabyState = STATE.IDLE;

/**
* Constructor for IceBabyTask
*/
public IceBabyTask() {
physics = ServiceLocator.getPhysicsService().getPhysics();
gameTime = ServiceLocator.getTimeSource();
Expand All @@ -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();
Expand Down Expand Up @@ -102,6 +111,9 @@ public void run() {

}

/**
* Updates the boss to start attacking and spawning new mobs
*/
@Override
public void update() {
if (!startFlag) {
Expand Down Expand Up @@ -131,7 +143,7 @@ public void update() {
}
case ATK1, ATK2 -> {
if (animation.isFinished()) {
changeState(STATE.ATK3);
ATK3();
}
}
case ATK3 -> {
Expand All @@ -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)) {
Expand All @@ -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();
Expand All @@ -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
Expand Down Expand Up @@ -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();
Expand All @@ -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();
Expand All @@ -238,13 +270,21 @@ public void run() {
}, 2f);
}

/**
* Creates a new mob triggered with the correct animation
*/
private void spawnMob() {
changeState(STATE.ATK2);
Entity newMob = NPCFactory.createSplittingWaterSlime();
newMob.setPosition((float) (iceBaby.getPosition().x + 0.5), (float) (iceBaby.getPosition().y + 0.5));
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<Entity> targets, int damage) {
for (int i = 0; i < targets.size; i++) {
Entity targetEntity = targets.get(i);
Expand All @@ -257,6 +297,11 @@ private void applyAoeDamage(Array<Entity> targets, int damage) {
}
}

/**
* Returns a list of nearby entities with PhysicsLayer.HUMAN.
*
* @return nearby entities with the PhysicsLayer of HUMAN
*/
private Array<Entity> getNearbyHumans(int radius) {
Array<Entity> nearbyEntities = ServiceLocator.getEntityService().
getNearbyEntities(iceBaby, radius);
Expand All @@ -281,7 +326,11 @@ private Array<Entity> getNearbyHumans(int radius) {
return nearbyHumans;
}


/**
* Returns the priority of this task.
*
* @return priority of task
*/
@Override
public int getPriority() {
return PRIORITY;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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())
Expand Down

0 comments on commit 4851a1e

Please sign in to comment.