Pages

quinta-feira, 21 de agosto de 2014

GameHUD: Game Over



The "game over" is managed in a very simple way. When the time is up the player can no longer collect the statues and the texts "GAME OVER" and "Press Enter" are displayed on the screen.

The blueprint "GameHUD" has a boolean variable named "GameOver". The creation and initialization of this variable was shown in the article "GameHUD: Initializing the variables with a Macro".

The only condition that leads to the end of the game is when time equals zero. This test is performed in the "Clock" Event that was shown in the article "GameHUD: Timer and Custom Event". 

When the variable "GameOver" is true, the player can continue to move but he can not collect the statues, because one of the conditions tested at the time of the collision with the statue is that the variable "GameOver" can not be true, as was seen in the article "Statue: Graph Actions".

At the event "Receive Draw Hud" that was shown in the article "GameHUD: Drawing on the screen", you must add the actions that test if it is game over and that draw on the screen the text "GAME OVER" and "Press Enter". The full version of the event "Receive Draw Hud" became:

Click to enlarge

When the player presses the ENTER key, the variables of the game will be reset. However, by default the classes of type HUD does not recognize Input events such as key presses. We need to enable the Input passing the PlayerController as parameter. This is done at the "Begin Play" event of the GameHUD:


Now we can add the input event "Enter" that is triggered when the Enter key is pressed. His only action is to call the Macro StartGame that prepares the variables for a new game:


The last change we need to do to complete this simple game is in the blueprint "MyGame" that is created by the "TP_ThirdPersonBP" template of the editor. Open the blueprint "MyGame" in the "Defaults" mode and modify the "HUD Class" property. To do this click the combo box of the property and select the "GameHUD" option. Compile and save.



Ready. Now just press the "Play" button of the main editor to try the game. 

With this article we conclude the first part of this blog: "Introduction to Blueprints".


Next: Construction Script in Blueprints
Prev: Statue: Graph Actions
Table of Contents