Skip to content

Commit

Permalink
fixed weapon tower so it could die and projectile was in the lane
Browse files Browse the repository at this point in the history
  • Loading branch information
ThivanW committed Oct 11, 2023
1 parent 3839d77 commit 6a21853
Showing 1 changed file with 15 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@
import com.csse3200.game.ai.tasks.DefaultTask;
import com.csse3200.game.ai.tasks.PriorityTask;
import com.csse3200.game.areas.ForestGameArea;
import com.csse3200.game.components.CombatStatsComponent;
import com.csse3200.game.entities.Entity;
import com.csse3200.game.entities.factories.ProjectileFactory;
import com.csse3200.game.physics.PhysicsEngine;
import com.csse3200.game.physics.PhysicsLayer;
import com.csse3200.game.physics.raycast.RaycastHit;
import com.csse3200.game.rendering.AnimationRenderComponent;
import com.csse3200.game.services.GameTime;
import com.csse3200.game.services.ServiceLocator;
import org.slf4j.Logger;
Expand All @@ -30,6 +32,7 @@ public class TowerCombatTask extends DefaultTask implements PriorityTask {
private static final String DEPLOY = "deployStart";
private static final String FIRING = "firingStart";
private static final String IDLE = "idleStart";
private static final String DEATH = "deathStart";

// class attributes
private final int priority; // The active priority this task will have
Expand All @@ -44,7 +47,7 @@ public class TowerCombatTask extends DefaultTask implements PriorityTask {
private static final Logger logger = LoggerFactory.getLogger(ForestGameArea.class);

private enum STATE {
IDLE, DEPLOY, FIRING, STOW
IDLE, DEPLOY, FIRING, STOW, DEATH
}
private STATE towerState = STATE.IDLE;

Expand Down Expand Up @@ -114,6 +117,11 @@ public void update() {
*/
public void updateTowerState() {
// configure tower state depending on target visibility
if (owner.getEntity().getComponent(CombatStatsComponent.class).getHealth() <= 0 && towerState != STATE.DEATH) {
owner.getEntity().getEvents().trigger(DEATH);
towerState = STATE.DEATH;
return;
}
switch (towerState) {
case IDLE -> {
// targets detected in idle mode - start deployment
Expand Down Expand Up @@ -144,7 +152,7 @@ public void updateTowerState() {

Entity newProjectile = ProjectileFactory.createFireBall(PhysicsLayer.NPC, new Vector2(100, owner.getEntity().getPosition().y), new Vector2(2f,2f));
newProjectile.setScale(1.1f, 0.8f);
newProjectile.setPosition((float) (owner.getEntity().getPosition().x + 0.5), (float) (owner.getEntity().getPosition().y + 0.5));
newProjectile.setPosition((float) (owner.getEntity().getPosition().x + 0.5), (float) (owner.getEntity().getPosition().y));
ServiceLocator.getEntityService().register(newProjectile);

// * TEMPRORARYYYYYYYY PLS DON'T DELETE THIS
Expand Down Expand Up @@ -177,6 +185,11 @@ public void updateTowerState() {
towerState = STATE.IDLE;
}
}
case DEATH -> {
if (owner.getEntity().getComponent(AnimationRenderComponent.class).isFinished()) {
owner.getEntity().setFlagForDelete(true);
}
}
}
}
/**
Expand Down

0 comments on commit 6a21853

Please sign in to comment.