From a27f96829771f581663652fb702f1d90cf84a1e9 Mon Sep 17 00:00:00 2001 From: Martin Araneda Date: Sat, 27 Aug 2022 18:14:21 -0400 Subject: [PATCH] add gameover --- godot/Main.tscn | 6 +- src/gui/game_over/GameOverScreen.cpp | 23 ++++++-- src/gui/game_over/GameOverScreen.h | 88 +++++++++++++++------------- 3 files changed, 70 insertions(+), 47 deletions(-) diff --git a/godot/Main.tscn b/godot/Main.tscn index d288642..5babece 100644 --- a/godot/Main.tscn +++ b/godot/Main.tscn @@ -1,7 +1,8 @@ -[gd_scene load_steps=3 format=2] +[gd_scene load_steps=4 format=2] [ext_resource path="res://Main.gdns" type="Script" id=1] [ext_resource path="res://levels/Prototype.tscn" type="PackedScene" id=2] +[ext_resource path="res://GUI/GameOver.tscn" type="PackedScene" id=3] [node name="Main" type="Node"] pause_mode = 2 @@ -10,3 +11,6 @@ level = ExtResource( 2 ) [node name="Level" type="Node" parent="."] pause_mode = 1 + +[node name="GameOver" parent="." instance=ExtResource( 3 )] +visible = false diff --git a/src/gui/game_over/GameOverScreen.cpp b/src/gui/game_over/GameOverScreen.cpp index 66bc484..e497503 100644 --- a/src/gui/game_over/GameOverScreen.cpp +++ b/src/gui/game_over/GameOverScreen.cpp @@ -1,12 +1,16 @@ #include "gui/game_over/GameOverScreen.h" +#include +#include #include #include +#include +#include using namespace godot; void GameOverScreen::_register_methods() -{ - register_method("_on_restart_button_pressed", &GameOverScreen::_on_restart_button_pressed); +{ + register_method("_on_animation_finished", &GameOverScreen::_on_botonreiniciar_pressed); } GameOverScreen::GameOverScreen() @@ -19,9 +23,20 @@ GameOverScreen::~GameOverScreen() void GameOverScreen::_init() { + _resource_loader = ResourceLoader::get_singleton(); } -void GameOverScreen::_on_restart_button_pressed() + +void GameOverScreen::_on_botonreiniciar_pressed() { - get_tree()->change_scene("res://monitor/GUI.tscn"); + + if (_resource_loader->exists("res://levels/Prototype.tscn")) //CAMBIAR A DINAMICO + { + Ref level_scene = _resource_loader->load("res://levels/Prototype.tscn"); + auto level = level_scene->instance(); + auto level_node = get_tree()->get_root()->find_node("Level"); + level_node->add_child(level); + } } + + diff --git a/src/gui/game_over/GameOverScreen.h b/src/gui/game_over/GameOverScreen.h index 1a40b2e..a03a2b2 100644 --- a/src/gui/game_over/GameOverScreen.h +++ b/src/gui/game_over/GameOverScreen.h @@ -1,56 +1,60 @@ -#ifndef ALAI_GAME_OVER_SCREEN -#define ALAI_GAME_OVER_SCREEN - +#ifndef ALAI_GAME_OVER_SCREEN_H +#define ALAI_GAME_OVER_SCREEN_H #include -#include #include +#include + namespace godot { - /** - * @brief This class controls what happens when the Coin is in the collected . - * - */ - class GameOverScreen : public Control - { - GODOT_CLASS(GameOverScreen, Control) + /** + * @brief This class controls what happens when the Coin is in the collected . + * + */ + class GameOverScreen : public Control + { + GODOT_CLASS(GameOverScreen, Control) - private: + private: + ResourceLoader *_resource_loader; + + public: + /** + * @brief This method registers classes with Godot. + * + * @details This method registers methods, properties, and signals with the Godot engine. + */ + static void _register_methods(); - public: - /** - * @brief This method registers classes with Godot. - * - * @details This method registers methods, properties, and signals with the Godot engine. - */ - static void _register_methods(); + /** + * @brief Construct a new GameOverScreen object. + * + */ + GameOverScreen(); - /** - * @brief Construct a new GameOverScreen object. - * - */ - GameOverScreen(); + /** + * @brief Destroy the GameOverScreen object. + * + */ + ~GameOverScreen(); - /** - * @brief Destroy the GameOverScreen object. - * - */ - ~GameOverScreen(); + /** + * @brief Initialize the class from Godot. + * + * @details This method is called just once when the Godot engine connects to the instance of the class. + */ + void _init(); - /** - * @brief Initialize the class from Godot. - * - * @details This method is called just once when the Godot engine connects to the instance of the class. - */ - void _init(); + /** + * @brief Called when the collected of the coin is entered. + * + */ + void _on_botonreiniciar_pressed(); - /** - * @brief Called when the collected of the coin is entered. - * - */ - void _on_restart_button_pressed(); - }; + + }; + } -#endif +#endif \ No newline at end of file