Skip to content

Commit

Permalink
Added UpgraderUIComponent to new towers, Changed position of UI
Browse files Browse the repository at this point in the history
  • Loading branch information
Hasakev committed Oct 11, 2023
1 parent 5488c94 commit ef486ab
Show file tree
Hide file tree
Showing 11 changed files with 58 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -331,15 +331,14 @@ public void create() {
// spawnWeaponTower();
// spawnGapScanners();
// spawnDroidTower();
// spawnFireWorksTower(); // Commented these out until they are needed for Demonstration
// spawnPierceTower();
// spawnRicochetTower();
spawnFireWorksTower(); // Commented these out until they are needed for Demonstration
spawnPierceTower();
spawnRicochetTower();
// spawnBombship();
}

private void displayUI() {
Entity ui = new Entity();
ui.addComponent(new GameAreaDisplay("Box Forest"));
ui.addComponent(ServiceLocator.getGameEndService().getDisplay());
ui.addComponent(ServiceLocator.getCurrencyService().getDisplay());
spawnEntity(ui);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ private void addActors() {
table = new Table();
table.top().left();
table.setFillParent(true);
table.padTop(140f).padLeft(20f);
table.padTop(60f).padLeft(5f);

scrapsTb = createButton("images/economy/scrapBanner.png",
ServiceLocator.getCurrencyService().getScrap().getAmount());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ private void addActors() {
table = new Table();
table.top().left();
table.setFillParent(true);
table.padTop(80f).padLeft(20f);
table.padTop(0f).padLeft(5f);

Drawable drawable = new TextureRegionDrawable(new TextureRegion(
new Texture("images/engineers/engineerBanner.png")));
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();

Expand All @@ -53,6 +56,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 All @@ -79,7 +83,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
Expand Up @@ -14,6 +14,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 @@ -32,6 +34,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 All @@ -78,6 +82,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 @@ -14,6 +14,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 @@ -38,6 +40,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();

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 All @@ -80,7 +84,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 @@ -2,8 +2,8 @@

public class FireworksTowerConfig {
public int health = 1;
public int baseAttack = 0;
public int baseAttack = 1;
public int cost = 1;
public int attackRate =0;
public int attackRate =1;
public int incomeRate =0;
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

public class PierceTowerConfig {
public int health = 1;
public int baseAttack = 0;
public int baseAttack = 1;
public int cost = 1;
public float attackRate = 1;
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

public class RicochetTowerConfig {
public int health = 1;
public int baseAttack = 0;
public int baseAttack = 1;
public int cost = 1;
public float attackRate = 1;
}
Original file line number Diff line number Diff line change
Expand Up @@ -196,14 +196,14 @@ public static Entity createTNTTower() {

TNTTower
.addComponent(new CombatStatsComponent(config.health, config.baseAttack))
.addComponent(new UpgradableStatsComponent(config.attackRate))
.addComponent(new CostComponent(config.cost))
.addComponent(new TNTDamageComponent(PhysicsLayer.NPC,TNT_KNOCK_BACK_FORCE,TNT_TOWER_RANGE))
.addComponent(aiTaskComponent)
.addComponent(animator)
.addComponent(new TNTAnimationController());

TNTTower.getComponent(AnimationRenderComponent.class).scaleEntity();
TNTTower.removeComponent(TowerUpgraderComponent.class);

return TNTTower;
}
Expand Down Expand Up @@ -275,7 +275,6 @@ public static Entity createWeaponTower() {
.addComponent(new CombatStatsComponent(config.health, config.baseAttack))
.addComponent(new UpgradableStatsComponent(config.attackRate))
.addComponent(new CostComponent(config.cost))
.addComponent(new UpgradableStatsComponent(config.attackRate))
.addComponent(aiTaskComponent)
.addComponent(animator)
.addComponent(new TowerAnimationController());
Expand Down Expand Up @@ -370,6 +369,7 @@ public static Entity createFireworksTower() {

fireworksTower
.addComponent(new CombatStatsComponent(config.health, config.baseAttack))
.addComponent(new UpgradableStatsComponent(config.attackRate))
.addComponent((new CostComponent(config.cost)))
.addComponent(aiTaskComponent)
.addComponent(animator)
Expand Down Expand Up @@ -404,6 +404,7 @@ public static Entity createPierceTower() {
pierceTower
.addComponent(animator)
.addComponent(new PierceTowerAnimationController())
.addComponent(new UpgradableStatsComponent(config.attackRate))
.addComponent(new CombatStatsComponent(config.health, config.baseAttack))
.addComponent((new CostComponent(config.cost)))
.addComponent(aiTaskComponent);
Expand Down Expand Up @@ -432,6 +433,7 @@ public static Entity createRicochetTower() {
ricochetTower
.addComponent(animator)
.addComponent(new RicochetTowerAnimationController())
.addComponent(new UpgradableStatsComponent(config.attackRate))
.addComponent(new CombatStatsComponent(config.health, config.baseAttack))
.addComponent((new CostComponent(config.cost)))
.addComponent(aiTaskComponent);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.csse3200.game.input;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Camera;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.Texture;
Expand Down Expand Up @@ -33,6 +34,8 @@
import java.util.Iterator;
import java.util.Map;

import static java.lang.Math.round;

public class UpgradeUIComponent extends InputComponent {
private static final Logger logger = LoggerFactory.getLogger(ForestGameArea.class);
private final EntityService entityService;
Expand Down Expand Up @@ -85,21 +88,21 @@ public boolean touchDown(int screenX, int screenY, int pointer, int button) {
Vector2 cursorPosition = new Vector2(worldCoordinates.x, worldCoordinates.y);
Entity clickedEntity = entityService.getEntityAtPosition(cursorPosition.x, cursorPosition.y);

//temp fix to prevent upgrading of new towers
if (clickedEntity!= null && (clickedEntity.getComponent(RicochetTowerAnimationController.class) != null ||
clickedEntity.getComponent(PierceTowerAnimationController.class) != null ||
clickedEntity.getComponent(FireworksTowerAnimationController.class) != null)) {
return false;
}
//
// //temp fix to prevent upgrading of new towers
// if (clickedEntity!= null && (clickedEntity.getComponent(RicochetTowerAnimationController.class) != null ||
// clickedEntity.getComponent(PierceTowerAnimationController.class) != null ||
// clickedEntity.getComponent(FireworksTowerAnimationController.class) != null)) {
// return false;
// }
// //

// If the clicked position contains a turret, and the turret is upgradable and not a TNT tower
if (clickedEntity != null && clickedEntity.getComponent(TowerUpgraderComponent.class) != null
&& clickedEntity.getComponent(TNTDamageComponent.class) == null) {
) {
// TNT TowerUpgraderComponent can be removed later, but possibly useful for future sprint.
// Clear all existing upgrade tables
logger.info("clickedEntity: " + clickedEntity);

// logger.info("clickedEntity: " + clickedEntity);
//
clearUpgradeTables();
// Check if there is an existing upgrade table for this turret entity
Table existingUpgradeTable = upgradeTables.get(clickedEntity);
Expand All @@ -110,8 +113,6 @@ public boolean touchDown(int screenX, int screenY, int pointer, int button) {
} else {
// If no upgrade table exists, create and store a new one
Table newUpgradeTable = createUpgradeTable(clickedEntity);
Vector2 UICoordinates = stage.screenToStageCoordinates(new Vector2(screenX, screenY));
newUpgradeTable.setPosition(UICoordinates.x, UICoordinates.y);
stage.addActor(newUpgradeTable);

// Store the new upgrade table in the map
Expand Down Expand Up @@ -149,9 +150,11 @@ private void clearUpgradeTables() {
private Table createUpgradeTable(Entity turretEntity) {
// This is the overarching table that contains the close button, the inner table, and the cost display
Table upgradeTable = new Table();
upgradeTable.top();
upgradeTable.top().left();
upgradeTable.defaults().pad(0).space(0);
upgradeTable.setSize(60, 60);
upgradeTable.padTop(5f).padLeft(5f);
upgradeTable.setPosition(0, round((float) Gdx.graphics.getHeight() / 1.3f));

// The inner table contains the upgrade buttons and the stats display
Table innerUpgradeTable = new Table();
Expand Down Expand Up @@ -380,6 +383,7 @@ public void exit(InputEvent event, float x, float y, int pointer, Actor toActor)
}
});
}
logger.info(String.valueOf(attack));
if (attack != 0) {
innerUpgradeTable.add(attackIconImage).padRight(5).width(32).height(32); // Add attack icon
innerUpgradeTable.add(attackLabel).expandX().left();
Expand Down

0 comments on commit ef486ab

Please sign in to comment.