Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Team 5] UI Upgrade Changes, Bug Fixes, Code Smells, Drops #290

Merged
merged 14 commits into from
Oct 17, 2023
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ public AITaskComponent addTask(PriorityTask task) {
*/
public <T extends PriorityTask> T getTask(Class<T> task) {
for (PriorityTask priorityTask : priorityTasks) {
if (priorityTask.getClass() == task) {
return (T) priorityTask;
if (task.isInstance(priorityTask)) {
return task.cast(priorityTask);
}
}
logger.info("Task {} not found", task);
Expand Down Expand Up @@ -83,25 +83,17 @@ public void dispose() {
*/
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);
}
priorityTasksToBeRestored.addAll(priorityTasks);
priorityTasks.clear();
}

/**
* 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);
}
priorityTasks.addAll(priorityTasksToBeRestored);
priorityTasksToBeRestored.clear();
this.update();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,7 @@ public void create() {
// spawnSplittingXenoGrunt(17, 2);
// spawnPatrick();
// spawnDemonBoss();
// spawnIceBaby();
// spawnSplittingRocky(17, 4);
// spawnFireWizard(17, 3);
// spawnNecromancer(17, 2);
Expand Down Expand Up @@ -350,8 +351,13 @@ private void spawnDemonBoss() {
spawnEntityAt(demon, new GridPoint2(19, 5), true, false);
}

private void spawnIceBaby() {
Entity iceBaby = MobBossFactory.createIceBoss(5000);
spawnEntityAt(iceBaby, new GridPoint2(19, 5), true, false);
}

private void spawnPatrick() {
Entity patrick = MobBossFactory.createPatrickBoss(3000);
Entity patrick = MobBossFactory.createPatrickBoss(5000);
spawnEntityAt(patrick, new GridPoint2(18, 5), true, false);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,6 @@ public void update() {

// apply slow effect
if (mob) {
if (target == null) {
return;
}
if (slowFlag) {
isSlowed = true;
Vector2 half_speed = new Vector2(defaultTargetSpeed.x / 2, defaultTargetSpeed.y / 2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,9 @@ private void addActors() {
TextButton pauseBtn = ButtonFactory.createButton("Pause");

// Starting animation for pause button
pauseBtn.setPosition(Gdx.graphics.getWidth(), Gdx.graphics.getHeight() - 150);
pauseBtn.addAction(new SequenceAction(Actions.moveTo(Gdx.graphics.getWidth() - 200,
Gdx.graphics.getHeight() - 150, 1f, Interpolation.fastSlow)));
pauseBtn.setPosition(Gdx.graphics.getWidth(), Gdx.graphics.getHeight() - 150f);
pauseBtn.addAction(new SequenceAction(Actions.moveTo(Gdx.graphics.getWidth() - 200f,
Gdx.graphics.getHeight() - 150f, 1f, Interpolation.fastSlow)));

// Spawns a pause menu when the button is pressed.
pauseBtn.addListener(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ private void addActors() {
remainingMobsButton = ButtonFactory.createButton("Mobs:"
+ ServiceLocator.getWaveService().getEnemyCount());

remainingMobsButton.setPosition(Gdx.graphics.getWidth(), Gdx.graphics.getHeight() - 230);
remainingMobsButton.addAction(new SequenceAction(Actions.moveTo(Gdx.graphics.getWidth() - 218,
Gdx.graphics.getHeight() - 230, 1f, Interpolation.fastSlow)));
remainingMobsButton.setPosition(Gdx.graphics.getWidth(), Gdx.graphics.getHeight() - 230f);
remainingMobsButton.addAction(new SequenceAction(Actions.moveTo(Gdx.graphics.getWidth() - 218f,
Gdx.graphics.getHeight() - 230f, 1f, Interpolation.fastSlow)));

buttonTable.top().right().padTop(130f).padRight(80f);
buttonTable.setFillParent(true);
Expand Down Expand Up @@ -81,9 +81,9 @@ public void createTimerButton() {

timerButton = ButtonFactory.createButton("Next wave in:"
+ (ServiceLocator.getWaveService().getNextWaveTime() / 1000));
timerButton.setPosition(Gdx.graphics.getWidth(), Gdx.graphics.getHeight() - 300);
timerButton.addAction(new SequenceAction(Actions.moveTo(Gdx.graphics.getWidth() - 445,
Gdx.graphics.getHeight() - 300, 1f, Interpolation.fastSlow)));
timerButton.setPosition(Gdx.graphics.getWidth(), Gdx.graphics.getHeight() - 300f);
timerButton.addAction(new SequenceAction(Actions.moveTo(Gdx.graphics.getWidth() - 445f,
Gdx.graphics.getHeight() - 300f, 1f, Interpolation.fastSlow)));
buttonTable.row();
buttonTable.add(timerButton).padRight(10f);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
import com.csse3200.game.services.GameTime;
import com.csse3200.game.services.ServiceLocator;

import static java.lang.Math.round;


/**
* The FireworksTowerCombatTask runs the AI for the FireworksTower class. The tower scans for mobs and targets in a
Expand All @@ -38,6 +40,7 @@ public class FireworksTowerCombatTask extends DefaultTask implements PriorityTas
private final Vector2 maxRangePosition = new Vector2();
private PhysicsEngine physics;
private GameTime timeSource;
private float fireRateInterval;
private long endTime;
private final RaycastHit hit = new RaycastHit();
private boolean shoot = true;
Expand All @@ -54,6 +57,7 @@ public enum STATE {
public FireworksTowerCombatTask(int priority, float maxRange) {
this.priority = priority;
this.maxRange = maxRange;
this.fireRateInterval = 1;
physics = ServiceLocator.getPhysicsService().getPhysics();
timeSource = ServiceLocator.getTimeSource();
}
Expand Down Expand Up @@ -81,7 +85,12 @@ public void start() {
public void update() {
if (timeSource.getTime() >= endTime) {
updateTowerState();
endTime = timeSource.getTime() + (INTERVAL * 1000);
if (towerState == STATE.ATTACK) {
endTime = timeSource.getTime() + round(fireRateInterval * 1000);
} else {
endTime = timeSource.getTime() + (INTERVAL * 1000);
}

}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.csse3200.game.components.tasks;

import com.badlogic.gdx.math.MathUtils;
import com.csse3200.game.ai.tasks.DefaultTask;
import com.csse3200.game.ai.tasks.PriorityTask;
import com.csse3200.game.components.CombatStatsComponent;
Expand All @@ -11,6 +12,8 @@
import com.csse3200.game.services.GameTime;


/// THIS CODE IS REDUNDANT ///

/**
* Task that prints a message to the terminal whenever it is called.
*/
Expand Down Expand Up @@ -97,10 +100,18 @@ private void killMob() {
}

private void dropCurrency() {
float randomValue = MathUtils.random(0,1);
Entity currency;
if (randomValue <= 0.1f) {
currency = DropFactory.createCrystalDrop();

}
else {
currency = DropFactory.createScrapDrop();

Entity scrap = DropFactory.createScrapDrop();
scrap.setPosition(mobPosition.x,mobPosition.y);
ServiceLocator.getEntityService().register(scrap);
}
currency.setPosition(mobPosition.x,mobPosition.y);
ServiceLocator.getEntityService().register(currency);

}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,27 @@
package com.csse3200.game.components.tasks.MobTask;

import com.badlogic.gdx.math.MathUtils;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.utils.Timer;
import com.csse3200.game.ai.tasks.DefaultTask;
import com.csse3200.game.ai.tasks.PriorityTask;
import com.csse3200.game.components.CombatStatsComponent;
import com.csse3200.game.components.ProjectileEffects;
import com.csse3200.game.components.tasks.CurrencyTask;
import com.csse3200.game.components.tasks.MovementTask;
import com.csse3200.game.entities.Entity;
import com.csse3200.game.entities.factories.DropFactory;
import com.csse3200.game.entities.factories.ProjectileFactory;
import com.csse3200.game.physics.PhysicsLayer;
import com.csse3200.game.physics.components.HitboxComponent;
import com.csse3200.game.physics.components.PhysicsMovementComponent;
import com.csse3200.game.rendering.AnimationRenderComponent;
import com.csse3200.game.services.GameTime;
import com.csse3200.game.services.ServiceLocator;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.csse3200.game.components.tasks.MobTask.MobType;

/**
Expand All @@ -33,8 +40,15 @@ public class MobTask extends DefaultTask implements PriorityTask {
private static final long RANGE_ATTACK_SPEED = 5000;
private static final float MELEE_ATTACK_RANGE = 0.2f;

private static final float CRYSTAL_DROP_RATE = 0.1f;
private static final float SCRAP_DROP_RATE = 0.6f;

private static final Logger logger = LoggerFactory.getLogger(MobTask.class);


// Private variables
private final MobType mobType;

private State state = State.DEFAULT;
private Entity mob;
private AnimationRenderComponent animation;
Expand Down Expand Up @@ -121,6 +135,7 @@ public void update() {
} else if (deathFlag && animation.isFinished()) {
ServiceLocator.getWaveService().updateEnemyCount();
mob.setFlagForDelete(true);
dropCurrency();
}

if(gameTime.getTime() >= dodgeEndTime) {
Expand Down Expand Up @@ -268,4 +283,25 @@ public int getPriority() {
public void setDodge(boolean dodgeFlag) {
this.canDodge = dodgeFlag;
}

private void dropCurrency() {
float randomValue = MathUtils.random(0f,1f);
logger.info("Random value: " + randomValue);
Entity currency;
if (randomValue <= CRYSTAL_DROP_RATE) {
currency = DropFactory.createCrystalDrop();
currency.setPosition(mob.getPosition().x,mob.getPosition().y);
ServiceLocator.getEntityService().register(currency);

}
else if (randomValue <= SCRAP_DROP_RATE) {
currency = DropFactory.createScrapDrop();
currency.setPosition(mob.getPosition().x,mob.getPosition().y);
ServiceLocator.getEntityService().register(currency);

}



}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
import com.csse3200.game.services.GameTime;
import com.csse3200.game.services.ServiceLocator;

import static java.lang.Math.round;

/**
* The PierceTowerCombatTask runs the AI for the PierceTower class. The tower scans for mobs and targets in a straight
* line from its centre coordinate and executes the trigger phrases for animations depeending on the current state of
Expand All @@ -31,6 +33,7 @@ public class PierceTowerCombatTask extends DefaultTask implements PriorityTask {

// Class attributes
private final int priority;
private float fireRateInterval;
private final float maxRange;
private Vector2 towerPosition = new Vector2(10, 10);
private final Vector2 maxRangePosition = new Vector2();
Expand All @@ -52,6 +55,7 @@ public enum STATE {
public PierceTowerCombatTask(int priority, float maxRange) {
this.priority = priority;
this.maxRange = maxRange;
this.fireRateInterval = 1;
physics = ServiceLocator.getPhysicsService().getPhysics();
timeSource = ServiceLocator.getTimeSource();
}
Expand Down Expand Up @@ -79,6 +83,9 @@ public void start() {
public void update() {
if (timeSource.getTime() >= endTime) {
updateTowerState();
if (towerState == STATE.ATTACK) {
endTime = timeSource.getTime() + round(fireRateInterval * 1000);
}
endTime = timeSource.getTime() + (INTERVAL * 1000);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
import com.csse3200.game.services.GameTime;
import com.csse3200.game.services.ServiceLocator;

import static java.lang.Math.round;


/**
* The RicochetTowerCombatTask runs the AI for the RicochetTower class. The tower scans for mobs and targets in a
Expand All @@ -37,6 +39,7 @@ public class RicochetTowerCombatTask extends DefaultTask implements PriorityTask
private final Vector2 maxRangePosition = new Vector2();
private PhysicsEngine physics;
private GameTime timeSource;
private float fireRateInterval;
private long endTime;
private final RaycastHit hit = new RaycastHit();
private boolean shoot = true;
Expand All @@ -54,6 +57,7 @@ public enum STATE {
public RicochetTowerCombatTask(int priority, float maxRange) {
this.priority = priority;
this.maxRange = maxRange;
this.fireRateInterval = 1;
physics = ServiceLocator.getPhysicsService().getPhysics();
timeSource = ServiceLocator.getTimeSource();
}
Expand Down Expand Up @@ -81,7 +85,11 @@ public void start() {
public void update() {
if (timeSource.getTime() >= endTime) {
updateTowerState();
endTime = timeSource.getTime() + (INTERVAL * 1000);
if (towerState == STATE.ATTACK) {
endTime = timeSource.getTime() + round(fireRateInterval * 1000);
} else {
endTime = timeSource.getTime() + (INTERVAL * 1000);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.csse3200.game.components.ProjectileEffects;
import com.csse3200.game.components.tasks.MovementTask;
import com.csse3200.game.entities.Entity;
import com.csse3200.game.entities.factories.DropFactory;
import com.csse3200.game.entities.factories.MobBossFactory;
import com.csse3200.game.entities.factories.ProjectileFactory;
import com.csse3200.game.physics.PhysicsLayer;
Expand Down Expand Up @@ -140,6 +141,8 @@ public void update() {
slimey.setScale(5f, 5f);
ServiceLocator.getEntityService().register(slimey);
demon.setFlagForDelete(true);
dropCurrency();

}

// detect half health
Expand Down Expand Up @@ -495,4 +498,19 @@ public void run() {
}, (float) (i + 1) * 2);
}
}

private void dropCurrency() {
// Create and register 5 crystal drops around the bossPosition
for (int i = 0; i < 5; i++) {
Entity crystal = DropFactory.createCrystalDrop();

// Calculate positions around the bossPosition
float offsetX = MathUtils.random(-1f, 1f); // Adjust the range as needed
float offsetY = MathUtils.random(-1f, 1f);
float dropX = owner.getEntity().getPosition().x + offsetX;
float dropY = owner.getEntity().getPosition().y + offsetY;
crystal.setPosition(dropX, dropY);
ServiceLocator.getEntityService().register(crystal);
}
}
}
Loading
Loading