Skip to content

Commit

Permalink
Implement swap lane for Final Boss
Browse files Browse the repository at this point in the history
  • Loading branch information
lenhatminh451 committed Sep 11, 2023
1 parent 029ee22 commit 052fecd
Show file tree
Hide file tree
Showing 4 changed files with 108 additions and 65 deletions.
54 changes: 27 additions & 27 deletions source/core/src/main/com/csse3200/game/areas/ForestGameArea.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public class ForestGameArea extends GameArea {

// Required to load assets before using them
private static final String[] forestTextures = {
"images/ingamebg.png",
"images/ingamebg.png",
"images/projectiles/projectile.png",
"images/box_boy_leaf.png",
"images/background/building1.png",
Expand Down Expand Up @@ -128,7 +128,7 @@ public class ForestGameArea extends GameArea {
private final TerrainFactory terrainFactory;

private Entity player;

// Variables to be used with spawn projectile methods. This is the variable
// that should occupy the direction param.
private static final int towardsMobs = 100;
Expand Down Expand Up @@ -270,7 +270,7 @@ private Entity spawnBossKing1() {
.distinct().limit(5).toArray();
for (int i = 0; i < NUM_BOSSKING1; i++) {
GridPoint2 randomPos = new GridPoint2(19, pickedLanes[i]);
bossKing1 = BossKingFactory.createBossKing1(player);
bossKing1 = BossKingFactory.createBossKing1(player, pickedLanes[i]);
spawnEntityAt(bossKing1,
randomPos,
true,
Expand All @@ -279,28 +279,28 @@ private Entity spawnBossKing1() {
return bossKing1;
}

/**
* Spawns a projectile that only heads towards the enemies in its lane.
*
* @param position The position of the Entity that's shooting the projectile.
* @param targetLayer The enemy layer of the "shooter".
* @param direction The direction the projectile should head towards.
* @param speed The speed of the projectiles.
*
/**
* Spawns a projectile that only heads towards the enemies in its lane.
*
* @param position The position of the Entity that's shooting the projectile.
* @param targetLayer The enemy layer of the "shooter".
* @param direction The direction the projectile should head towards.
* @param speed The speed of the projectiles.
*
*/
private void spawnProjectile(Vector2 position, short targetLayer, int direction, Vector2 speed) {
Entity Projectile = ProjectileFactory.createFireBall(targetLayer, new Vector2(direction, position.y), speed);
Projectile.setPosition(position);
spawnEntity(Projectile);
}
/**
/**
* Spawns a projectile specifically for general mobs/xenohunters
*
*
* @param position The position of the Entity that's shooting the projectile.
* @param targetLayer The enemy layer of the "shooter".
* @param direction The direction the projectile should head towards.
* @param speed The speed of the projectiles.
*
*
*/
private void spawnMobBall(Vector2 position, short targetLayer, int direction, Vector2 speed) {
Entity Projectile = ProjectileFactory.createMobBall(targetLayer, new Vector2(direction, position.y), speed);
Expand All @@ -309,14 +309,14 @@ private void spawnMobBall(Vector2 position, short targetLayer, int direction, Ve
}

/**
* Spawns a projectile to be used for multiple projectile function.
*
* @param position The position of the Entity that's shooting the projectile.
* @param targetLayer The enemy layer of the "shooter".
* @param space The space between the projectiles' destination.
* @param direction The direction the projectile should head towards.
* @param speed The speed of the projectiles.
*
* Spawns a projectile to be used for multiple projectile function.
*
* @param position The position of the Entity that's shooting the projectile.
* @param targetLayer The enemy layer of the "shooter".
* @param space The space between the projectiles' destination.
* @param direction The direction the projectile should head towards.
* @param speed The speed of the projectiles.
*
*/
private void spawnProjectile(Vector2 position, short targetLayer, int space, int direction, Vector2 speed) {
Entity Projectile = ProjectileFactory.createFireBall(targetLayer, new Vector2(direction, position.y + space), speed);
Expand Down Expand Up @@ -382,7 +382,7 @@ private Entity spawnBossKing2() {
/**
* Creates multiple projectiles that travel simultaneous. They all have same
* the starting point but different destinations.
*
*
* @param position The position of the Entity that's shooting the projectile.
* @param targetLayer The enemy layer of the "shooter".
* @param direction The direction the projectile should head towards.
Expand All @@ -393,14 +393,14 @@ private Entity spawnBossKing2() {
private void spawnMultiProjectile(Vector2 position, short targetLayer, int direction, int space, Vector2 speed, int quantity) {
int half = quantity / 2;
for (int i = 0; i < quantity; i++) {
spawnProjectile(position, targetLayer, space * half, direction, speed);
--half;
spawnProjectile(position, targetLayer, space * half, direction, speed);
--half;
}
}

/**
* Returns projectile that can do an area of effect damage
*
*
* @param position The position of the Entity that's shooting the projectile.
* @param targetLayer The enemy layer of the "shooter".
* @param direction The direction the projectile should head towards.
Expand Down Expand Up @@ -505,7 +505,7 @@ private void spawnIncome() {
spawnEntityAt(towerfactory, randomPos, true, true);
}
}

private void spawnEngineer() {

for (int i = 0; i < terrain.getMapBounds(0).x; i += 3) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,38 @@
import com.csse3200.game.ai.tasks.DefaultTask;
import com.csse3200.game.ai.tasks.PriorityTask;
import com.csse3200.game.ai.tasks.Task;
import com.csse3200.game.components.ProjectileEffects;
import com.csse3200.game.entities.Entity;
import com.csse3200.game.entities.factories.ProjectileFactory;
import com.csse3200.game.physics.PhysicsEngine;
import com.csse3200.game.physics.raycast.RaycastHit;
import com.csse3200.game.services.ServiceLocator;
import com.csse3200.game.physics.PhysicsLayer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import static com.csse3200.game.screens.MainGameScreen.viewportHeight;

/**
* Going forward with certain speed, and switching to another land
* Requires an entity with a PhysicsMovementComponent.
* Wander around by moving a random position within a range of the starting position. Wait a little
* bit between movements. Requires an entity with a PhysicsMovementComponent.
*/
public class FinalBossMovementTask extends DefaultTask implements PriorityTask {
private static final Logger logger = LoggerFactory.getLogger(FinalBossMovementTask.class);

private final float switchTime;
private Vector2 startPos;
// private WaitTask waitTask;
private MovementTask moveForwardTask;
private MovementTask switchLaneTask;
private final float waitTime;
private int currLane;
private Vector2 currentPos;
private MovementTask movementTask;
private MovementTask swapLaneTask;
private WaitTask waitTask;
private Task currentTask;

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

@Override
Expand All @@ -36,51 +46,84 @@ public int getPriority() {
@Override
public void start() {
super.start();
startPos = owner.getEntity().getPosition();
currentPos = owner.getEntity().getPosition();

// waitTask = new WaitTask(switchTime);
// waitTask.create(owner);
waitTask = new WaitTask(waitTime);
waitTask.create(owner);

switchLaneTask = new MovementTask(startPos.sub(0, 2));
switchLaneTask.create(owner);
swapLaneTask = new MovementTask(currentPos);
swapLaneTask.create(owner);

moveForwardTask = new MovementTask(startPos.sub(2,0));
moveForwardTask.create(owner);
movementTask = new MovementTask(currentPos);
movementTask.create(owner);

moveForwardTask.start();
currentTask = moveForwardTask;
movementTask.start();
owner.getEntity().getEvents().trigger("walkStart");
currentTask = movementTask;

this.owner.getEntity().getEvents().trigger("finalBossMovementStart");
}

@Override
public void update() {
if (currentTask.getStatus() != Status.ACTIVE) {
if (currentTask == moveForwardTask) {
startSwitchingLane();
} else {
if (currentTask == movementTask) {
startWaiting();
} else if (currentTask == waitTask) {
// startSwappingLane();
startMoving();
// startWaiting();;
}
// } else {
// startMoving();
// }
}
currentTask.update();
}

// private void startWaiting() {
// logger.debug("Starting waiting for switching lane");
// swapTask(waitTask);
// }
private void startWaiting() {
logger.debug("Starting waiting");

private void startSwitchingLane() {
logger.debug("Starting switching lane");
switchLaneTask.setTarget(startPos.sub(0, 2));
swapTask(switchLaneTask);
currentTask.stop();

currentTask = waitTask;
currentTask.start();
}

private void startMoving() {
logger.debug("Starting moving forward");
moveForwardTask.setTarget(startPos.sub(2,0));
swapTask(moveForwardTask);
logger.debug("Starting moving");

currentTask.stop();

movementTask.setTarget(currentPos.sub(2,0));
currentTask = movementTask;
currentTask.start();

// swapTask(movementTask);
}

private void startSwappingLane() {
logger.debug("Starting swapping");

currentTask.stop();

float laneHeight = viewportHeight / 8;

if (currLane == 0) {
// Move up
swapLaneTask.setTarget(currentPos.add(0, laneHeight));

currLane++;
} else {
// Temporary move down for all other cases
swapLaneTask.setTarget(currentPos.sub(0, laneHeight));

currLane--;
}

currentTask = swapLaneTask;
swapLaneTask.start();

// swapTask(swapLaneTask);
}

private void swapTask(Task newTask) {
Expand All @@ -90,5 +133,4 @@ private void swapTask(Task newTask) {
currentTask = newTask;
currentTask.start();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.csse3200.game.ai.tasks.AITaskComponent;
import com.csse3200.game.components.*;
import com.csse3200.game.components.npc.BossAnimationController;
import com.csse3200.game.components.tasks.FinalBossMovementTask;
import com.csse3200.game.components.tasks.RangeBossTask;
import com.csse3200.game.entities.Entity;
import com.csse3200.game.entities.configs.BossKingConfigs;
Expand All @@ -25,11 +26,11 @@ public class BossKingFactory {
private static final int BOSS_MOB_AGRO_RANGE = 10;

// Create Boss King 1
public static Entity createBossKing1(Entity target) {
public static Entity createBossKing1(Entity target, int numLane) {
BossKingConfigs config = configs.BossKing;
Entity bossKing1 = createBaseBoss(target);

AITaskComponent aiTaskComponent1 = new AITaskComponent().addTask(new RangeBossTask(3f));
AITaskComponent aiTaskComponent1 = new AITaskComponent().addTask(new RangeBossTask(1f));

// Animation section
AnimationRenderComponent animator1 = new AnimationRenderComponent(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ void beforeEach() {

@Test
void shouldTriggerEvent() {
FinalBossMovementTask FBMTask = new FinalBossMovementTask(1f);
FinalBossMovementTask FBMTask = new FinalBossMovementTask(1f, 2);

AITaskComponent aiTaskComponent = new AITaskComponent().addTask(FBMTask);
Entity entity = new Entity().addComponent(aiTaskComponent).addComponent(new PhysicsMovementComponent());
Expand Down

0 comments on commit 052fecd

Please sign in to comment.