Skip to content

Commit

Permalink
Implemented pausing the game in PauseMenuTimeStopComponent via disabl…
Browse files Browse the repository at this point in the history
…ing the entities on screen. Does not yet handle incoming waves.
  • Loading branch information
AlasdairS4698737 committed Sep 25, 2023
1 parent e0f2eb1 commit 29192a8
Showing 1 changed file with 20 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,22 +1,40 @@
package com.csse3200.game.components.pausemenu;

import com.csse3200.game.components.Component;
import com.csse3200.game.entities.Entity;
import com.badlogic.gdx.utils.Array;
import com.csse3200.game.services.ServiceLocator;

/**
* Handles the pausing/resuming of time when the pause menu is brought up/put away.
*/
public class PauseMenuTimeStopComponent extends Component {

private Array<Entity> freezeList;
public PauseMenuTimeStopComponent() {
}

/**
* Handles the pausing of the game entities when the pause menu is made.
*/
@Override
public void create() {
ServiceLocator.getTimeSource().setTimeScale(0f);
freezeList = ServiceLocator.getEntityService().getEntities();
for (Entity pauseTarget : freezeList) {
if (pauseTarget.getId() != getEntity().getId()) {
// ZA WARUDO! TOKI WO TOMARE!
pauseTarget.setEnabled(false);
}
}
}

/**
* Handles the un-pausing of the game entities when the pause menu is closed.
*/
@Override
public void dispose() {
ServiceLocator.getTimeSource().setTimeScale(1f);
for (Entity pauseTarget : freezeList) {
pauseTarget.setEnabled(true);
}
}
}

0 comments on commit 29192a8

Please sign in to comment.