Skip to content

Commit

Permalink
Revert "Implemented the wave timer pausing when the pause menu is ope…
Browse files Browse the repository at this point in the history
…ned. ISSUE: The wave timer entity isn't present in MainGameScreen, so it can't be passed to the pause menu at present. Fixing this is the next objective for this task."

This reverts commit e095797.
  • Loading branch information
AlasdairS4698737 committed Sep 28, 2023
1 parent e095797 commit c1b69da
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,11 @@ public class MainGamePauseDisplay extends UIComponent {
private static final Logger logger = LoggerFactory.getLogger(MainGamePauseDisplay.class);
private static final float Z_INDEX = 2f;
private Table table;

private GdxGame game;
private Entity waveSpawner;

public MainGamePauseDisplay(GdxGame screenSwitchHandle, Entity waveSpawner) {
public MainGamePauseDisplay(GdxGame screenSwitchHandle) {
game = screenSwitchHandle;
this.waveSpawner = waveSpawner;
}

@Override
Expand All @@ -46,7 +45,7 @@ private void addActors() {
@Override
public void changed(ChangeEvent changeEvent, Actor actor) {
logger.debug("Pause button clicked");
PauseMenuFactory.createPauseMenu(game, waveSpawner);
PauseMenuFactory.createPauseMenu(game);
}
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,14 @@
public class PauseMenuTimeStopComponent extends Component {

private Array<Entity> freezeList;
private Entity waveSpawner;

/**
* Initialises the component.
* @param waveSpawner The entity that controls the wave spawning timer.
*/
public PauseMenuTimeStopComponent(Entity waveSpawner) {
this.waveSpawner = waveSpawner;
public PauseMenuTimeStopComponent() {
}

/**
* Handles the pausing of the game entities when the pause menu is made.
*/
@Override
public void create() {
waveSpawner.getEvents().trigger("toggleWaveTimer");
freezeList = ServiceLocator.getEntityService().getEntities();
for (Entity pauseTarget : freezeList) {
if (pauseTarget.getId() != getEntity().getId()) {
Expand All @@ -41,7 +33,6 @@ public void create() {
*/
@Override
public void dispose() {
waveSpawner.getEvents().trigger("toggleWaveTimer");
for (Entity pauseTarget : freezeList) {
pauseTarget.setEnabled(true);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ public class SpawnWaveTask extends DefaultTask implements PriorityTask {
private final GameTime globalTime;
private long endTime = 0;
private final int SPAWNING_INTERVAL = 10;
private boolean wavesPaused = false;
private long pauseTime = 0;
public SpawnWaveTask() {
this.globalTime = ServiceLocator.getTimeSource();
}
Expand All @@ -27,30 +25,13 @@ public int getPriority() {
public void start() {
super.start();
endTime = globalTime.getTime() + (SPAWNING_INTERVAL * 1000);
this.owner.getEntity().getEvents().addListener("toggleWaveTimer", this::toggleWaveTimer);
}

@Override
public void update() {
if (!wavesPaused) {
if (globalTime.getTime() >= endTime) {
this.owner.getEntity().getEvents().trigger("spawnWave");
endTime = globalTime.getTime() + (SPAWNING_INTERVAL * 1000L); // reset end time
}
}
}

/**
* Function for pausing the wave timer when the pause menu is opened, and resuming it when the pause menu is closed.
*/
private void toggleWaveTimer() {
if (!wavesPaused) {
pauseTime = globalTime.getTime();
wavesPaused = true;
} else {
// Offsets the next wave spawn by however long the game was paused.
endTime += globalTime.getTime() - pauseTime;
wavesPaused = false;
if (globalTime.getTime() >= endTime) {
this.owner.getEntity().getEvents().trigger("spawnWave");
endTime = globalTime.getTime() + (SPAWNING_INTERVAL * 1000L); // reset end time
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,11 @@ public class PauseMenuFactory {

/**
* Creates the pause menu
* @param game The Gdx game instance that handles screen changes.
* @param waveSpawner The entity that handles the wave spawn timer
* @return entity
*/
public static Entity createPauseMenu(GdxGame game, Entity waveSpawner) {
public static Entity createPauseMenu(GdxGame game) {
Entity pauseMenu = new Entity()
.addComponent(new PauseMenuTimeStopComponent(waveSpawner))
.addComponent(new PauseMenuTimeStopComponent())
.addComponent(new PauseMenuRenderComponent())
.addComponent(new PauseMenuContinueButton())
.addComponent(new PauseMenuSettingsButton(game))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,10 +202,7 @@ private void createUI() {
.addComponent(new MainGameActions(this.game))
.addComponent(new MainGameExitDisplay())
.addComponent(new MainGameLoseDisplay())
// WHERE'S THE WAVE SPAWNER, HOW IS THIS GAME FUNCTIONING WHEN IT DOESN'T EVEN MAKE A WAVE SPAWNER
// I'm told there's a new entity for the SpawnWaveTask, maybe it'll actually be accessible in this class.
// fyi there REALLY shouldn't be a null arg, but I need to push this before I can fix the issue.
.addComponent(new MainGamePauseDisplay(this.game, null))
.addComponent(new MainGamePauseDisplay(this.game))
.addComponent(new Terminal())
.addComponent(inputComponent)
.addComponent(new TerminalDisplay());
Expand Down

0 comments on commit c1b69da

Please sign in to comment.