Game over screen finished

This commit is contained in:
Martin Araneda 2022-08-27 22:34:18 -04:00
parent 705ed4e897
commit 3bcbde8161
6 changed files with 84 additions and 21 deletions

View File

@ -14,18 +14,20 @@ font_data = ExtResource( 2 )
[sub_resource type="StyleBoxFlat" id=3]
bg_color = Color( 0.0705882, 0.917647, 0, 1 )
[node name="GameOver" type="Control"]
anchor_right = 1.0
anchor_bottom = 1.0
[node name="GameOver" type="CanvasLayer"]
script = ExtResource( 3 )
[node name="ColorRect" type="ColorRect" parent="."]
[node name="Control" type="Control" parent="."]
margin_right = 40.0
margin_bottom = 40.0
[node name="ColorRect" type="ColorRect" parent="Control"]
margin_right = 512.0
margin_bottom = 288.0
rect_min_size = Vector2( 512, 288 )
rect_rotation = -0.338293
color = Color( 0, 0, 0, 1 )
[node name="Label" type="Label" parent="."]
[node name="Label" type="Label" parent="Control"]
margin_left = 66.0
margin_top = 17.0
margin_right = 456.0
@ -34,7 +36,7 @@ custom_fonts/font = SubResource( 1 )
text = "GAME OVER"
align = 1
[node name="botonreiniciar" type="Button" parent="."]
[node name="botonreiniciar" type="Button" parent="Control"]
margin_left = 194.0
margin_top = 150.0
margin_right = 338.0
@ -42,6 +44,5 @@ margin_bottom = 180.0
custom_fonts/font = SubResource( 2 )
custom_styles/hover = SubResource( 3 )
text = "REINICIAR"
script = ExtResource( 3 )
[connection signal="pressed" from="botonreiniciar" to="botonreiniciar" method="_on_botonreiniciar_pressed"]
[connection signal="pressed" from="Control/botonreiniciar" to="." method="_on_botonreiniciar_pressed"]

View File

@ -53,7 +53,7 @@ func _ready() -> void:
Event.connect("object_created", self, "_object_created")
Event.connect("object_updated", self, "_object_updated")
Event.connect("object_removed", self, "_object_removed")
Event.connect("coin_collected", self, "_on_coin_update")
game_version = get_parent().game_version
player["rut"] = ""

View File

@ -15,6 +15,7 @@
#include "coin/CoinCounter.h"
#include "goal/GoalReached.h"
#include "goal/GoalNotReached.h"
#include "gui/game_over/GameOverScreen.h"
using namespace godot;
@ -61,4 +62,5 @@ extern "C" void GDN_EXPORT godot_nativescript_init(void *handle)
register_class<CoinCounter>();
register_class<GoalReached>();
register_class<GoalNotReached>();
register_class<GameOverScreen>();
}

View File

@ -1,4 +1,6 @@
#include "gui/game_over/GameOverScreen.h"
#include "Event.h"
#include <Resource.hpp>
#include <Ref.hpp>
#include <Node.hpp>
@ -6,11 +8,15 @@
#include <PackedScene.hpp>
#include <Viewport.hpp>
using namespace godot;
void GameOverScreen::_register_methods()
{
register_method("_on_animation_finished", &GameOverScreen::_on_botonreiniciar_pressed);
register_method("_on_botonreiniciar_pressed", &GameOverScreen::_on_botonreiniciar_pressed);
register_method("_ready", &GameOverScreen::_ready);
register_method("connect_signal", &GameOverScreen::connect_signal);
register_method("_on_player_died", &GameOverScreen::_on_player_died);
}
GameOverScreen::GameOverScreen()
@ -27,16 +33,66 @@ void GameOverScreen::_init()
}
void GameOverScreen::_ready()
{
connect_signal();
}
void GameOverScreen::_on_botonreiniciar_pressed()
{
if (_resource_loader->exists("res://levels/Prototype.tscn")) //CAMBIAR A DINAMICO
{
Ref<PackedScene> 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);
auto level_node = get_tree()->get_root()->get_node("Main")->find_node("Level");
if (level_node != nullptr)
{
level_node->add_child(level);
set_visible(false);
call_deferred("connect_signal");
}
else
{
WARN_PRINT("Node level not found!");
}
}
}
void GameOverScreen::_on_player_died() //eliminar nivel
{
auto event = get_node<alai::Event>("/root/Event");
event->disconnect("player_died", this, "_on_player_died");
Godot::print("player ded");
set_visible(true);
auto level_node = get_tree()->get_root()->get_node("Main")->find_node("Level");
if (level_node != nullptr)
{
auto child = level_node->get_child(0);
if (child != nullptr)
{
child->queue_free();
}
else
{
WARN_PRINT("Child not found!");
}
}
else
{
WARN_PRINT("Node level not found!");
}
}
void GameOverScreen::connect_signal()
{
auto event = get_node<alai::Event>("/root/Event");
event->connect("player_died", this, "_on_player_died");
}

View File

@ -2,7 +2,7 @@
#define ALAI_GAME_OVER_SCREEN_H
#include <Godot.hpp>
#include <Control.hpp>
#include <CanvasLayer.hpp>
#include <ResourceLoader.hpp>
@ -12,9 +12,9 @@ namespace godot
* @brief This class controls what happens when the Coin is in the collected .
*
*/
class GameOverScreen : public Control
class GameOverScreen : public CanvasLayer
{
GODOT_CLASS(GameOverScreen, Control)
GODOT_CLASS(GameOverScreen, CanvasLayer)
private:
ResourceLoader *_resource_loader;
@ -50,8 +50,10 @@ namespace godot
* @brief Called when the collected of the coin is entered.
*
*/
void _ready();
void _on_player_died();
void _on_botonreiniciar_pressed();
void connect_signal();
};

View File

@ -52,7 +52,7 @@ void Player::_init()
set_double_jump(player::double_jump);
coins = 0;
velocity = Vector2();
}
@ -166,14 +166,16 @@ void Player::_physics_process(float delta)
{
if (!notifier->is_on_screen())
{
if (get_parent()->get_class() == "TileMap")
auto event = get_node<alai::Event>("/root/Event");
event->emit_signal("player_died");
/*if (get_parent()->get_class() == "TileMap")
{
auto error = get_tree()->change_scene("res://Main.tscn");
if (error != Error::OK)
{
ERR_PRINT(String().num((int) error) + " Could not load scene!");
}
}
}*/
}
}