Skip to content

Commit

Permalink
Add melee attack for Final Boss
Browse files Browse the repository at this point in the history
  • Loading branch information
lenhatminh451 committed Sep 11, 2023
1 parent 052fecd commit fb9309d
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,18 @@ public class FinalBossMovementTask extends DefaultTask implements PriorityTask {
private MovementTask swapLaneTask;
private WaitTask waitTask;
private Task currentTask;
private PhysicsEngine physics;
private static final short TARGET = PhysicsLayer.TOWER;
private final RaycastHit hit = new RaycastHit();

/**
* @param waitTime How long in seconds to wait between moving.
*/
public FinalBossMovementTask(float waitTime, int numLane) {
this.waitTime = waitTime;
this.currLane = numLane;

physics = ServiceLocator.getPhysicsService().getPhysics();
}

@Override
Expand Down Expand Up @@ -68,6 +73,14 @@ public void start() {
public void update() {
if (currentTask.getStatus() != Status.ACTIVE) {
if (currentTask == movementTask) {
// Melee attack
if (towerAhead()) {
Entity newProjectile = ProjectileFactory.createEffectProjectile(PhysicsLayer.TOWER, new Vector2(0,currentPos.y + 0.75f), new Vector2(2f,2f), ProjectileEffects.BURN, false);
newProjectile.scaleHeight(-0.4f);
newProjectile.setPosition((float) (currentPos.x), (float) (currentPos.y+0.75f));
ServiceLocator.getEntityService().register(newProjectile);
}

startWaiting();
} else if (currentTask == waitTask) {
// startSwappingLane();
Expand Down Expand Up @@ -133,4 +146,8 @@ private void swapTask(Task newTask) {
currentTask = newTask;
currentTask.start();
}

private boolean towerAhead() {
return physics.raycast(currentPos, new Vector2(currentPos.x - 1, currentPos.y), TARGET, hit);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public static Entity createBossKing1(Entity target, int numLane) {
BossKingConfigs config = configs.BossKing;
Entity bossKing1 = createBaseBoss(target);

AITaskComponent aiTaskComponent1 = new AITaskComponent().addTask(new RangeBossTask(1f));
AITaskComponent aiTaskComponent1 = new AITaskComponent().addTask(new FinalBossMovementTask(1f, numLane));

// Animation section
AnimationRenderComponent animator1 = new AnimationRenderComponent(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.csse3200.game.entities.Entity;
import com.csse3200.game.events.listeners.EventListener0;
import com.csse3200.game.extensions.GameExtension;
import com.csse3200.game.physics.PhysicsService;
import com.csse3200.game.physics.components.PhysicsMovementComponent;
import com.csse3200.game.services.GameTime;
import com.csse3200.game.services.ServiceLocator;
Expand All @@ -25,6 +26,7 @@ class FinalBossMovementTaskTest {
@BeforeEach
void beforeEach() {
ServiceLocator.registerTimeSource(gameTime);
ServiceLocator.registerPhysicsService(new PhysicsService());
}

@Test
Expand Down

0 comments on commit fb9309d

Please sign in to comment.