Skip to content

Commit

Permalink
implemented slime spawn after shooting fireballs
Browse files Browse the repository at this point in the history
  • Loading branch information
gregchan550 committed Oct 6, 2023
1 parent f3a208c commit eef36b9
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 15 deletions.
16 changes: 9 additions & 7 deletions source/core/src/main/com/csse3200/game/areas/ForestGameArea.java
Original file line number Diff line number Diff line change
Expand Up @@ -324,9 +324,11 @@ public void create() {
// spawnEntity(waves);
// waves.getEvents().addListener("spawnWave", this::spawnMob);
// spawnGregMob();
spawnDodgingDragonKnight(17,4);
spawnDeflectWizard(17, 3);
spawnSplittingXenoGrunt(17, 2);
// spawnDodgingDragonKnight(17,4);
// spawnDeflectWizard(17, 3);
// spawnSplittingXenoGrunt(17, 2);
// spawnPatrick();
spawnDemonBoss();

spawnScrap();
spawnGapScanners();
Expand Down Expand Up @@ -398,10 +400,10 @@ private Entity spawnPlayer(GridPoint2 position) {
}

// commented 383 - 386 out as there was a missing arg?
// private void spawnDemonBoss() {
// Entity demon = MobBossFactory.createDemonBoss();
// spawnEntityAt(demon, new GridPoint2(19, 5), true, false);
// }
private void spawnDemonBoss() {
Entity demon = MobBossFactory.createDemonBoss(5000);
spawnEntityAt(demon, new GridPoint2(19, 5), true, false);
}

private void spawnPatrick() {
Entity patrick = MobBossFactory.createPatrickBoss(3000);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ public class DemonBossTask extends DefaultTask implements PriorityTask {
private static final Vector2 DEMON_SPEED = new Vector2(1f, 1f);
private static final float STOP_DISTANCE = 0.1f;
private static final float JUMP_DISTANCE = 3.0f;
private static final int Y_TOP_BOUNDARY = 6;
private static final int Y_BOT_BOUNDARY = 1;
private static final double Y_TOP_BOUNDARY = 5.5;
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;
Expand All @@ -44,6 +44,9 @@ public class DemonBossTask extends DefaultTask implements PriorityTask {
private static final int CLEAVE_DAMAGE = 50;
private static final int HEAL_TIMES = 10;
private static final int HEALTH_TO_ADD = 10;
private static final int SLIMEY_BOY_HEALTH = 500;
private static final int SLIMES_SPAWNED = 1;
private static final int SPAWN_RADIUS = 2;

// Private variables
private static final Logger logger = LoggerFactory.getLogger(DemonBossTask.class);
Expand All @@ -67,6 +70,7 @@ public class DemonBossTask extends DefaultTask implements PriorityTask {
private boolean isJumping;
private boolean halfHealthFlag = false;
private boolean isHealing = false;
private boolean isSpawning = false;

/**
* The different demon states.
Expand Down Expand Up @@ -144,7 +148,7 @@ public void update() {
// detect death stage
if (health <= 0) {
// spawn slimey boy
Entity slimey = MobBossFactory.createSlimeyBoy();
Entity slimey = MobBossFactory.createSlimeyBoy(SLIMEY_BOY_HEALTH);
slimey.setPosition(demon.getPosition().x, demon.getPosition().y);
slimey.setScale(5f, 5f);
ServiceLocator.getEntityService().register(slimey);
Expand Down Expand Up @@ -172,11 +176,13 @@ public void update() {
}
case BREATH, CLEAVE -> {
if (animation.isFinished()) {
changeState(DemonState.IDLE);
changeState(DemonState.CAST);
isSpawning = true;
spawnDemonSlimes();
}
}
case CAST -> {
if (!isHealing) {
if (!isHealing && !isSpawning) {
changeState(DemonState.IDLE);
}
}
Expand Down Expand Up @@ -460,5 +466,30 @@ public void run() {
}, (float) i /2);
}
}

private void spawnDemonSlimes() {
for (int i = 0; i < SLIMES_SPAWNED; i++) {
int finalI = i;
Timer.schedule(new Timer.Task() {
@Override
public void run() {
Entity slime = MobBossFactory.createSlimeyBoy(100);
float angle = MathUtils.random(0f, MathUtils.PI2);
float distance = MathUtils.random(0f, SPAWN_RADIUS);

float x = demon.getPosition().x + distance * MathUtils.cos(angle);
float y = demon.getPosition().y + distance * MathUtils.sin(angle);

Vector2 spawnLocation = new Vector2(x, y);
slime.setPosition(spawnLocation);
ServiceLocator.getEntityService().register(slime);

if (finalI == SLIMES_SPAWNED - 1) {
isSpawning = false;
}
}
}, (float) i /2);
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public static Entity createDemonBoss(int health) {
*
* @return Slimey Boy
*/
public static Entity createSlimeyBoy() {
public static Entity createSlimeyBoy(int health) {
Entity slimeyBoy = createBaseBoss();

// Animation
Expand All @@ -106,7 +106,7 @@ public static Entity createSlimeyBoy() {
.addComponent(animator)
.addComponent(new DemonAnimationController())
.addComponent(aiTaskComponent)
.addComponent(new CombatStatsComponent(80, 0));
.addComponent(new CombatStatsComponent(health, 0));

// Scale demon
slimeyBoy.getComponent(AnimationRenderComponent.class).scaleEntity();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public void setUp() {
.getAsset("images/mobboss/demon.atlas", TextureAtlas.class);
baseBoss = MobBossFactory.createBaseBoss();
demon = MobBossFactory.createDemonBoss(80);
slimeyBoy = MobBossFactory.createSlimeyBoy();
slimeyBoy = MobBossFactory.createSlimeyBoy(80);
patrick = MobBossFactory.createPatrickBoss(80);
deadPatrick = MobBossFactory.patrickDead();
iceBaby = MobBossFactory.createIceBoss(80);
Expand Down

0 comments on commit eef36b9

Please sign in to comment.