Skip to content

Commit

Permalink
added the animations for stunTower and FireTower
Browse files Browse the repository at this point in the history
  • Loading branch information
shiv-0831 committed Sep 11, 2023
2 parents d10b851 + 0f02b04 commit 98d4f20
Show file tree
Hide file tree
Showing 20 changed files with 697 additions and 63 deletions.
55 changes: 55 additions & 0 deletions source/core/assets/images/projectiles/burn_effect.atlas
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@

burn_effect.png
size: 256, 64
format: RGBA8888
filter: Nearest, Nearest
repeat: none
projectile
rotate: false
xy: 78, 2
size: 36, 31
orig: 36, 31
offset: 0, 0
index: -1
projectile
rotate: false
xy: 2, 2
size: 36, 31
orig: 36, 31
offset: 0, 0
index: -1
projectile
rotate: false
xy: 154, 2
size: 35, 31
orig: 35, 31
offset: 0, 0
index: -1
projectile
rotate: false
xy: 40, 2
size: 36, 31
orig: 36, 31
offset: 0, 0
index: -1
projectileFinal
rotate: false
xy: 116, 2
size: 36, 31
orig: 36, 31
offset: 0, 0
index: -1
projectile
rotate: false
xy: 191, 2
size: 31, 31
orig: 31, 31
offset: 0, 0
index: -1
default
rotate: false
xy: 78, 2
size: 36, 31
orig: 36, 31
offset: 0, 0
index: -1
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
41 changes: 41 additions & 0 deletions source/core/assets/images/projectiles/oldstun_effect.atlas
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@

stun_effect.png
size: 256, 32
format: RGBA8888
filter: Nearest, Nearest
repeat: none
projectile
rotate: false
xy: 86, 3
size: 41, 27
orig: 41, 27
offset: 0, 0
index: -1
projectile
rotate: false
xy: 2, 2
size: 40, 28
orig: 40, 28
offset: 0, 0
index: -1
projectile
rotate: false
xy: 129, 2
size: 40, 28
orig: 40, 28
offset: 0, 0
index: -1
projectile
rotate: false
xy: 44, 2
size: 40, 28
orig: 40, 28
offset: 0, 0
index: -1
default
rotate: false
xy: 86, 3
size: 41, 27
orig: 41, 27
offset: 0, 0
index: -1
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
41 changes: 41 additions & 0 deletions source/core/assets/images/projectiles/stun_effect.atlas
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@

stun_effect.png
size: 128, 32
format: RGBA8888
filter: Nearest, Nearest
repeat: none
projectile
rotate: false
xy: 2, 2
size: 21, 19
orig: 21, 19
offset: 0, 0
index: -1
projectile
rotate: false
xy: 48, 2
size: 20, 19
orig: 20, 19
offset: 0, 0
index: -1
projectile
rotate: false
xy: 25, 2
size: 21, 19
orig: 21, 19
offset: 0, 0
index: -1
projectile
rotate: false
xy: 70, 2
size: 17, 19
orig: 17, 19
offset: 0, 0
index: -1
default
rotate: false
xy: 2, 2
size: 21, 19
orig: 21, 19
offset: 0, 0
index: -1
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ public class AITaskComponent extends Component implements TaskRunner {
private static final Logger logger = LoggerFactory.getLogger(AITaskComponent.class);

private final List<PriorityTask> priorityTasks = new ArrayList<>(2);
private final List<PriorityTask> priorityTasksToBeRestored = new ArrayList<>(2);
private PriorityTask currentTask;

/**
* Add a priority task to the list of tasks. This task will be run only when it has the highest
* priority, and can be stopped to run a higher priority task.
Expand Down Expand Up @@ -59,6 +59,33 @@ public void dispose() {
}
}

/**
* Empties the priorityTasks List. Disposes all of the entity's tasks.
*/
public void disposeAll() {
currentTask = null;
for (int i = 0; i < priorityTasks.size(); i++) {
priorityTasksToBeRestored.add(priorityTasks.get(i));
}
for (int i = 0; i < priorityTasks.size(); i++) {
priorityTasks.remove(i);
}
}

/**
* Restores the priorityTasks List. Adds all of the entity's disposed tasks
* back into priorityTasks.
*/
public void restore() {
for (int i = 0; i < priorityTasksToBeRestored.size(); i++) {
priorityTasks.add(priorityTasksToBeRestored.get(i));
}
for (int i = 0; i < priorityTasksToBeRestored.size(); i++) {
priorityTasksToBeRestored.remove(i);
}
this.update();
}

private PriorityTask getHighestPriorityTask() {
try {
return Collections.max(priorityTasks, Comparator.comparingInt(PriorityTask::getPriority));
Expand Down
10 changes: 7 additions & 3 deletions source/core/src/main/com/csse3200/game/areas/ForestGameArea.java
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,9 @@ public class ForestGameArea extends GameArea {
"images/projectiles/mobProjectile.png",
"images/projectiles/engineer_projectile.png",
"images/projectiles/mobKing_projectile.png",
"images/projectiles/snow_ball.png"
"images/projectiles/snow_ball.png",
"images/projectiles/burn_effect.png",
"images/projectiles/stun_effect.png"
};
private static final String[] forestTextureAtlases = {
"images/economy/econ-tower.atlas",
Expand All @@ -128,7 +130,9 @@ public class ForestGameArea extends GameArea {
"images/projectiles/mobProjectile.atlas",
"images/projectiles/engineer_projectile.atlas",
"images/projectiles/mobKing_projectile.atlas",
"images/projectiles/snow_ball.atlas"
"images/projectiles/snow_ball.atlas",
"images/projectiles/burn_effect.atlas",
"images/projectiles/stun_effect.atlas"

};
private static final String[] forestSounds = {
Expand Down Expand Up @@ -191,7 +195,7 @@ public void create() {
spawnPierceFireBall(new Vector2(2, 3), PhysicsLayer.NPC, towardsMobs, new Vector2(2f, 2f));
spawnRicochetFireball(new Vector2(2, 4), PhysicsLayer.NPC, towardsMobs, new Vector2(2f, 2f));
spawnSplitFireWorksFireBall(new Vector2(2, 5), PhysicsLayer.NPC, towardsMobs, new Vector2(2f, 2f), 12);
spawnEffectProjectile(new Vector2(2, 6), PhysicsLayer.NPC, towardsMobs, new Vector2(2f, 2f), ProjectileEffects.SLOW, false);
// spawnEffectProjectile(new Vector2(2, 6), PhysicsLayer.NPC, towardsMobs, new Vector2(2f, 2f), ProjectileEffects.SLOW, false);
// spawnProjectileTest(new Vector2(0, 8), PhysicsLayer.NPC, towardsMobs, new Vector2(2f, 2f));
spawnXenoGrunts();
// spawnGhosts();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
package com.csse3200.game.components;

import java.util.ArrayList;

import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.physics.box2d.Fixture;
import com.csse3200.game.ai.tasks.AITaskComponent;
import com.csse3200.game.components.tower.TowerUpgraderComponent;
import com.csse3200.game.entities.Entity;
import com.csse3200.game.entities.factories.ProjectileFactory;
import com.csse3200.game.physics.BodyUserData;
import com.csse3200.game.physics.PhysicsLayer;
import com.csse3200.game.physics.components.ColliderComponent;
import com.csse3200.game.physics.components.HitboxComponent;
import com.csse3200.game.physics.components.PhysicsComponent;
import com.csse3200.game.physics.components.PhysicsMovementComponent;
import com.csse3200.game.services.ServiceLocator;

Expand All @@ -29,6 +30,7 @@ public class EffectsComponent extends Component {
private HitboxComponent hitboxComponent;
private final short targetLayer;
private Array<CombatStatsComponent> burnEntities = new Array<>();
private ArrayList<Entity> stunnedEntities = new ArrayList<>();

/**
* Constructor for the AoEComponent.
Expand All @@ -50,7 +52,7 @@ public void create() {
}

private void onCollisionStart(Fixture me, Fixture other) {
// Nothing to do on collision start
// Nothing to do in collision start
}

private void onCollisionEnd(Fixture me, Fixture other) {
Expand All @@ -72,28 +74,19 @@ private void onCollisionEnd(Fixture me, Fixture other) {
return;
}

System.out.println("target layer: " + otherEntity.getLayer());

// Apply effect
switch (effect) {
case FIREBALL -> {
if (aoe) {
applyAoeEffect(ProjectileEffects.FIREBALL);
}
}
case BURN -> {
if (aoe) {
applyAoeEffect(ProjectileEffects.BURN);
} else {
applySingleEffect(ProjectileEffects.BURN, otherCombatStats, otherEntity);
}
if (effect == ProjectileEffects.FIREBALL) {
if (aoe) {
applyAoeEffect(ProjectileEffects.FIREBALL);
}
case SLOW -> {
if (aoe) {
applyAoeEffect(ProjectileEffects.SLOW);
} else {
applySingleEffect(ProjectileEffects.SLOW, otherCombatStats, otherEntity);
}
} else {
if (aoe) {
applyAoeEffect(effect);
} else {
applySingleEffect(effect, otherCombatStats, otherEntity);
}
case STUN -> {}
}
}

Expand All @@ -117,7 +110,7 @@ public void applySingleEffect(ProjectileEffects effect, CombatStatsComponent tar
burnEffect(targetCombatStats, hostCombatStats);
}
case SLOW -> {slowEffect(targetEntity);}
case STUN -> {}
case STUN -> {stunEffect(targetEntity);}
}
}
/**
Expand Down Expand Up @@ -152,7 +145,9 @@ public void applyAoeEffect(ProjectileEffects effect) {
case FIREBALL -> {fireballEffect(targetCombatStats, hostCombatStats);}
case BURN -> {burnEffect(targetCombatStats, hostCombatStats);}
case SLOW -> {slowEffect(targetEntity);}
case STUN -> {}
case STUN -> {
stunEffect(targetEntity);
}
}
} else {
return;
Expand Down Expand Up @@ -180,7 +175,6 @@ private void burnEffect(CombatStatsComponent target, CombatStatsComponent host)
return;
}
burnEntities.add(target);

// Create a timer task to apply the effect repeatedly
int numberOfTicks = 5;
long delay = 1;
Expand Down Expand Up @@ -218,7 +212,7 @@ private void slowEffect(Entity targetEntity) {
if (PhysicsLayer.contains(PhysicsLayer.HUMANS, targetEntity.getComponent(HitboxComponent.class).getLayer())) {
// towers
towerFlag = true;
//targetEntity.getEvents().trigger("upgradeTower", TowerUpgraderComponent.UPGRADE.FIRERATE, -30);
targetEntity.getEvents().trigger("upgradeTower", TowerUpgraderComponent.UPGRADE.FIRERATE, -30);
} else if (PhysicsLayer.contains(PhysicsLayer.NPC, targetEntity.getComponent(HitboxComponent.class).getLayer())) {
// mobs
mobFlag = true;
Expand All @@ -245,11 +239,47 @@ private void slowEffect(Entity targetEntity) {
@Override
public void run() {
if (finalTowerFlag) {
//targetEntity.getEvents().trigger("upgradeTower", TowerUpgraderComponent.UPGRADE.FIRERATE, 30);
targetEntity.getEvents().trigger("upgradeTower", TowerUpgraderComponent.UPGRADE.FIRERATE, 30);
} else if (finalMobFlag) {
finalTargetPhysics.setSpeed(new Vector2(finalXSpeed, finalYSpeed));
}
}
}, 5); // 5 seconds delay
}

/**
* Applies stun effect to a taget entity.
* @param targetEntity Entity for stun effect to be applied to.
*/
private void stunEffect(Entity targetEntity) {
CombatStatsComponent hostCombatStats = targetEntity.getComponent(CombatStatsComponent.class);
AITaskComponent taskComponent = targetEntity.getComponent(AITaskComponent.class);

if (hostCombatStats == null || taskComponent == null) {
return;
}

hostCombatStats.setBaseAttack(0);

if (stunnedEntities.contains(targetEntity)) {
return;
}

taskComponent.disposeAll();
stunnedEntities.add(targetEntity);

new java.util.Timer().schedule(
new java.util.TimerTask() {
@Override
public void run() {
taskComponent.restore();
for (int i = 0; i < stunnedEntities.size(); i++) {
if (stunnedEntities.get(i).equals(targetEntity)) {
stunnedEntities.remove(stunnedEntities.get(i));
}
}
this.cancel();
}
}, 5000);
}
}
Loading

0 comments on commit 98d4f20

Please sign in to comment.