Skip to content

Commit

Permalink
Added Shooting Functionality to Engineers.
Browse files Browse the repository at this point in the history
  • Loading branch information
praneetdhoolia committed Sep 6, 2023
1 parent 443c67a commit e3b92aa
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 49 deletions.
24 changes: 4 additions & 20 deletions source/core/src/main/com/csse3200/game/areas/ForestGameArea.java
Original file line number Diff line number Diff line change
Expand Up @@ -129,34 +129,18 @@ public ForestGameArea(TerrainFactory terrainFactory) {
/** Create the game area, including terrain, static entities (trees), dynamic entities (player) */
@Override
public void create() {
// Load game assets
loadAssets();

displayUI();

spawnTerrain();
spawnBuilding1();
spawnBuilding2();
spawnMountains();
player = spawnPlayer();

playMusic();

// Types of projectile
spawnAoeProjectile(new Vector2(0, 10), player, towardsMobs, new Vector2(2f, 2f), 1);
spawnProjectile(new Vector2(0, 10), player, towardsMobs, new Vector2(2f, 2f));
spawnMultiProjectile(new Vector2(0, 10), player, towardsMobs, 20, new Vector2(2f, 2f), 7);
spawnXenoGrunts();

spawnGhosts();

// Spawn Entities
player = spawnPlayer();
spawnWeaponTower();
spawnIncome();
spawnScrap();

spawnEngineer();
bossKing1 = spawnBossKing1();
bossKing2 = spawnBossKing2();

playMusic();
}

private void displayUI() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@ public class EngineerCombatTask extends DefaultTask implements PriorityTask {
// Animation event names for the Engineer's state machine.
private static final String STOW = "";
private static final String DEPLOY = "";
private static final String FIRING = "";
private static final String IDLE = "";
private static final String DYING = "";
private static final String FIRING = "firingStart";
private static final String IDLE_LEFT = "idleLeft";
private static final String IDLE_RIGHT = "idleRight";
private static final String DYING = "deathStart";

// The Engineer's attributes.
private final int priority; // The priority of this task within the task list.
Expand All @@ -41,9 +42,9 @@ public class EngineerCombatTask extends DefaultTask implements PriorityTask {

/** The Engineer's states. */
private enum STATE {
IDLE, DEPLOY, FIRING, STOW
IDLE_LEFT, IDLE_RIGHT, DEPLOY, FIRING, STOW
}
private STATE engineerState = STATE.IDLE;
private STATE engineerState = STATE.IDLE_RIGHT;

/**
* @param priority The Engineer's combat task priority in the list of tasks.
Expand All @@ -57,7 +58,7 @@ public EngineerCombatTask(int priority, float maxRange) {
}

/**
* Starts the Task running, triggers the initial "idleStart" event.
* Runs the task and triggers Engineer's idle animation.
*/
@Override
public void start() {
Expand All @@ -66,7 +67,7 @@ public void start() {
this.engineerPosition = owner.getEntity().getCenterPosition();
this.maxRangePosition.set(engineerPosition.x + maxRange, engineerPosition.y);
// Default to idle mode
owner.getEntity().getEvents().trigger(IDLE);
owner.getEntity().getEvents().trigger(IDLE_RIGHT);

endTime = timeSource.getTime() + (INTERVAL * 500);
}
Expand All @@ -89,11 +90,18 @@ public void update() {
public void updateEngineerState() {
// configure tower state depending on target visibility
switch (engineerState) {
case IDLE -> {
case IDLE_LEFT -> {
// targets detected in idle mode - start deployment
if (isTargetVisible()) {
owner.getEntity().getEvents().trigger(DEPLOY);
engineerState = STATE.DEPLOY;
owner.getEntity().getEvents().trigger(FIRING);
engineerState = STATE.FIRING;
}
}
case IDLE_RIGHT -> {
// targets detected in idle mode - start deployment
if (isTargetVisible()) {
owner.getEntity().getEvents().trigger(FIRING);
engineerState = STATE.FIRING;
}
}
case DEPLOY -> {
Expand All @@ -110,8 +118,8 @@ public void updateEngineerState() {
// targets gone - stop firing
if (!isTargetVisible()) {

owner.getEntity().getEvents().trigger(STOW);
engineerState = STATE.STOW;
owner.getEntity().getEvents().trigger(IDLE_RIGHT);
engineerState = STATE.IDLE_RIGHT;
} else {
owner.getEntity().getEvents().trigger(FIRING);
// this might be changed to an event which gets triggered everytime the tower enters the firing state
Expand All @@ -120,17 +128,17 @@ public void updateEngineerState() {
ServiceLocator.getEntityService().register(newProjectile);
}
}
case STOW -> {
// currently stowing
if (isTargetVisible()) {
owner.getEntity().getEvents().trigger(DEPLOY);
engineerState = STATE.DEPLOY;
} else {
owner.getEntity().getEvents().trigger(IDLE);
engineerState = STATE.IDLE;
}
}
// case STOW -> {
// // currently stowing
// if (isTargetVisible()) {
//
// owner.getEntity().getEvents().trigger(DEPLOY);
// engineerState = STATE.DEPLOY;
// } else {
// owner.getEntity().getEvents().trigger(IDLE);
// engineerState = STATE.IDLE;
// }
// }
}
}
/**
Expand All @@ -139,7 +147,7 @@ public void updateEngineerState() {
@Override
public void stop() {
super.stop();
owner.getEntity().getEvents().trigger(STOW);
owner.getEntity().getEvents().trigger(IDLE_RIGHT);
}

/**
Expand Down Expand Up @@ -173,6 +181,6 @@ private int getInactivePriority() {
*/
private boolean isTargetVisible() {
// If there is an obstacle in the path to the max range point, mobs visible.
return physics.raycast(engineerPosition, maxRangePosition, TARGET, hit);
return physics.raycast(owner.getEntity().getCenterPosition(), maxRangePosition, TARGET, hit);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,6 @@ public class EngineerFactory {
public static Entity createEngineer() {
Entity engineer = createBaseHumanNPC();
BaseEntityConfig config = configs.engineer;
AITaskComponent combatComponent =
new AITaskComponent()
.addTask(new EngineerCombatTask(COMBAT_TASK_PRIORITY, ENGINEER_RANGE));

AnimationRenderComponent animator = new AnimationRenderComponent(
new TextureAtlas("images/engineers/engineer.atlas"));
Expand All @@ -75,9 +72,10 @@ public static Entity createEngineer() {
.addComponent(new CombatStatsComponent(config.health, config.baseAttack))
.addComponent(animator)
.addComponent(new HumanAnimationController());
//.addComponent(combatComponent);

engineer.getComponent(AnimationRenderComponent.class).scaleEntity();
engineer.getComponent(AITaskComponent.class)
.addTask(new EngineerCombatTask(COMBAT_TASK_PRIORITY, ENGINEER_RANGE));
engineer.setScale(1.5f, 1.2f);
return engineer;
}
Expand Down

0 comments on commit e3b92aa

Please sign in to comment.