-
Notifications
You must be signed in to change notification settings - Fork 1
Implementation Guide
This page explains how the countdown timer is implemented into the game screen.
The display of the countdown timer is to be added to the main game screen via the MainGameScreen's createUI() method, therefore, a component will be created to represent the countdown display.
A countdownDisplay.java file was created in the components file of src/main, where libGDX GUI elements are created and added to the stage.
The class takes in the current game as a constructor, and declares initial variables including setting the game time limit.
public countdownDisplay(GdxGame game) { super(); this.game = game; this.timeRemaining = 7260; //- (ServiceLocator.getTimeSource().getTime() / 1000); timeCount = 0; }
In the create() method, addActors() is called which creates a label to display the time remaining and added to the stage. The pause and resume buttons are also created and added to the stage.
` public Label counterLabel;
@Override
public void create() {
super.create();
addActors();
}
private void addActors() {
counterLabel = new Label(String.valueOf(timeRemaining), skin);
counterLabel.setPosition((float) (stage.getWidth() * 0.8), (float) (stage.getHeight() * 0.1));
counterLabel.setFontScale(2);
stage.addActor(counterLabel);
Table pauseBtn = pauseButton();
Table resumeBtn = resumeButton();
stage.addActor(pauseBtn);
stage.addActor(resumeBtn);
}
`
The basic countdown functionality is implemented in the update() method. This method is called each frame, and so to update the time, the time passed between two frames (getDeltaTime) is subtracted from the variable timeRemaining. The text on the label is also updated, to ensure the component displays the updated time remaining each frame.
` @Override public void update() { super.update(); timeCount = Gdx.graphics.getDeltaTime();
if (this.timeRemaining <= 0) {
counterLabel.setText("GAME OVER!");
}
if (timeRemaining>0 && stop==false) {
this.timeRemaining -= timeCount;
.
.
.
// sets the text of the label to the current time remaining.
counterLabel.setText(String.valueOf(equHours+":"+equMins+":"+equSeconds));
}
}
`
The countdown component as implemented in countdownDisplay.java is added to the main game screen via the createUI() method in MainGameScreen.java.
` /**
- Creates the main game's ui including components for rendering ui elements to the screen and
- capturing and handling ui input. */ private void createUI() { logger.debug("Creating ui"); Stage stage = ServiceLocator.getRenderService().getStage(); InputComponent inputComponent = ServiceLocator.getInputService().getInputFactory().createForTerminal();
this.timeSinceStart = ServiceLocator.getTimeSource().getTime();
logger.info("time passed since game started: {}", this.timeSinceStart);
Entity ui = new Entity();
ui.addComponent(new InputDecorator(stage, 10))
.addComponent(new PerformanceDisplay())
.addComponent(new MainGameActions(this.game))
.addComponent(new MainGameExitDisplay())
.addComponent(new countdownDisplay(this.game))
.addComponent(new Terminal())
.addComponent(inputComponent)
.addComponent(new TerminalDisplay());
ServiceLocator.getEntityService().register(ui);
} `
- Pause When the player clicks on the pause button on the main game screen, a pop-up window titled "PAUSE" is displayed to the player. At the same time, the music and movement of the elements on the screen stop as well.
Creation of the paused button, and adding event listener on click which creates paused pop-up window (countdownDisplay.java):
Changing the status of the game to paused, which will stop the game and music (MainGameScreen.java):
A new instance of the PausedWindow.java class is created (the current game as the parameter) on click of the paused button on the main game screen, and the create() method is called to create the UI elements in addActors().
- Resume The resume button is displayed in the paused pop-up window. When this button is clicked, the implementation simply does the opposite to what was done in the implementation of pausing the game.
Creation of the resume button in the paused pop-up window (PausedWindow.java in addActors()):
Resuming the game:
- Restart The restart button is accessed from the paused pop-up window just like the resume button. When the player clicks this button, the main game screen is reloaded, making the game restart.
PausedWindow.java
When the countdown timer runs out, the timeRemaining is less than or equal to zero. In the countdownDisplay class, this condition is checked for in the update method, and when true, the game will be over as in the player has ran out of time and lost. Initially we had tried to setLose() (Team 3's method) and trigger "ending" event (Also Team 3's event) within this update method, however this caused a run time exception, so we had moved it to MainGameScreen.java where we created the method setterForCountDown().
countdownDisplay.java update() method checking timeRemaining is less than or equal to zero:
MainGameScreen.java --> timeTime variable is created where false means there is no more time remaining. Initially this is set to true, and is toggled to false when setterForCountDown() is called:
MainGameScreen.java --> when the timeTime variable is false (i.e. no more time remaining therefore game over), Team 3's setLose() method is used, and the screen type is set to ENDING to display the appropriate ending screen created by Team 3:
- Uniform Pixel Grid Resolution
- Storyline
- Instruction
- NPC info
- NPC Communication Script
- Inventory-System-and-Consumables
- Storyline User Test
- Traitor Clues
- Game Characters
- Player Profile User Test
- Player Eviction Menu Sprint1: User survey (Team 7)
- Player Eviction Menu Sprint2: User survey (Team 7)
- Sprint3 - Win/lose Condition: User survey (Team 7)
- Sprint4 - Polishing-tasks: User survey (Team 7)
- Transition Animation/Special Effects/Sound Effects: Feature Overviews
- Transition Animation and Effects: Design Process & Guideline
- Sprint 4 User Testing
- Transition Animation & Effect: Code Guideline-Sprint4
- Sound effect when players complete npc tasks and hover over npc cards
- Fixing the clue bug
- Music Test
- Player Eviction Menu: Design Process & Guideline
- Player Eviction Menu (Feature Overviews)
- Player Eviction Menu: Code Guideline - Sprint1
- Sprint 1 User Testing
- Detailed Eviction Card: Design Process & Guideline
- Detailed Eviction Card: Feature Overviews
- Sprint 2 User Testing
- Player Eviction Menu: Code Guideline - Sprint2
- Sprint 2 Inventory System and Consumables Items User Testing
- Sprint 2 Inventory System and Consumables Items Functionality
- NPC interaction testing plan sprint3
- NPC interaction testing results sprint3
- NPC Dialogue Scripts
- Code Guideline
- Win/lose Condition: Design Process & Guideline
- Win/lose Condition: Feature Overviews
- Sprint 3 User Testing
- Win/lose condition: Code Guideline - Sprint3
- Enemy List
- User Testing 1: Enemy Image Filter
- User Testing 2: Enemy Animation and AI
- User Testing 3: Basic Attack