add a win screen when the flag is reached
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
#include "goal/GoalReached.h"
|
||||
|
||||
#include "Event.h"
|
||||
|
||||
#include <Area2D.hpp>
|
||||
|
||||
void alai::GoalReached::_register_methods()
|
||||
@@ -22,7 +24,8 @@ void alai::GoalReached::_init()
|
||||
|
||||
void alai::GoalReached::_state_enter()
|
||||
{
|
||||
godot::Godot::print("Flag touched");
|
||||
auto event = get_node<alai::Event>("/root/Event");
|
||||
event->emit_signal("player_won");
|
||||
}
|
||||
|
||||
void alai::GoalReached::_state_exit()
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
#include "goal/GoalReached.h"
|
||||
#include "goal/GoalNotReached.h"
|
||||
#include "gui/game_over/GameOverScreen.h"
|
||||
#include "gui/game_won/GameWonScreen.h"
|
||||
|
||||
/**
|
||||
* @brief This function connects the gdnative init function.
|
||||
@@ -62,4 +63,5 @@ extern "C" void GDN_EXPORT godot_nativescript_init(void *handle)
|
||||
godot::register_class<alai::GoalReached>();
|
||||
godot::register_class<alai::GoalNotReached>();
|
||||
godot::register_class<alai::GameOverScreen>();
|
||||
godot::register_class<alai::GameWonScreen>();
|
||||
}
|
||||
|
||||
65
src/gui/game_won/GameWonScreen.cpp
Normal file
65
src/gui/game_won/GameWonScreen.cpp
Normal file
@@ -0,0 +1,65 @@
|
||||
#include "gui/game_won/GameWonScreen.h"
|
||||
#include "Event.h"
|
||||
|
||||
#include <SceneTree.hpp>
|
||||
#include <Viewport.hpp>
|
||||
|
||||
void alai::GameWonScreen::_register_methods()
|
||||
{
|
||||
godot::register_method("_ready", &GameWonScreen::_ready);
|
||||
godot::register_method("connect_signal", &GameWonScreen::connect_signal);
|
||||
godot::register_method("_on_player_won", &GameWonScreen::_on_player_won);
|
||||
godot::register_method("_on_quit_button_pressed", &GameWonScreen::_on_quit_button_pressed);
|
||||
}
|
||||
|
||||
alai::GameWonScreen::GameWonScreen()
|
||||
{
|
||||
}
|
||||
|
||||
alai::GameWonScreen::~GameWonScreen()
|
||||
{
|
||||
}
|
||||
|
||||
void alai::GameWonScreen::_init()
|
||||
{
|
||||
}
|
||||
|
||||
void alai::GameWonScreen::_ready()
|
||||
{
|
||||
connect_signal();
|
||||
}
|
||||
|
||||
void alai::GameWonScreen::_on_quit_button_pressed()
|
||||
{
|
||||
get_tree()->quit();
|
||||
}
|
||||
|
||||
void alai::GameWonScreen::_on_player_won()
|
||||
{
|
||||
auto event = get_node<alai::Event>("/root/Event");
|
||||
event->disconnect("player_won", this, "_on_player_won");
|
||||
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 alai::GameWonScreen::connect_signal()
|
||||
{
|
||||
auto event = get_node<alai::Event>("/root/Event");
|
||||
event->connect("player_won", this, "_on_player_won");
|
||||
}
|
||||
51
src/gui/game_won/GameWonScreen.h
Normal file
51
src/gui/game_won/GameWonScreen.h
Normal file
@@ -0,0 +1,51 @@
|
||||
#ifndef ALAI_GAME_WON_GAME_WON_SCREEN_H
|
||||
#define ALAI_GAME_WON_GAME_WON_SCREEN_H
|
||||
|
||||
#include <CanvasLayer.hpp>
|
||||
#include <Godot.hpp>
|
||||
|
||||
namespace alai
|
||||
{
|
||||
/**
|
||||
* @brief This class controls what happens when the game is won.
|
||||
*
|
||||
*/
|
||||
class GameWonScreen : public godot::CanvasLayer
|
||||
{
|
||||
GODOT_CLASS(GameWonScreen, godot::CanvasLayer)
|
||||
|
||||
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 GameWonScreen object.
|
||||
*
|
||||
*/
|
||||
GameWonScreen();
|
||||
|
||||
/**
|
||||
* @brief Destroy the GameWonScreen object.
|
||||
*
|
||||
*/
|
||||
~GameWonScreen();
|
||||
|
||||
/**
|
||||
* @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();
|
||||
|
||||
void _ready();
|
||||
void _on_player_won();
|
||||
void _on_quit_button_pressed();
|
||||
void connect_signal();
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user