Skip to content

Commit

Permalink
Merge pull request #274 from UQcsse3200/team-2-ahmad
Browse files Browse the repository at this point in the history
Team 2 ahmad
  • Loading branch information
Mohamad11Dab authored Oct 16, 2023
2 parents afeb827 + 7b7af9e commit 845e5f8
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,6 @@ public void create() {

private void displayUI() {
Entity ui = new Entity();
// ui.addComponent(new GameAreaDisplay("Box Forest")); TODO: This should be the level name?
ui.addComponent(ServiceLocator.getGameEndService().getDisplay());
ui.addComponent(ServiceLocator.getCurrencyService().getDisplay());
spawnEntity(ui);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.csse3200.game.components.maingame;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input;
import com.badlogic.gdx.audio.Sound;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
Expand All @@ -12,7 +13,6 @@
import com.badlogic.gdx.utils.Array;
import com.csse3200.game.GdxGame;
import com.csse3200.game.entities.factories.PauseMenuFactory;
import com.csse3200.game.screens.MainGameScreen;
import com.csse3200.game.screens.TowerType;
import com.csse3200.game.services.ServiceLocator;
import com.csse3200.game.ui.ButtonFactory;
Expand All @@ -29,10 +29,18 @@ public class MainGameDisplay extends UIComponent {
private static final float Z_INDEX = 2f;
private final Table towerTable = new Table();
private final Table buttonTable = new Table();
private final Table progressTable = new Table();
private final Table levelNameTable = new Table();
private final String[] sounds = {
"sounds/ui/click/click_01.ogg",
"sounds/ui/open_close/open_01.ogg"
};
private String level;
private static final String[] levels = {
"Desert Planet",
"Ice Planet",
"Lava Planet"
};
private Sound click;
private Sound openSound;
private final GdxGame game;
Expand All @@ -43,13 +51,15 @@ public class MainGameDisplay extends UIComponent {
private ImageButton tower3;
private ImageButton tower4;
private ImageButton tower5;
private LevelProgressBar progressbar;

/**
* The constructor for the display
* @param screenSwitchHandle a handle back to the game entry point that manages screen switching
*/
public MainGameDisplay(GdxGame screenSwitchHandle) {
public MainGameDisplay(GdxGame screenSwitchHandle, int level) {
game = screenSwitchHandle;
this.level = levels[level];
}

/**
Expand All @@ -70,13 +80,19 @@ private void addActors() {
// Create and position the tables that will hold the buttons.

// Contains the tower build menu buttons
towerTable.top().padTop(80f);
towerTable.top().padTop(50f);
towerTable.setFillParent(true);

// Contains other buttons (just pause at this stage)
buttonTable.top().right().padTop(80f).padRight(80f);
buttonTable.top().right().padTop(50f).padRight(80f);
buttonTable.setFillParent(true);

progressTable.top().center().setWidth(500f);
progressTable.setFillParent(true);

levelNameTable.top().left().padLeft(20f).padTop(20f);
levelNameTable.setFillParent(true);

// Stores tower defaults, in case towers haven't been set in the tower select screen
TowerType[] defaultTowers = {
TowerType.TNT,
Expand Down Expand Up @@ -273,19 +289,35 @@ public void clicked(InputEvent event, float x, float y) {
TextTooltip tower5Tooltip = new TextTooltip(towers.get(4).getDescription(), getSkin());
tower5.addListener(tower5Tooltip);

progressbar = new LevelProgressBar(500, 10);

levelNameTable.setSkin(getSkin());
levelNameTable.add(this.level, "title");

// Scale all the tower build buttons down
// Add all buttons to their respective tables and position them
towerTable.setSkin(getSkin());
towerTable.add(tower1).padRight(10f);
towerTable.add(tower2).padRight(10f);
towerTable.add(tower3).padRight(10f);
towerTable.add(tower4).padRight(10f);
towerTable.add(tower5).padRight(10f);
towerTable.row();
towerTable.add("1", "small");
towerTable.add("2", "small");
towerTable.add("3", "small");
towerTable.add("4", "small");
towerTable.add("5", "small");
towerTable.row().colspan(5).pad(20f);
towerTable.add(progressbar).fillX();

buttonTable.add(pauseBtn);

// Add tables to the stage

stage.addActor(buttonTable);
stage.addActor(towerTable);
stage.addActor(levelNameTable);

TooltipManager tm = TooltipManager.getInstance();
tm.initialTime = 3;
Expand All @@ -298,6 +330,11 @@ public void draw(SpriteBatch batch) {
towerUpdate();
}

public void updateLevelProgressBar() {
float totalSecs = ((float) ServiceLocator.getTimeSource().getTime() / 1000);
progressbar.setValue(totalSecs);
}

/**
* Update function for the tower build menu buttons that is called with every draw, updates button states
* depending on button selection and currency balance
Expand All @@ -320,6 +357,7 @@ private void towerUpdate() {
for (int i = 0; i < towerButtons.size; i++) {
towerButtons.get(i).setDisabled(Integer.parseInt(towers.get(i).getPrice()) > balance);
}
updateLevelProgressBar();
}

/**
Expand All @@ -334,13 +372,11 @@ private void towerToggle(ImageButton towerButton) {
// set all buttons to off, disable if isDisabled
for (ImageButton button : towerButtons) {
button.setChecked(false);
// button.setDisabled(isDisabled);
}
} else {
// set the button corresponding to towerButton to on, all others to off
for (ImageButton button : towerButtons) {
button.setChecked(button == towerButton);
// button.setDisabled(isDisabled && button == towerButton);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.csse3200.game.components.maingame;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.actions.Actions;
Expand All @@ -23,7 +22,6 @@ public class UIElementsDisplay extends UIComponent {
private final Table buttonTable = new Table();
private TextButton remainingMobsButton;
private TextButton timerButton;
private LevelProgressBar progressbar;

@Override
public void create() {
Expand All @@ -38,7 +36,7 @@ private void addActors() {

remainingMobsButton = ButtonFactory.createButton("Mobs:"
+ ServiceLocator.getWaveService().getEnemyCount());
buttonTable.top().right().padTop(160f).padRight(80f);
buttonTable.top().right().padTop(130f).padRight(80f);

buttonTable.setFillParent(true);

Expand All @@ -48,18 +46,9 @@ private void addActors() {

stage.addActor(buttonTable);

progressbar = new LevelProgressBar(500, 10);
progressbar.setPosition(500, Gdx.graphics.getHeight() - 200);
// stage.addActor(progressbar); // will re-enable once positioned and working correctly

createTimerButton();
}

public void updateLevelProgressBar() {
float totalSecs = ((float) ServiceLocator.getTimeSource().getTime() / 1000);
progressbar.setValue(totalSecs);
}

/**
* This method updates the mob count button as mobs die in the game
*/
Expand Down Expand Up @@ -143,6 +132,5 @@ public float getZIndex() {
public void dispose() {
super.dispose();
buttonTable.clear();
progressbar.clear();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,6 @@ public void render(float delta) {

ServiceLocator.getWaveService().getDisplay().updateTimerButton();
ServiceLocator.getWaveService().getDisplay().updateMobCount();
ServiceLocator.getWaveService().getDisplay().updateLevelProgressBar();
renderer.render();

// Check if the game has ended
Expand Down Expand Up @@ -297,7 +296,7 @@ private void createUI() {
.addComponent(new MainGameActions(this.game))
.addComponent(ServiceLocator.getWaveService().getDisplay())
//.addComponent(new MainGameWinDisplay()) <- needs to be uncommented when team 3 have implemented the ui
.addComponent(new MainGameDisplay(this.game))
.addComponent(new MainGameDisplay(this.game, selectedLevel))
.addComponent(new Terminal())
.addComponent(buildHandler)
.addComponent(inputComponent)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@

/** Controls the game time */
public class GameTime {
private static Logger logger = LoggerFactory.getLogger(GameTime.class);
private static final Logger logger = LoggerFactory.getLogger(GameTime.class);
private final long startTime;
private float timeScale = 1f;

private boolean paused = false;

public GameTime() {
Expand Down

0 comments on commit 845e5f8

Please sign in to comment.