Skip to content

Commit

Permalink
Merge pull request #117 from UQcsse3200/Team-2--Alasdair-Branch
Browse files Browse the repository at this point in the history
Team 2  alasdair branch
  • Loading branch information
The-AhmadAA authored Sep 8, 2023
2 parents 4169819 + 5549e12 commit bfc1018
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,11 @@ private boolean isTargetVisible() {
private void changeFireRateInterval(int perMinute) {
float oldFireSpeed = 1/fireRateInterval;
float newFireSpeed = oldFireSpeed + perMinute/60f;
fireRateInterval = 1/newFireSpeed;
if (newFireSpeed == 0) {
return;
} else {
fireRateInterval = 1 / newFireSpeed;
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,7 @@ public static Entity createWeaponTower() {
.addComponent(new CostComponent(config.cost))
.addComponent(aiTaskComponent)
.addComponent(animator)
.addComponent(new TowerAnimationController())
.addComponent(new TowerUpgraderComponent());
.addComponent(new TowerAnimationController());

return weapon;

Expand All @@ -132,7 +131,8 @@ public static Entity createBaseTower() {
Entity tower = new Entity()
.addComponent(new ColliderComponent())
.addComponent(new HitboxComponent().setLayer(PhysicsLayer.OBSTACLE)) // TODO: we might have to change the names of the layers
.addComponent(new PhysicsComponent().setBodyType(BodyType.StaticBody));
.addComponent(new PhysicsComponent().setBodyType(BodyType.StaticBody))
.addComponent(new TowerUpgraderComponent());

return tower;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,20 @@ void increaseFireRate() {
verify(towerUpgraderComponent).upgradeTower(TowerUpgraderComponent.UPGRADE.FIRERATE, 60);
assertEquals(0.5, towerCombatTask.getFireRateInterval());
}

@Test
void divideByZeroDefaultToIgnore() {
entity.addComponent(towerUpgraderComponent);
AITaskComponent aiTaskComponent = new AITaskComponent();
ServiceLocator.registerPhysicsService(mock(PhysicsService.class));
ServiceLocator.registerTimeSource(mock(GameTime.class));
TowerCombatTask towerCombatTask = new TowerCombatTask(10, 10, 1);
aiTaskComponent.addTask(towerCombatTask);
entity.addComponent(aiTaskComponent);
towerCombatTask.start();
entity.create();
entity.getEvents().trigger("upgradeTower", TowerUpgraderComponent.UPGRADE.FIRERATE, -60);
verify(towerUpgraderComponent).upgradeTower(TowerUpgraderComponent.UPGRADE.FIRERATE, -60);
assertEquals(1., towerCombatTask.getFireRateInterval());
}
}

0 comments on commit bfc1018

Please sign in to comment.