Skip to content

Commit

Permalink
Cleaning up forest game area and effects component
Browse files Browse the repository at this point in the history
  • Loading branch information
MiniSoda17 committed Oct 16, 2023
1 parent 869ac9d commit d206e3e
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 246 deletions.
111 changes: 0 additions & 111 deletions source/core/src/main/com/csse3200/game/areas/ForestGameArea.java
Original file line number Diff line number Diff line change
Expand Up @@ -394,106 +394,6 @@ public void spawnMob(String entity, GridPoint2 randomPos, int health) {
spawnEntityAt(mob, randomPos, true, false);
}

private void spawnWeaponTower() {
GridPoint2 minPos = new GridPoint2(0, 0);
GridPoint2 maxPos = terrain.getMapBounds(0).sub(5, 1);

for (int i = 0; i < NUM_WEAPON_TOWERS + 7 ; i++) {
GridPoint2 randomPos1 = RandomUtils.random(minPos, maxPos);
GridPoint2 randomPos2 = RandomUtils.random(minPos, maxPos);
Entity wallTower = TowerFactory.createWallTower();
Entity fireTower = TowerFactory.createFireTower();
Entity stunTower = TowerFactory.createStunTower();
spawnEntityAt(fireTower, randomPos1, true, true);
spawnEntityAt(stunTower, randomPos2, true, true);
spawnEntityAt(wallTower, randomPos2, true, true);
}
}

// * TEMPORARY FOR TESTING
private void spawnFireTowerAt(int x, int y) {
GridPoint2 pos = new GridPoint2(x, y);
Entity fireTower = TowerFactory.createFireTower();

spawnEntityAt(fireTower, pos, true, true);
}
private void spawnDroidTowerAt(int x, int y) {
GridPoint2 pos = new GridPoint2(x, y);
Entity droidTower = TowerFactory.createDroidTower();

spawnEntityAt(droidTower, pos, true, true);
}

private void spawnTNTTower() {
GridPoint2 minPos = new GridPoint2(0, 0);
GridPoint2 maxPos = terrain.getMapBounds(0).sub(5, 1);

for (int i = 0; i < NUM_WEAPON_TOWERS + 5; i++) {
GridPoint2 randomPos = RandomUtils.random(minPos, maxPos);
Entity weaponTower = TowerFactory.createTNTTower();
spawnEntityAt(weaponTower, randomPos, true, true);
}

}
private void spawnFireWorksTower() {
GridPoint2 minPos = new GridPoint2(0, 2);
GridPoint2 maxPos = terrain.getMapBounds(0).sub(1, 1);

for (int i = 0; i < NUM_WEAPON_TOWERS; i++) {
GridPoint2 randomPos = RandomUtils.random(minPos, maxPos);
Entity FireWorksTower = TowerFactory.createFireworksTower();
spawnEntityAt(FireWorksTower, randomPos, true, true);
}

}
private void spawnPierceTower() {
GridPoint2 minPos = new GridPoint2(0, 2);
GridPoint2 maxPos = terrain.getMapBounds(0).sub(3, 3);

for (int i = 0; i < NUM_WEAPON_TOWERS; i++) {
GridPoint2 randomPos = RandomUtils.random(minPos, maxPos);
Entity PierceTower = TowerFactory.createPierceTower();
spawnEntityAt(PierceTower, randomPos, true, true);
}

}
private void spawnRicochetTower() {
GridPoint2 minPos = new GridPoint2(0, 2);
GridPoint2 maxPos = terrain.getMapBounds(0).sub(0, 3);

for (int i = 0; i < NUM_WEAPON_TOWERS; i++) {
GridPoint2 randomPos = RandomUtils.random(minPos, maxPos);
Entity RicochetTower = TowerFactory.createRicochetTower();
spawnEntityAt(RicochetTower, randomPos, true, true);
}

}

private void spawnBombship() {
GridPoint2 minPos = new GridPoint2(0, 0);
GridPoint2 maxPos = terrain.getMapBounds(0).sub(5, 1);
Entity bombship = BombshipFactory.createBombship();
spawnEntityAt(bombship, minPos, true, true);
}

private void spawnDroidTower() {
GridPoint2 minPos = new GridPoint2(0, 0);
GridPoint2 maxPos = terrain.getMapBounds(0).sub(5, 1);

for (int i = 0; i < NUM_WEAPON_TOWERS + 5; i++) {
GridPoint2 randomPos = RandomUtils.random(minPos, maxPos);
Entity weaponTower = TowerFactory.createDroidTower();
spawnEntityAt(weaponTower, randomPos, true, false);
}
}

private void playMusic() {
Music music = ServiceLocator.getResourceService().getAsset(BACKGROUND_MUSIC, Music.class);
music.setLooping(true);
music.setVolume(0.3f);
music.play();
}

private void loadAssets() {
logger.debug("Loading assets");
ResourceService resourceService = ServiceLocator.getResourceService();
Expand Down Expand Up @@ -541,17 +441,6 @@ private void spawnScrap() {
}
}

private void spawnIncome() {
GridPoint2 minPos = new GridPoint2(0, 0);
GridPoint2 maxPos = terrain.getMapBounds(0).sub(2, 2);

for (int i = 0; i < 50; i++) {
GridPoint2 randomPos = RandomUtils.random(minPos, maxPos);
Entity towerfactory = TowerFactory.createIncomeTower();
spawnEntityAt(towerfactory, randomPos, true, true);
}
}

/**
* Creates the scanners (one per lane) that detect absence of towers and presence of mobs,
* and trigger engineer spawning
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,13 @@

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.physics.BodyUserData;
import com.csse3200.game.physics.PhysicsLayer;
import com.csse3200.game.physics.components.HitboxComponent;
import com.csse3200.game.physics.components.PhysicsMovementComponent;
import com.csse3200.game.services.ServiceLocator;

import com.badlogic.gdx.utils.Timer;
import com.badlogic.gdx.utils.Timer.Task;

import com.badlogic.gdx.utils.Array;

/**
Expand Down Expand Up @@ -102,6 +95,7 @@ public void applySingleEffect(ProjectileEffects effect, Entity targetEntity) {
}
effectComponent.applyEffect(effect, hostEntity, targetEntity);
}

/**
* Used for aoe projectiles to apply effects to all entities within the area of effect (radius).
* @param effect effect to be applied to entities within radius
Expand Down Expand Up @@ -136,132 +130,4 @@ public void applyAoeEffect(ProjectileEffects effect) {
effectComponent.applyEffect(effect, hostEntity, targetEntity);
}
}

/**
* Deals damage to target based on hosts' CombatStatsComponent
* @param target CombatStatsComponent of entity hit by projectile
* @param host CombatStatsComponent of projectile
*/
private void fireballEffect(CombatStatsComponent target, CombatStatsComponent host) {
target.hit(host);
}

// /**
// * Applies 5 ticks of damage from hosts' CombatStatsComponent over 5 seconds
// * @param target CombatStatsComponent of entity hit by projectile
// * @param host CombatStatsComponent of projectile
// */
// private void burnEffect(CombatStatsComponent target, CombatStatsComponent host) {
// // Ensure burn effects aren't applied multiple times by same projectile
// if (burnEntities.contains(target, false)) {
// return;
// }
// burnEntities.add(target);
// // Create a timer task to apply the effect repeatedly
// int numberOfTicks = 5;
// long delay = 1;
// Timer.schedule(new Timer.Task() {
// private int count = 0;
//
// @Override
// public void run() {
// if (count < numberOfTicks) {
// target.hit(host);
// count++;
// } else {
// // Ensure to cancel the task when it's done
// this.cancel();
// }
// }
// }, delay, delay);
// }

/**
* Applies slow effect to targetEntity. If entity is a mob, speed
* and firing rate will be slowed. If entity is a tower, firing rate
* will be slowed
* @param targetEntity Entity for slow effect to be applied to
*/
private void slowEffect(Entity targetEntity) {
boolean towerFlag = false;
boolean mobFlag = false;

PhysicsMovementComponent targetPhysics = null;
float xSpeed = 0;
float ySpeed = 0;

// Create a timer task to apply the effect repeatedly
if (PhysicsLayer.contains(PhysicsLayer.HUMANS, targetEntity.getComponent(HitboxComponent.class).getLayer())) {
// towers
towerFlag = true;
targetEntity.getEvents().trigger("upgradeTower", TowerUpgraderComponent.UPGRADE.FIRERATE, -30);
} else if (PhysicsLayer.contains(PhysicsLayer.NPC, targetEntity.getComponent(HitboxComponent.class).getLayer())) {
// mobs
mobFlag = true;
targetPhysics = targetEntity.getComponent(PhysicsMovementComponent.class);
if (targetPhysics == null) {
return;
}

// Halve the mob speed
xSpeed = targetPhysics.getSpeed().x;
ySpeed = targetPhysics.getSpeed().y;
targetPhysics.setSpeed(new Vector2(xSpeed/2, ySpeed/2));
} else {
return;
}

// Reset speed
boolean finalTowerFlag = towerFlag;
boolean finalMobFlag = mobFlag;
PhysicsMovementComponent finalTargetPhysics = targetPhysics;
float finalXSpeed = xSpeed;
float finalYSpeed = ySpeed;
Timer.schedule(new Task() {
@Override
public void run() {
if (finalTowerFlag) {
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);
}
}

0 comments on commit d206e3e

Please sign in to comment.