Skip to content

Commit

Permalink
added multiple placement key functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
The-AhmadAA committed Oct 12, 2023
1 parent 56e1267 commit 18a7a6f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,11 @@ private void addActors() {
remainingMobsButton = new TextButton("Mobs:"
+ ServiceLocator.getWaveService().getEnemyCount(), skin);
buttonTable.top().right();
towerTable.top();
towerTable.top().padTop(80f);

buttonTable.setFillParent(true);
towerTable.setFillParent(true);

towerTable.setDebug(true);
towerTable.padTop(50f);

TowerType[] defaultTowers = {
TowerType.TNT,
TowerType.DROID,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public class BuildInputComponent extends InputComponent {
private Sound errorSound;
private Array<TowerType> towers = new Array<>();
private Array<TowerType> defaultTowers = new Array<>();
private boolean multipleTowerBuild = false;

/**
* Constructor for the BuildInputComponent
Expand Down Expand Up @@ -127,11 +128,29 @@ public boolean keyUp(int keycode) {
case Input.Keys.NUM_5:
ServiceLocator.getCurrencyService().setTowerType(towers.get(4));
return true;
case Input.Keys.CONTROL_LEFT:
// After multiple placement, deselect tower and prevent further builds
ServiceLocator.getCurrencyService().setTowerType(null);
multipleTowerBuild = false;
return true;
default:
return false;
}
}

/**
*
* @param keycode one of the constants in {@link Input.Keys}
* @return
*/
public boolean keyDown(int keycode) {
if (keycode == Input.Keys.CONTROL_LEFT) {
multipleTowerBuild = true;
return true;
}
return false;
}

/**
* Instantiates and spawns the selected tower at the given x y coordinates on the tile map. Assumes that the given
* x and y coordinate is valid and that the TowerType exists in the CurrencyService.
Expand Down Expand Up @@ -182,7 +201,9 @@ public boolean buildTower(int x, int y) {
buildSound.setVolume(soundId, 0.4f);

// deselect the tower after building
ServiceLocator.getCurrencyService().setTowerType(null);
if (!multipleTowerBuild) {
ServiceLocator.getCurrencyService().setTowerType(null);
}
return true;
} else {
// play a sound to indicate an invalid action
Expand Down

0 comments on commit 18a7a6f

Please sign in to comment.