Skip to content

Commit

Permalink
Merge branch 'Team-1-Mobs-Enhancement-variations' of https://github.c…
Browse files Browse the repository at this point in the history
…om/UQcsse3200/2023-studio-3 into Team-1-Mobs-Enhancement-variations
  • Loading branch information
MiniSoda17 committed Oct 15, 2023
2 parents f4b9a7c + 264c5d6 commit 7b0d4c5
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ public void create() {
// spawnRicochetTower();
// spawnBombship();
}

private void displayUI() {
Entity ui = new Entity();
ui.addComponent(new GameAreaDisplay("Box Forest"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class SplitMoblings extends Component {
public static final float MIN_X_BOUNDS = 1;
public static final float MAX_X_BOUNDS = (float) 18.5;
public static final float MIN_Y_BOUNDS = 0;
public static final float MAX_Y_BOUNDS = 6;
public static final float MAX_Y_BOUNDS = 5;
public static final String DIE_START_EVENT = "splitDeath";

/**
Expand Down Expand Up @@ -154,6 +154,8 @@ public void spawnAdditionalMob(float positionX, float positionY,
entityType.setScale(initialScaleX * scaleX, initialScaleY * scaleY);

ServiceLocator.getEntityService().register(entityType);

// ServiceLocator.getWaveService().setEnemyCount(ServiceLocator.getWaveService().getEnemyCount() + 1);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public class MobTask extends DefaultTask implements PriorityTask {
private Entity target;
private GameTime gameTime;
private long lastTimeAttacked;
private long dodgeEndTime;

// Flags
boolean melee;
Expand All @@ -51,6 +52,7 @@ public class MobTask extends DefaultTask implements PriorityTask {
boolean rangeAttackFlag = false;
boolean meleeAttackFlag = false;
boolean deathFlag = false;
boolean canDodge = false;

// Enums
private enum State {
Expand All @@ -66,6 +68,17 @@ public MobTask(MobType mobType) {
gameTime = ServiceLocator.getTimeSource();
}

/**
* constructor for the mob
* @param mobType type of mob it is
* @param canDodge ability to dodge projectiles
*/
public MobTask(MobType mobType, boolean canDodge) {
this.mobType = mobType;
gameTime = ServiceLocator.getTimeSource();
this.canDodge = true;
}

/**
* starts general mob sequence, starts its movement task and initialises
* some of its variables
Expand All @@ -84,6 +97,7 @@ public void start() {
runFlag = true;
changeState(State.RUN);
lastTimeAttacked = gameTime.getTime();
dodgeEndTime = gameTime.getTime();

if (melee) {
mob.getComponent(PhysicsMovementComponent.class).setSpeed(MELEE_MOB_SPEED);
Expand All @@ -108,6 +122,14 @@ public void update() {
mob.setFlagForDelete(true);
}

if(gameTime.getTime() >= dodgeEndTime) {
if (canDodge) {
mob.getEvents().trigger("dodgeIncomingEntity",
mob.getCenterPosition());
}
dodgeEndTime = gameTime.getTime() + 500; // 500ms
}

switch (state) {
case RUN -> {
if (runFlag) {
Expand Down Expand Up @@ -313,4 +335,13 @@ private void rangeAttack() {
public int getPriority() {
return PRIORITY;
}

/**
* Sets dodge flag of the mob
*
* @param dodgeFlag If true, mob dodges projectile.
*/
public void setDodge(boolean dodgeFlag) {
this.canDodge = dodgeFlag;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -646,8 +646,9 @@ public static Entity createDodgingDragonKnight(int health) {

dodgeKnight.addComponent(new DodgingComponent(PhysicsLayer.PROJECTILE, 0.25f));
// dodgeKnight.getComponent(AITaskComponent.class).addTask(new MobDodgeTask(new Vector2(2f, 2f), 2f, 5));
dodgeKnight.getComponent(AITaskComponent.class).
addTask(new MobDodgeTask(MobType.DRAGON_KNIGHT, 5));
// dodgeKnight.getComponent(AITaskComponent.class).
// addTask(new MobDodgeTask(MobType.DRAGON_KNIGHT, 5));
dodgeKnight.getComponent(AITaskComponent.class).getTask(MobTask.class).setDodge(true);
PhysicsUtils.setScaledCollider(dodgeKnight, 0.3f, 0.7f);
dodgeKnight.setScale(0.3f, 0.7f);

Expand All @@ -664,8 +665,9 @@ public static Entity createDodgingArcaneArcher(int health) {

dodgeKnight.addComponent(new DodgingComponent(PhysicsLayer.PROJECTILE, 0.25f));
// dodgeKnight.getComponent(AITaskComponent.class).addTask(new MobDodgeTask(new Vector2(2f, 2f), 2f, 5));
dodgeKnight.getComponent(AITaskComponent.class).
addTask(new MobDodgeTask(MobType.DRAGON_KNIGHT, 5));
// dodgeKnight.getComponent(AITaskComponent.class).
// addTask(new MobDodgeTask(MobType.DRAGON_KNIGHT, 5));
dodgeKnight.getComponent(AITaskComponent.class).getTask(MobTask.class).setDodge(true);
PhysicsUtils.setScaledCollider(dodgeKnight, 0.3f, 0.7f);
dodgeKnight.setScale(0.3f, 0.7f);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ public void setUp() {
DEFAULT_RANGE_DETECTION,
1.75f);
// task = new MobDodgeTask(new Vector2(2f, 2f), 2f, 5);
task = new MobDodgeTask(MobType.DRAGON_KNIGHT, 5);
// task = new MobDodgeTask(MobType.DRAGON_KNIGHT, 5);
task = new MobTask(MobType.DRAGON_KNIGHT, true);
}

@Test
Expand Down

0 comments on commit 7b0d4c5

Please sign in to comment.