Skip to content

Commit

Permalink
Merge branch 'feature/Team4/integrate-enemies' of https://github.com/…
Browse files Browse the repository at this point in the history
…UQcsse3200/2023-studio-3 into feature/Team4/integrate-enemies
  • Loading branch information
samsully committed Sep 6, 2023
2 parents 2283ed2 + bfb1b8b commit c944054
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ public void create() {
spawnBuilding2();
spawnMountains();
player = spawnPlayer();
player.getEvents().addListener("spawnWave", this::spawnXenoGrunts);

playMusic();

Expand Down Expand Up @@ -312,6 +313,7 @@ private void spawnProjectile(Vector2 position, Entity target, int space, int di

// }


private void spawnXenoGrunts() {
GridPoint2 minPos = terrain.getMapBounds(0).sub(1, 5);
GridPoint2 maxPos = terrain.getMapBounds(0).sub(1, 25);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package com.csse3200.game.components.tasks;

import com.badlogic.gdx.math.Vector2;
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.services.GameTime;
import com.csse3200.game.services.ServiceLocator;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class SpawnWaveTask extends DefaultTask implements PriorityTask {
private static final Logger logger = LoggerFactory.getLogger(SpawnWaveTask.class);
private final GameTime globalTime;
private long endTime;

private final int SPAWNING_INTERVAL = 10;

public SpawnWaveTask() {
this.globalTime = ServiceLocator.getTimeSource();
}

@Override
public int getPriority() {
return 10; // Low priority task
}

@Override
public void start() {
super.start();
endTime = globalTime.getTime() + (SPAWNING_INTERVAL * 1000);
}

@Override
public void update() {
if (globalTime.getTime() >= endTime) {
this.owner.getEntity().getEvents().trigger("spawnWave");
endTime = globalTime.getTime() + (SPAWNING_INTERVAL * 1000L); // reset end time
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.csse3200.game.components.npc.XenoAnimationController;
import com.csse3200.game.components.TouchAttackComponent;
import com.csse3200.game.components.tasks.MobAttackTask;
import com.csse3200.game.components.tasks.SpawnWaveTask;
import com.csse3200.game.components.tasks.WanderTask;
import com.csse3200.game.entities.Entity;
import com.csse3200.game.entities.Melee;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
package com.csse3200.game.entities.factories;

import com.badlogic.gdx.math.Vector2;
import com.csse3200.game.ai.tasks.AITaskComponent;
import com.csse3200.game.components.CombatStatsComponent;
import com.csse3200.game.components.player.InventoryComponent;
import com.csse3200.game.components.player.PlayerActions;
import com.csse3200.game.components.player.PlayerStatsDisplay;
import com.csse3200.game.components.tasks.MobAttackTask;
import com.csse3200.game.components.tasks.SpawnWaveTask;
import com.csse3200.game.components.tasks.WanderTask;
import com.csse3200.game.entities.Entity;
import com.csse3200.game.entities.configs.PlayerConfig;
import com.csse3200.game.files.FileLoader;
Expand Down Expand Up @@ -33,7 +38,9 @@ public class PlayerFactory {
public static Entity createPlayer() {
InputComponent inputComponent =
ServiceLocator.getInputService().getInputFactory().createForPlayer();

AITaskComponent aiComponent =
new AITaskComponent()
.addTask(new SpawnWaveTask());
Entity player =
new Entity()
.addComponent(new TextureRenderComponent("images/box_boy_leaf.png"))
Expand All @@ -44,6 +51,7 @@ public static Entity createPlayer() {
.addComponent(new CombatStatsComponent(stats.health, stats.baseAttack))
.addComponent(new InventoryComponent(stats.gold))
.addComponent(inputComponent)
.addComponent(aiComponent)
.addComponent(new PlayerStatsDisplay());

PhysicsUtils.setScaledCollider(player, 0.6f, 0.3f);
Expand Down

0 comments on commit c944054

Please sign in to comment.