From eef36b945367be62b8f27ae0130e8567d38d6fb6 Mon Sep 17 00:00:00 2001 From: gregchan550 Date: Fri, 6 Oct 2023 13:13:32 +1000 Subject: [PATCH] implemented slime spawn after shooting fireballs --- .../csse3200/game/areas/ForestGameArea.java | 16 ++++---- .../tasks/bosstask/DemonBossTask.java | 41 ++++++++++++++++--- .../entities/factories/MobBossFactory.java | 4 +- .../factories/MobBossFactoryTest.java | 2 +- 4 files changed, 48 insertions(+), 15 deletions(-) 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 7660bf94b..5656b08ee 100644 --- a/source/core/src/main/com/csse3200/game/areas/ForestGameArea.java +++ b/source/core/src/main/com/csse3200/game/areas/ForestGameArea.java @@ -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(); @@ -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); diff --git a/source/core/src/main/com/csse3200/game/components/tasks/bosstask/DemonBossTask.java b/source/core/src/main/com/csse3200/game/components/tasks/bosstask/DemonBossTask.java index 6349e51ab..025f8989f 100644 --- a/source/core/src/main/com/csse3200/game/components/tasks/bosstask/DemonBossTask.java +++ b/source/core/src/main/com/csse3200/game/components/tasks/bosstask/DemonBossTask.java @@ -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; @@ -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); @@ -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. @@ -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); @@ -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); } } @@ -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); + } + } } 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 876b810f7..c046b0fc6 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 @@ -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 @@ -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(); diff --git a/source/core/src/test/com/csse3200/game/entities/factories/MobBossFactoryTest.java b/source/core/src/test/com/csse3200/game/entities/factories/MobBossFactoryTest.java index ad0ff7b62..1c961242c 100644 --- a/source/core/src/test/com/csse3200/game/entities/factories/MobBossFactoryTest.java +++ b/source/core/src/test/com/csse3200/game/entities/factories/MobBossFactoryTest.java @@ -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);