develop #34
@ -6,7 +6,6 @@
|
|||||||
[node name="Monitor" type="Node"]
|
[node name="Monitor" type="Node"]
|
||||||
pause_mode = 2
|
pause_mode = 2
|
||||||
script = ExtResource( 1 )
|
script = ExtResource( 1 )
|
||||||
monitor_enabled = true
|
|
||||||
|
|
||||||
[node name="MonitorGUI" parent="." instance=ExtResource( 3 )]
|
[node name="MonitorGUI" parent="." instance=ExtResource( 3 )]
|
||||||
visible = false
|
visible = false
|
||||||
|
@ -1,40 +1,37 @@
|
|||||||
#include "CameraLimit.h"
|
#include "CameraLimit.h"
|
||||||
|
|
||||||
|
#include <Camera2D.hpp>
|
||||||
#include <SceneTree.hpp>
|
#include <SceneTree.hpp>
|
||||||
#include <TileMap.hpp>
|
#include <TileMap.hpp>
|
||||||
#include <Camera2D.hpp>
|
|
||||||
#include <Viewport.hpp>
|
#include <Viewport.hpp>
|
||||||
#include <Node.hpp>
|
|
||||||
|
|
||||||
using namespace godot;
|
void alai::CameraLimit::_register_methods()
|
||||||
|
|
||||||
void CameraLimit::_register_methods()
|
|
||||||
{
|
{
|
||||||
register_method("_ready", &CameraLimit::_ready);
|
register_method("_ready", &CameraLimit::_ready);
|
||||||
}
|
}
|
||||||
|
|
||||||
CameraLimit::CameraLimit()
|
alai::CameraLimit::CameraLimit()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
CameraLimit::~CameraLimit()
|
alai::CameraLimit::~CameraLimit()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void CameraLimit::_init()
|
void alai::CameraLimit::_init()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void CameraLimit::_ready()
|
void alai::CameraLimit::_ready()
|
||||||
{
|
{
|
||||||
auto node = find_node("Middleground");
|
auto node = find_node("Middleground");
|
||||||
auto middle_ground = cast_to<TileMap>(node);
|
auto middle_ground = cast_to<godot::TileMap>(node);
|
||||||
if (middle_ground != NULL)
|
if (middle_ground != NULL)
|
||||||
{
|
{
|
||||||
auto used_rect = middle_ground->get_used_rect();
|
auto used_rect = middle_ground->get_used_rect();
|
||||||
auto bounds = Vector2(used_rect.position.x + used_rect.size.x, used_rect.position.y + used_rect.size.y);
|
auto bounds = godot::Vector2(used_rect.position.x + used_rect.size.x, used_rect.position.y + used_rect.size.y);
|
||||||
node = get_tree()->get_root()->find_node("Camera2D", true, false);
|
node = get_tree()->get_root()->find_node("Camera2D", true, false);
|
||||||
auto camera = cast_to<Camera2D>(node);
|
auto camera = cast_to<godot::Camera2D>(node);
|
||||||
if (camera != NULL)
|
if (camera != NULL)
|
||||||
{
|
{
|
||||||
camera->set_limit(2, bounds.x * middle_ground->get_cell_size().x);
|
camera->set_limit(2, bounds.x * middle_ground->get_cell_size().x);
|
||||||
|
@ -4,16 +4,16 @@
|
|||||||
#include <Godot.hpp>
|
#include <Godot.hpp>
|
||||||
#include <Node2D.hpp>
|
#include <Node2D.hpp>
|
||||||
|
|
||||||
namespace godot
|
namespace alai
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @brief This class limits the camera's position.
|
* @brief This class limits the camera's position.
|
||||||
*
|
*
|
||||||
* @details The camera will be limited based on the used width and height of the Middleground tilemap.
|
* @details The camera will be limited based on the used width and height of the Middleground tilemap.
|
||||||
*/
|
*/
|
||||||
class CameraLimit: public Node2D
|
class CameraLimit: public godot::Node2D
|
||||||
{
|
{
|
||||||
GODOT_CLASS(CameraLimit, Node2D)
|
GODOT_CLASS(CameraLimit, godot::Node2D)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
|
85
src/Main.cpp
85
src/Main.cpp
@ -2,50 +2,47 @@
|
|||||||
|
|
||||||
#include <SceneTree.hpp>
|
#include <SceneTree.hpp>
|
||||||
|
|
||||||
using namespace godot;
|
void alai::Main::_register_methods()
|
||||||
using namespace main;
|
|
||||||
|
|
||||||
void Main::_register_methods()
|
|
||||||
{
|
{
|
||||||
register_method("_ready", &Main::_ready);
|
godot::register_method("_ready", &Main::_ready);
|
||||||
register_method("_physics_process", &Main::_physics_process);
|
godot::register_method("_physics_process", &Main::_physics_process);
|
||||||
register_method("_on_monitor_loaded", &Main::_on_monitor_loaded);
|
godot::register_method("_on_monitor_loaded", &Main::_on_monitor_loaded);
|
||||||
register_property<Main, String>("game_version", &Main::set_game_version, &Main::get_game_version, String(main::game_version.c_str()));
|
godot::register_property<Main, godot::String>("game_version", &Main::set_game_version, &Main::get_game_version, godot::String(default_game_version.c_str()));
|
||||||
register_property<Main, Ref<PackedScene>>("level", &Main::set_level, &Main::get_level, NULL, GODOT_METHOD_RPC_MODE_DISABLED, GODOT_PROPERTY_USAGE_DEFAULT, GODOT_PROPERTY_HINT_RESOURCE_TYPE, String("PackedScene"));
|
godot::register_property<Main, godot::Ref<godot::PackedScene>>("level", &Main::set_level, &Main::get_level, godot::Ref<godot::PackedScene>(nullptr), GODOT_METHOD_RPC_MODE_DISABLED, GODOT_PROPERTY_USAGE_DEFAULT, GODOT_PROPERTY_HINT_RESOURCE_TYPE, "PackedScene");
|
||||||
register_property<Main, bool>("full_screen", &Main::set_full_screen, &Main::get_full_screen, main::full_screen);
|
godot::register_property<Main, bool>("full_screen", &Main::set_full_screen, &Main::get_full_screen, default_full_screen);
|
||||||
register_property<Main, Vector2>("window_size", &Main::set_window_size, &Main::get_window_size, main::window_size);
|
godot::register_property<Main, godot::Vector2>("window_size", &Main::set_window_size, &Main::get_window_size, default_window_size);
|
||||||
register_property<Main, int8_t>("launch_screen", &Main::set_launch_screen, &Main::get_launch_screen, main::launch_screen);
|
godot::register_property<Main, int8_t>("launch_screen", &Main::set_launch_screen, &Main::get_launch_screen, default_launch_screen);
|
||||||
register_signal<Main>("monitor_loaded");
|
godot::register_signal<Main>("monitor_loaded");
|
||||||
}
|
}
|
||||||
|
|
||||||
Main::Main()
|
alai::Main::Main()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
Main::~Main()
|
alai::Main::~Main()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void Main::_init()
|
void alai::Main::_init()
|
||||||
{
|
{
|
||||||
_os = OS::get_singleton();
|
_os = godot::OS::get_singleton();
|
||||||
_input = Input::get_singleton();
|
_input = godot::Input::get_singleton();
|
||||||
_project_settings = ProjectSettings::get_singleton();
|
_project_settings = godot::ProjectSettings::get_singleton();
|
||||||
_resource_loader = ResourceLoader::get_singleton();
|
_resource_loader = godot::ResourceLoader::get_singleton();
|
||||||
|
|
||||||
game_version = String(main::game_version.c_str());
|
set_game_version(godot::String(default_game_version.c_str()));
|
||||||
full_screen = main::full_screen;
|
set_full_screen(default_full_screen);
|
||||||
window_size = main::window_size;
|
set_window_size(default_window_size);
|
||||||
launch_screen = main::launch_screen;
|
set_launch_screen(default_launch_screen);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Main::_ready()
|
void alai::Main::_ready()
|
||||||
{
|
{
|
||||||
auto success = _project_settings->load_resource_pack("monitor.pck");
|
auto success = _project_settings->load_resource_pack("monitor.pck");
|
||||||
if (success)
|
if (success)
|
||||||
{
|
{
|
||||||
// Load monitor from pck
|
// Load monitor from pck
|
||||||
Godot::print("Monitor pck found, loading...");
|
godot::Godot::print("Monitor pck found, loading...");
|
||||||
load_monitor();
|
load_monitor();
|
||||||
}
|
}
|
||||||
else if (_resource_loader->exists("res://monitor/Monitor.tscn"))
|
else if (_resource_loader->exists("res://monitor/Monitor.tscn"))
|
||||||
@ -75,19 +72,19 @@ void Main::_ready()
|
|||||||
if (success)
|
if (success)
|
||||||
{
|
{
|
||||||
// Load crt from pck
|
// Load crt from pck
|
||||||
Godot::print("CRT pck found, loading...");
|
godot::Godot::print("CRT pck found, loading...");
|
||||||
Ref<PackedScene> crt_scene = _resource_loader->load("res://shaders/crt/crt.tscn");
|
godot::Ref<godot::PackedScene> crt_scene = _resource_loader->load("res://shaders/crt/crt.tscn");
|
||||||
add_child(crt_scene->instance());
|
add_child(crt_scene->instance());
|
||||||
}
|
}
|
||||||
else if (_resource_loader->exists("res://shaders/crt/crt.tscn"))
|
else if (_resource_loader->exists("res://shaders/crt/crt.tscn"))
|
||||||
{
|
{
|
||||||
// Load crt from alai's pck
|
// Load crt from alai's pck
|
||||||
Ref<PackedScene> crt_scene = _resource_loader->load("res://shaders/crt/crt.tscn");
|
godot::Ref<godot::PackedScene> crt_scene = _resource_loader->load("res://shaders/crt/crt.tscn");
|
||||||
add_child(crt_scene->instance());
|
add_child(crt_scene->instance());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Main::_on_monitor_loaded()
|
void alai::Main::_on_monitor_loaded()
|
||||||
{
|
{
|
||||||
if (level != nullptr)
|
if (level != nullptr)
|
||||||
{
|
{
|
||||||
@ -97,16 +94,16 @@ void Main::_on_monitor_loaded()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Main::load_monitor()
|
void alai::Main::load_monitor()
|
||||||
{
|
{
|
||||||
Ref<PackedScene> monitor_scene = _resource_loader->load("res://monitor/Monitor.tscn");
|
godot::Ref<godot::PackedScene> monitor_scene = _resource_loader->load("res://monitor/Monitor.tscn");
|
||||||
add_child(monitor_scene->instance());
|
add_child(monitor_scene->instance());
|
||||||
auto monitor = get_node("Monitor");
|
auto monitor = get_node("Monitor");
|
||||||
monitor->connect("monitor_loaded", this, "_on_monitor_loaded");
|
monitor->connect("monitor_loaded", this, "_on_monitor_loaded");
|
||||||
get_tree()->set_pause(true);
|
get_tree()->set_pause(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
Node *Main::load_level()
|
godot::Node *alai::Main::load_level()
|
||||||
{
|
{
|
||||||
if (level != nullptr)
|
if (level != nullptr)
|
||||||
{
|
{
|
||||||
@ -119,7 +116,7 @@ Node *Main::load_level()
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Main::_physics_process(float delta)
|
void alai::Main::_physics_process(float delta)
|
||||||
{
|
{
|
||||||
if (_input->is_action_just_pressed("ui_cancel"))
|
if (_input->is_action_just_pressed("ui_cancel"))
|
||||||
{
|
{
|
||||||
@ -127,52 +124,52 @@ void Main::_physics_process(float delta)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Main::set_level(Ref<PackedScene> level)
|
void alai::Main::set_level(godot::Ref<godot::PackedScene> level)
|
||||||
{
|
{
|
||||||
this->level = level;
|
this->level = level;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ref<PackedScene> Main::get_level()
|
godot::Ref<godot::PackedScene> alai::Main::get_level()
|
||||||
{
|
{
|
||||||
return this->level;
|
return this->level;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Main::set_game_version(String game_version)
|
void alai::Main::set_game_version(godot::String game_version)
|
||||||
{
|
{
|
||||||
this->game_version = game_version;
|
this->game_version = game_version;
|
||||||
}
|
}
|
||||||
|
|
||||||
String Main::get_game_version()
|
godot::String alai::Main::get_game_version()
|
||||||
{
|
{
|
||||||
return this->game_version;
|
return this->game_version;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Main::set_full_screen(bool full_screen)
|
void alai::Main::set_full_screen(bool full_screen)
|
||||||
{
|
{
|
||||||
this->full_screen = full_screen;
|
this->full_screen = full_screen;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Main::get_full_screen()
|
bool alai::Main::get_full_screen()
|
||||||
{
|
{
|
||||||
return this->full_screen;
|
return this->full_screen;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Main::set_window_size(Vector2 window_size)
|
void alai::Main::set_window_size(godot::Vector2 window_size)
|
||||||
{
|
{
|
||||||
this-> window_size = window_size;
|
this-> window_size = window_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector2 Main::get_window_size()
|
godot::Vector2 alai::Main::get_window_size()
|
||||||
{
|
{
|
||||||
return this->window_size;
|
return this->window_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Main::set_launch_screen(int8_t launch_screen)
|
void alai::Main::set_launch_screen(int8_t launch_screen)
|
||||||
{
|
{
|
||||||
this->launch_screen = launch_screen;
|
this->launch_screen = launch_screen;
|
||||||
}
|
}
|
||||||
|
|
||||||
int8_t Main::get_launch_screen()
|
int8_t alai::Main::get_launch_screen()
|
||||||
{
|
{
|
||||||
if (this->launch_screen == -1)
|
if (this->launch_screen == -1)
|
||||||
{
|
{
|
||||||
|
105
src/Main.h
105
src/Main.h
@ -3,90 +3,82 @@
|
|||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <Godot.hpp>
|
#include <Godot.hpp>
|
||||||
|
#include <Input.hpp>
|
||||||
#include <Node.hpp>
|
#include <Node.hpp>
|
||||||
#include <OS.hpp>
|
#include <OS.hpp>
|
||||||
#include <Input.hpp>
|
|
||||||
#include <PackedScene.hpp>
|
#include <PackedScene.hpp>
|
||||||
#include <Ref.hpp>
|
|
||||||
#include <ProjectSettings.hpp>
|
#include <ProjectSettings.hpp>
|
||||||
|
#include <Ref.hpp>
|
||||||
#include <ResourceLoader.hpp>
|
#include <ResourceLoader.hpp>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief This is the godot namespace for all the code included in the library.
|
* @brief This is the alai namespace for all the code included in the game.
|
||||||
*
|
*
|
||||||
* @details This namespace is used a prefix when the Godot engine looks for classes, methods, and properties.
|
* @details This namespace is used a prefix when the Godot engine looks for classes, methods, and properties.
|
||||||
*/
|
*/
|
||||||
namespace godot
|
namespace alai
|
||||||
{
|
{
|
||||||
/**
|
|
||||||
* @brief This namespace houses some global variables and the main class.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
namespace main
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* @brief The default value for the game version.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
const std::string game_version = "0.1.0";
|
|
||||||
/**
|
|
||||||
* @brief The default value for if the game should start in full screen.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
const bool full_screen = false;
|
|
||||||
/**
|
|
||||||
* @brief The default resolution for the game window.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
const Vector2 window_size = Vector2(1280, 720);
|
|
||||||
/**
|
|
||||||
* @brief The default screen the the game should open on.
|
|
||||||
*
|
|
||||||
* @details -1 opens it on the currently active screen. And 0 and above are the screens to use.
|
|
||||||
*/
|
|
||||||
const int8_t launch_screen = -1;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief This class controls the Main node.
|
* @brief This class controls the Main node.
|
||||||
*
|
*
|
||||||
* @details The main node is responsible for controling the window and the game iteself is a child of it.
|
* @details The main node is responsible for controlling the window and the game itself is a child of it.
|
||||||
*/
|
*/
|
||||||
class Main : public Node
|
class Main : public godot::Node
|
||||||
{
|
{
|
||||||
GODOT_CLASS(Main, Node)
|
GODOT_CLASS(Main, godot::Node)
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/**
|
/**
|
||||||
* @brief OS singleton.
|
* @brief OS singleton.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
OS *_os;
|
godot::OS *_os;
|
||||||
/**
|
/**
|
||||||
* @brief Input singleton.
|
* @brief Input singleton.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
Input *_input;
|
godot::Input *_input;
|
||||||
/**
|
/**
|
||||||
* @brief ProjectSettings singleton.
|
* @brief ProjectSettings singleton.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
ProjectSettings *_project_settings;
|
godot::ProjectSettings *_project_settings;
|
||||||
/**
|
/**
|
||||||
* @brief ResourceLoader singleton.
|
* @brief ResourceLoader singleton.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
ResourceLoader *_resource_loader;
|
godot::ResourceLoader *_resource_loader;
|
||||||
|
/**
|
||||||
|
* @brief The default value for the game version.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
inline static const std::string default_game_version = "0.1.0";
|
||||||
|
/**
|
||||||
|
* @brief The default value for if the game should start in full screen.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
inline static const bool default_full_screen = false;
|
||||||
|
/**
|
||||||
|
* @brief The default resolution for the game window.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
inline static const godot::Vector2 default_window_size = godot::Vector2(1280, 720);
|
||||||
|
/**
|
||||||
|
* @brief The default screen the the game should open on.
|
||||||
|
*
|
||||||
|
* @details -1 opens it on the currently active screen. And 0 and above are the screens to use.
|
||||||
|
*/
|
||||||
|
inline static const int8_t default_launch_screen = -1;
|
||||||
/**
|
/**
|
||||||
* @brief The first level to load
|
* @brief The first level to load
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
Ref<PackedScene> level;
|
godot::Ref<godot::PackedScene> level;
|
||||||
/**
|
/**
|
||||||
* @brief The current version of the game.
|
* @brief The current version of the game.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
String game_version;
|
godot::String game_version;
|
||||||
/**
|
/**
|
||||||
* @brief If the window is full screen or not.
|
* @brief If the window is full screen or not.
|
||||||
*
|
*
|
||||||
@ -96,7 +88,7 @@ namespace godot
|
|||||||
* @brief The size of the window.
|
* @brief The size of the window.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
Vector2 window_size;
|
godot::Vector2 window_size;
|
||||||
/**
|
/**
|
||||||
* @brief The screen to launch the game on.
|
* @brief The screen to launch the game on.
|
||||||
*
|
*
|
||||||
@ -151,28 +143,28 @@ namespace godot
|
|||||||
*
|
*
|
||||||
* @param[in] level The new level to load when starting.
|
* @param[in] level The new level to load when starting.
|
||||||
*/
|
*/
|
||||||
void set_level(Ref<PackedScene> level);
|
void set_level(godot::Ref<godot::PackedScene> level);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Get the level object.
|
* @brief Get the level object.
|
||||||
*
|
*
|
||||||
* @return Ref<PackedScene> The level scene to load.
|
* @return Ref<PackedScene> The level scene to load.
|
||||||
*/
|
*/
|
||||||
Ref<PackedScene> get_level();
|
godot::Ref<godot::PackedScene> get_level();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Set the game version object.
|
* @brief Set the game version object.
|
||||||
*
|
*
|
||||||
* @param[in] game_version The new version fo the game.
|
* @param[in] game_version The new version fo the game.
|
||||||
*/
|
*/
|
||||||
void set_game_version(String game_version);
|
void set_game_version(godot::String game_version);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Get the game version object.
|
* @brief Get the game version object.
|
||||||
*
|
*
|
||||||
* @return String The current version of the game.
|
* @return String The current version of the game.
|
||||||
*/
|
*/
|
||||||
String get_game_version();
|
godot::String get_game_version();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Set the full screen object.
|
* @brief Set the full screen object.
|
||||||
@ -194,14 +186,14 @@ namespace godot
|
|||||||
*
|
*
|
||||||
* @param[in] window_size The new window size.
|
* @param[in] window_size The new window size.
|
||||||
*/
|
*/
|
||||||
void set_window_size(Vector2 window_size);
|
void set_window_size(godot::Vector2 window_size);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Get the window size object.
|
* @brief Get the window size object.
|
||||||
*
|
*
|
||||||
* @return Vector2 The window size.
|
* @return Vector2 The window size.
|
||||||
*/
|
*/
|
||||||
Vector2 get_window_size();
|
godot::Vector2 get_window_size();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Set the launch screen object.
|
* @brief Set the launch screen object.
|
||||||
@ -217,12 +209,25 @@ namespace godot
|
|||||||
*/
|
*/
|
||||||
int8_t get_launch_screen();
|
int8_t get_launch_screen();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Called when the monitor finishes loading.
|
||||||
|
*
|
||||||
|
*/
|
||||||
void _on_monitor_loaded();
|
void _on_monitor_loaded();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Loads the monitor and adds it to the scene.
|
||||||
|
*
|
||||||
|
*/
|
||||||
void load_monitor();
|
void load_monitor();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Loads the selected level.
|
||||||
|
*
|
||||||
|
* @return Node* The level node which we will later add the monitor to.
|
||||||
|
*/
|
||||||
Node *load_level();
|
Node *load_level();
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -1,55 +1,48 @@
|
|||||||
#include "coin/CoinCollected.h"
|
#include "coin/CoinCollected.h"
|
||||||
#include <AnimationPlayer.hpp>
|
|
||||||
#include "Event.h"
|
#include "Event.h"
|
||||||
|
|
||||||
using namespace godot;
|
#include <AnimationPlayer.hpp>
|
||||||
|
|
||||||
void CoinCollected::_register_methods()
|
void alai::CoinCollected::_register_methods()
|
||||||
{
|
{
|
||||||
register_method("_state_enter", &CoinCollected::_state_enter);
|
register_method("_state_enter", &CoinCollected::_state_enter);
|
||||||
register_method("_state_exit", &CoinCollected::_state_exit);
|
register_method("_state_exit", &CoinCollected::_state_exit);
|
||||||
register_method("_on_animation_finished", &CoinCollected::_on_animation_finished);
|
register_method("_on_animation_finished", &CoinCollected::_on_animation_finished);
|
||||||
}
|
}
|
||||||
|
|
||||||
CoinCollected::CoinCollected()
|
alai::CoinCollected::CoinCollected()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
CoinCollected::~CoinCollected()
|
alai::CoinCollected::~CoinCollected()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void CoinCollected::_init()
|
void alai::CoinCollected::_init()
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CoinCollected::_state_enter()
|
void alai::CoinCollected::_state_enter()
|
||||||
{
|
{
|
||||||
auto node = get_parent()->find_node("AnimationPlayer");
|
auto node = get_parent()->find_node("AnimationPlayer");
|
||||||
|
|
||||||
if (node != nullptr)
|
if (node != nullptr)
|
||||||
{
|
{
|
||||||
auto animation_player = Object::cast_to<AnimationPlayer>(node);
|
auto animation_player = Object::cast_to<godot::AnimationPlayer>(node);
|
||||||
animation_player->play("jump");
|
animation_player->play("jump");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CoinCollected::_state_exit()
|
void alai::CoinCollected::_state_exit()
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CoinCollected::_on_animation_finished(String anim_name)
|
void alai::CoinCollected::_on_animation_finished(godot::String anim_name)
|
||||||
{
|
{
|
||||||
auto event = get_node<alai::Event>("/root/Event");
|
auto event = get_node<alai::Event>("/root/Event");
|
||||||
event->emit_signal("coin_collected", 1);
|
event->emit_signal("coin_collected", 1);
|
||||||
this->get_parent()->queue_free();
|
this->get_parent()->queue_free();
|
||||||
|
|
||||||
|
|
||||||
// get_state_machine()->change("CoinCounter");
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,28 +1,27 @@
|
|||||||
#ifndef ALAI_COIN_COLLECTED
|
#ifndef ALAI_COIN_COIN_COLLECTED_H
|
||||||
#define ALAI_COIN_COLLECTED
|
#define ALAI_COIN_COIN_COLLECTED_H
|
||||||
|
|
||||||
#include "state_machine/State.h"
|
#include "state_machine/State.h"
|
||||||
|
|
||||||
#include <Godot.hpp>
|
|
||||||
#include <Node.hpp>
|
|
||||||
#include <AnimatedSprite.hpp>
|
#include <AnimatedSprite.hpp>
|
||||||
|
#include <Godot.hpp>
|
||||||
|
|
||||||
namespace godot
|
namespace alai
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @brief This class controls what happens when the Coin is in the collected state.
|
* @brief This class controls what happens when the Coin is in the collected state.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
class CoinCollected : public State
|
class CoinCollected : public alai::State
|
||||||
{
|
{
|
||||||
GODOT_CLASS(CoinCollected, State)
|
GODOT_CLASS(CoinCollected, alai::State)
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/**
|
/**
|
||||||
* @brief The animated sprite of the Coin.
|
* @brief The animated sprite of the Coin.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
AnimatedSprite *animated_sprite;
|
godot::AnimatedSprite *animated_sprite;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
@ -67,9 +66,8 @@ namespace godot
|
|||||||
* @brief Called when the animation of the collected coin has finished.
|
* @brief Called when the animation of the collected coin has finished.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
void _on_animation_finished(String anim_name);
|
void _on_animation_finished(godot::String anim_name);
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -1,43 +1,37 @@
|
|||||||
#include "coin/CoinCounter.h"
|
#include "coin/CoinCounter.h"
|
||||||
#include <String.hpp>
|
|
||||||
#include "coin/CoinCollected.h"
|
|
||||||
#include "Event.h"
|
|
||||||
using namespace godot;
|
|
||||||
|
|
||||||
void CoinCounter::_register_methods()
|
#include "Event.h"
|
||||||
|
|
||||||
|
#include <String.hpp>
|
||||||
|
|
||||||
|
void alai::CoinCounter::_register_methods()
|
||||||
{
|
{
|
||||||
register_method("_on_coin_collected", &CoinCounter::_on_coin_collected);
|
register_method("_on_coin_collected", &CoinCounter::_on_coin_collected);
|
||||||
register_method("_ready", &CoinCounter::_ready);
|
register_method("_ready", &CoinCounter::_ready);
|
||||||
}
|
}
|
||||||
|
|
||||||
CoinCounter::CoinCounter()
|
alai::CoinCounter::CoinCounter()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
CoinCounter::~CoinCounter()
|
alai::CoinCounter::~CoinCounter()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void CoinCounter::_init()
|
void alai::CoinCounter::_init()
|
||||||
{
|
{
|
||||||
|
coins = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CoinCounter::_on_CoinHUD_ready()
|
void alai::CoinCounter::_on_coin_collected(int amount)
|
||||||
{
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
void CoinCounter::_on_coin_collected(int amount)
|
|
||||||
{
|
{
|
||||||
coins = coins + amount;
|
coins = coins + amount;
|
||||||
set_text(String::num(coins));
|
set_text(godot::String::num(coins));
|
||||||
}
|
}
|
||||||
void CoinCounter::_ready()
|
|
||||||
|
void alai::CoinCounter::_ready()
|
||||||
{
|
{
|
||||||
set_text("0");
|
set_text("0");
|
||||||
auto event = get_node<alai::Event>("/root/Event");
|
auto event = get_node<alai::Event>("/root/Event");
|
||||||
event->connect("coin_collected", this, "_on_coin_collected");
|
event->connect("coin_collected", this, "_on_coin_collected");
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,24 +1,21 @@
|
|||||||
#ifndef ALAI_COIN_COUNTER
|
#ifndef ALAI_COIN_COIN_COUNTER_H
|
||||||
#define ALAI_COIN_COUNTER
|
#define ALAI_COIN_COIN_COUNTER_H
|
||||||
|
|
||||||
|
|
||||||
#include <Godot.hpp>
|
#include <Godot.hpp>
|
||||||
#include <Node.hpp>
|
|
||||||
#include <Label.hpp>
|
#include <Label.hpp>
|
||||||
|
|
||||||
namespace godot
|
namespace alai
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @brief This class controls what happens when the Coin is in the collected .
|
* @brief This class controls what happens when the Coin is in the collected .
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
class CoinCounter : public Label
|
class CoinCounter : public godot::Label
|
||||||
{
|
{
|
||||||
GODOT_CLASS(CoinCounter, Label)
|
GODOT_CLASS(CoinCounter, godot::Label)
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int coins = 0;
|
int coins;
|
||||||
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
|
@ -1,56 +1,46 @@
|
|||||||
#include "coin/CoinNotCollected.h"
|
#include "coin/CoinNotCollected.h"
|
||||||
|
|
||||||
#include <Area2D.hpp>
|
#include <Area2D.hpp>
|
||||||
|
|
||||||
using namespace godot;
|
void alai::CoinNotCollected::_register_methods()
|
||||||
|
|
||||||
|
|
||||||
void CoinNotCollected::_register_methods()
|
|
||||||
{
|
{
|
||||||
register_method("_state_enter", &CoinNotCollected::_state_enter);
|
register_method("_state_enter", &CoinNotCollected::_state_enter);
|
||||||
register_method("_state_exit", &CoinNotCollected::_state_exit);
|
register_method("_state_exit", &CoinNotCollected::_state_exit);
|
||||||
register_method("_on_body_entered", &CoinNotCollected::_on_body_entered);
|
register_method("_on_body_entered", &CoinNotCollected::_on_body_entered);
|
||||||
}
|
}
|
||||||
|
|
||||||
CoinNotCollected::CoinNotCollected()
|
alai::CoinNotCollected::CoinNotCollected()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
CoinNotCollected::~CoinNotCollected()
|
alai::CoinNotCollected::~CoinNotCollected()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void CoinNotCollected::_init()
|
void alai::CoinNotCollected::_init()
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CoinNotCollected::_state_enter()
|
void alai::CoinNotCollected::_state_enter()
|
||||||
{
|
{
|
||||||
animated_sprite = get_parent()->get_node<AnimatedSprite>("AnimatedSprite");
|
animated_sprite = get_parent()->get_node<godot::AnimatedSprite>("AnimatedSprite");
|
||||||
animated_sprite->set_animation("spin");
|
animated_sprite->set_animation("spin");
|
||||||
animated_sprite->play();
|
animated_sprite->play();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CoinNotCollected::_state_exit()
|
void alai::CoinNotCollected::_state_exit()
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CoinNotCollected::_on_body_entered(Node *node)
|
void alai::CoinNotCollected::_on_body_entered(Node *node)
|
||||||
{
|
{
|
||||||
Godot::print("Coin touched");
|
|
||||||
auto parent_node = get_parent();
|
auto parent_node = get_parent();
|
||||||
|
|
||||||
if (parent_node != nullptr)
|
if (parent_node != nullptr)
|
||||||
{
|
{
|
||||||
auto coin = Object::cast_to<Area2D>(parent_node);
|
auto coin = Object::cast_to<godot::Area2D>(parent_node);
|
||||||
coin->set_collision_mask_bit(0, false);
|
coin->set_collision_mask_bit(0, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
get_state_machine()->change("CoinCollected");
|
get_state_machine()->change("CoinCollected");
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,28 +1,27 @@
|
|||||||
#ifndef ALAI_COIN_NOT_COLLECTED
|
#ifndef ALAI_COIN_COIN_NOT_COLLECTED_H
|
||||||
#define ALAI_COIN_NOT_COLLECTED
|
#define ALAI_COIN_COIN_NOT_COLLECTED_H
|
||||||
|
|
||||||
#include "state_machine/State.h"
|
#include "state_machine/State.h"
|
||||||
|
|
||||||
#include <Godot.hpp>
|
|
||||||
#include <Node.hpp>
|
|
||||||
#include <AnimatedSprite.hpp>
|
#include <AnimatedSprite.hpp>
|
||||||
|
#include <Godot.hpp>
|
||||||
|
|
||||||
namespace godot
|
namespace alai
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @brief This class controls what happens when the Coin is in the not collected state.
|
* @brief This class controls what happens when the Coin is in the not collected state.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
class CoinNotCollected : public State
|
class CoinNotCollected : public alai::State
|
||||||
{
|
{
|
||||||
GODOT_CLASS(CoinNotCollected, State)
|
GODOT_CLASS(CoinNotCollected, alai::State)
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/**
|
/**
|
||||||
* @brief The animated sprite of the Coin.
|
* @brief The animated sprite of the Coin.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
AnimatedSprite *animated_sprite;
|
godot::AnimatedSprite *animated_sprite;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
@ -70,7 +69,6 @@ namespace godot
|
|||||||
*/
|
*/
|
||||||
void _on_body_entered(Node *node);
|
void _on_body_entered(Node *node);
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -1,55 +1,46 @@
|
|||||||
#include "goal/GoalNotReached.h"
|
#include "goal/GoalNotReached.h"
|
||||||
|
|
||||||
#include <Area2D.hpp>
|
#include <Area2D.hpp>
|
||||||
|
|
||||||
using namespace godot;
|
void alai::GoalNotReached::_register_methods()
|
||||||
|
|
||||||
|
|
||||||
void GoalNotReached::_register_methods()
|
|
||||||
{
|
{
|
||||||
register_method("_state_enter", &GoalNotReached::_state_enter);
|
register_method("_state_enter", &GoalNotReached::_state_enter);
|
||||||
register_method("_state_exit", &GoalNotReached::_state_exit);
|
register_method("_state_exit", &GoalNotReached::_state_exit);
|
||||||
register_method("_on_Goal_body_entered", &GoalNotReached::_on_Goal_body_entered);
|
register_method("_on_Goal_body_entered", &GoalNotReached::_on_Goal_body_entered);
|
||||||
}
|
}
|
||||||
|
|
||||||
GoalNotReached::GoalNotReached()
|
alai::GoalNotReached::GoalNotReached()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
GoalNotReached::~GoalNotReached()
|
alai::GoalNotReached::~GoalNotReached()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void GoalNotReached::_init()
|
void alai::GoalNotReached::_init()
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void GoalNotReached::_state_enter()
|
void alai::GoalNotReached::_state_enter()
|
||||||
{
|
{
|
||||||
animated_sprite = get_parent()->get_node<AnimatedSprite>("AnimatedSprite");
|
animated_sprite = get_parent()->get_node<godot::AnimatedSprite>("AnimatedSprite");
|
||||||
animated_sprite->set_animation("flagmove");
|
animated_sprite->set_animation("flagmove");
|
||||||
animated_sprite->play();
|
animated_sprite->play();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GoalNotReached::_state_exit()
|
void alai::GoalNotReached::_state_exit()
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void GoalNotReached::_on_Goal_body_entered(Node *node)
|
void alai::GoalNotReached::_on_Goal_body_entered(Node *node)
|
||||||
{
|
{
|
||||||
auto parent_node = get_parent();
|
auto parent_node = get_parent();
|
||||||
|
|
||||||
if (parent_node != nullptr)
|
if (parent_node != nullptr)
|
||||||
{
|
{
|
||||||
auto goal = Object::cast_to<Area2D>(parent_node);
|
auto goal = Object::cast_to<godot::Area2D>(parent_node);
|
||||||
goal->set_collision_mask_bit(0, false);
|
goal->set_collision_mask_bit(0, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
get_state_machine()->change("GoalReached");
|
get_state_machine()->change("GoalReached");
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,28 +1,27 @@
|
|||||||
#ifndef ALAI_GOAL_NOT_REACHED
|
#ifndef ALAI_GOAL_GOAL_NOT_REACHED_H
|
||||||
#define ALAI_GOAL_NOT_REACHED
|
#define ALAI_GOAL_GOAL_NOT_REACHED_H
|
||||||
|
|
||||||
#include "state_machine/State.h"
|
#include "state_machine/State.h"
|
||||||
|
|
||||||
#include <Godot.hpp>
|
|
||||||
#include <Node.hpp>
|
|
||||||
#include <AnimatedSprite.hpp>
|
#include <AnimatedSprite.hpp>
|
||||||
|
#include <Godot.hpp>
|
||||||
|
|
||||||
namespace godot
|
namespace alai
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @brief This class controls what happens when the Coin is in the not collected state.
|
* @brief This class controls what happens when the Coin is in the not collected state.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
class GoalNotReached : public State
|
class GoalNotReached : public alai::State
|
||||||
{
|
{
|
||||||
GODOT_CLASS(GoalNotReached, State)
|
GODOT_CLASS(GoalNotReached, alai::State)
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/**
|
/**
|
||||||
* @brief The animated sprite of the Coin.
|
* @brief The animated sprite of the Coin.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
AnimatedSprite *animated_sprite;
|
godot::AnimatedSprite *animated_sprite;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
@ -70,7 +69,6 @@ namespace godot
|
|||||||
*/
|
*/
|
||||||
void _on_Goal_body_entered(Node *node);
|
void _on_Goal_body_entered(Node *node);
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -1,36 +1,30 @@
|
|||||||
#include "goal/GoalReached.h"
|
#include "goal/GoalReached.h"
|
||||||
|
|
||||||
#include <Area2D.hpp>
|
#include <Area2D.hpp>
|
||||||
|
|
||||||
using namespace godot;
|
void alai::GoalReached::_register_methods()
|
||||||
|
|
||||||
void GoalReached::_register_methods()
|
|
||||||
{
|
{
|
||||||
register_method("_state_enter", &GoalReached::_state_enter);
|
register_method("_state_enter", &GoalReached::_state_enter);
|
||||||
register_method("_state_exit", &GoalReached::_state_exit);
|
register_method("_state_exit", &GoalReached::_state_exit);
|
||||||
}
|
}
|
||||||
|
|
||||||
GoalReached::GoalReached()
|
alai::GoalReached::GoalReached()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
GoalReached::~GoalReached()
|
alai::GoalReached::~GoalReached()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void GoalReached::_init()
|
void alai::GoalReached::_init()
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void GoalReached::_state_enter()
|
void alai::GoalReached::_state_enter()
|
||||||
{
|
{
|
||||||
Godot::print("Flag touched");
|
godot::Godot::print("Flag touched");
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void GoalReached::_state_exit()
|
void alai::GoalReached::_state_exit()
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,28 +1,27 @@
|
|||||||
#ifndef ALAI_GOAL_REACHED
|
#ifndef ALAI_GOAL_GOAL_REACHED_H
|
||||||
#define ALAI_GOAL_REACHED
|
#define ALAI_GOAL_GOAL_REACHED_H
|
||||||
|
|
||||||
#include "state_machine/State.h"
|
#include "state_machine/State.h"
|
||||||
|
|
||||||
#include <Godot.hpp>
|
|
||||||
#include <Node.hpp>
|
|
||||||
#include <AnimatedSprite.hpp>
|
#include <AnimatedSprite.hpp>
|
||||||
|
#include <Godot.hpp>
|
||||||
|
|
||||||
namespace godot
|
namespace alai
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @brief This class controls what happens when the goal flag is in the reached state.
|
* @brief This class controls what happens when the goal flag is in the reached state.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
class GoalReached : public State
|
class GoalReached : public alai::State
|
||||||
{
|
{
|
||||||
GODOT_CLASS(GoalReached, State)
|
GODOT_CLASS(GoalReached, alai::State)
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/**
|
/**
|
||||||
* @brief The animated sprite of the Coin.
|
* @brief The animated sprite of the Coin.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
AnimatedSprite *animated_sprite;
|
godot::AnimatedSprite *animated_sprite;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
@ -68,7 +67,6 @@ namespace godot
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -17,15 +17,13 @@
|
|||||||
#include "goal/GoalNotReached.h"
|
#include "goal/GoalNotReached.h"
|
||||||
#include "gui/game_over/GameOverScreen.h"
|
#include "gui/game_over/GameOverScreen.h"
|
||||||
|
|
||||||
using namespace godot;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief This function connects the gdnative init function.
|
* @brief This function connects the gdnative init function.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
extern "C" void GDN_EXPORT godot_gdnative_init(godot_gdnative_init_options *o)
|
extern "C" void GDN_EXPORT godot_gdnative_init(godot_gdnative_init_options *o)
|
||||||
{
|
{
|
||||||
Godot::gdnative_init(o);
|
godot::Godot::gdnative_init(o);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -36,8 +34,8 @@ extern "C" void GDN_EXPORT godot_gdnative_terminate(godot_gdnative_terminate_opt
|
|||||||
{
|
{
|
||||||
// This next line is a workaround to fix bug:
|
// This next line is a workaround to fix bug:
|
||||||
// https://github.com/godotengine/godot/issues/48295
|
// https://github.com/godotengine/godot/issues/48295
|
||||||
Godot::nativescript_terminate(_RegisterState::nativescript_handle);
|
godot::Godot::nativescript_terminate(godot::_RegisterState::nativescript_handle);
|
||||||
Godot::gdnative_terminate(o);
|
godot::Godot::gdnative_terminate(o);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -46,21 +44,22 @@ extern "C" void GDN_EXPORT godot_gdnative_terminate(godot_gdnative_terminate_opt
|
|||||||
*/
|
*/
|
||||||
extern "C" void GDN_EXPORT godot_nativescript_init(void *handle)
|
extern "C" void GDN_EXPORT godot_nativescript_init(void *handle)
|
||||||
{
|
{
|
||||||
Godot::nativescript_init(handle);
|
godot::Godot::nativescript_init(handle);
|
||||||
register_class<alai::Event>();
|
|
||||||
register_class<StateMachine>();
|
godot::register_class<alai::Event>();
|
||||||
register_class<State>();
|
godot::register_class<alai::StateMachine>();
|
||||||
register_class<main::Main>();
|
godot::register_class<alai::State>();
|
||||||
register_class<CameraLimit>();
|
godot::register_class<alai::Main>();
|
||||||
register_class<player::Player>();
|
godot::register_class<alai::CameraLimit>();
|
||||||
register_class<player::PlayerIdle>();
|
godot::register_class<alai::player::Player>();
|
||||||
register_class<player::PlayerMove>();
|
godot::register_class<alai::player::PlayerIdle>();
|
||||||
register_class<player::PlayerJump>();
|
godot::register_class<alai::player::PlayerMove>();
|
||||||
register_class<player::PlayerFall>();
|
godot::register_class<alai::player::PlayerJump>();
|
||||||
register_class<CoinNotCollected>();
|
godot::register_class<alai::player::PlayerFall>();
|
||||||
register_class<CoinCollected>();
|
godot::register_class<alai::CoinNotCollected>();
|
||||||
register_class<CoinCounter>();
|
godot::register_class<alai::CoinCollected>();
|
||||||
register_class<GoalReached>();
|
godot::register_class<alai::CoinCounter>();
|
||||||
register_class<GoalNotReached>();
|
godot::register_class<alai::GoalReached>();
|
||||||
register_class<GameOverScreen>();
|
godot::register_class<alai::GoalNotReached>();
|
||||||
|
godot::register_class<alai::GameOverScreen>();
|
||||||
}
|
}
|
||||||
|
@ -1,54 +1,49 @@
|
|||||||
#include "gui/game_over/GameOverScreen.h"
|
#include "gui/game_over/GameOverScreen.h"
|
||||||
#include "Event.h"
|
#include "Event.h"
|
||||||
|
|
||||||
#include <Resource.hpp>
|
|
||||||
#include <Ref.hpp>
|
|
||||||
#include <Node.hpp>
|
#include <Node.hpp>
|
||||||
#include <SceneTree.hpp>
|
|
||||||
#include <PackedScene.hpp>
|
#include <PackedScene.hpp>
|
||||||
|
#include <Ref.hpp>
|
||||||
|
#include <Resource.hpp>
|
||||||
|
#include <SceneTree.hpp>
|
||||||
#include <Viewport.hpp>
|
#include <Viewport.hpp>
|
||||||
|
|
||||||
|
void alai::GameOverScreen::_register_methods()
|
||||||
using namespace godot;
|
|
||||||
|
|
||||||
void GameOverScreen::_register_methods()
|
|
||||||
{
|
{
|
||||||
register_method("_on_botonreiniciar_pressed", &GameOverScreen::_on_botonreiniciar_pressed);
|
register_method("_on_restart_button_pressed", &GameOverScreen::_on_restart_button_pressed);
|
||||||
register_method("_ready", &GameOverScreen::_ready);
|
register_method("_ready", &GameOverScreen::_ready);
|
||||||
register_method("connect_signal", &GameOverScreen::connect_signal);
|
register_method("connect_signal", &GameOverScreen::connect_signal);
|
||||||
register_method("_on_player_died", &GameOverScreen::_on_player_died);
|
register_method("_on_player_died", &GameOverScreen::_on_player_died);
|
||||||
}
|
}
|
||||||
|
|
||||||
GameOverScreen::GameOverScreen()
|
alai::GameOverScreen::GameOverScreen()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
GameOverScreen::~GameOverScreen()
|
alai::GameOverScreen::~GameOverScreen()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void GameOverScreen::_init()
|
void alai::GameOverScreen::_init()
|
||||||
{
|
{
|
||||||
_resource_loader = ResourceLoader::get_singleton();
|
_resource_loader = godot::ResourceLoader::get_singleton();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void GameOverScreen::_ready()
|
void alai::GameOverScreen::_ready()
|
||||||
{
|
{
|
||||||
connect_signal();
|
connect_signal();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GameOverScreen::_on_botonreiniciar_pressed()
|
void alai::GameOverScreen::_on_restart_button_pressed()
|
||||||
{
|
{
|
||||||
if (_resource_loader->exists("res://levels/Prototype.tscn")) //CAMBIAR A DINAMICO
|
if (_resource_loader->exists("res://levels/Prototype.tscn"))
|
||||||
{
|
{
|
||||||
Ref<PackedScene> level_scene = _resource_loader->load("res://levels/Prototype.tscn");
|
godot::Ref<godot::PackedScene> level_scene = _resource_loader->load("res://levels/Prototype.tscn");
|
||||||
auto level = level_scene->instance();
|
auto level = level_scene->instance();
|
||||||
auto level_node = get_tree()->get_root()->get_node("Main")->find_node("Level");
|
auto level_node = get_tree()->get_root()->get_node("Main")->find_node("Level");
|
||||||
|
|
||||||
if (level_node != nullptr)
|
if (level_node != nullptr)
|
||||||
{
|
{
|
||||||
|
|
||||||
level_node->add_child(level);
|
level_node->add_child(level);
|
||||||
set_visible(false);
|
set_visible(false);
|
||||||
call_deferred("connect_signal");
|
call_deferred("connect_signal");
|
||||||
@ -57,16 +52,13 @@ void GameOverScreen::_on_botonreiniciar_pressed()
|
|||||||
{
|
{
|
||||||
WARN_PRINT("Node level not found!");
|
WARN_PRINT("Node level not found!");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
void alai::GameOverScreen::_on_player_died()
|
||||||
|
|
||||||
void GameOverScreen::_on_player_died() //eliminar nivel
|
|
||||||
{
|
{
|
||||||
auto event = get_node<alai::Event>("/root/Event");
|
auto event = get_node<alai::Event>("/root/Event");
|
||||||
event->disconnect("player_died", this, "_on_player_died");
|
event->disconnect("player_died", this, "_on_player_died");
|
||||||
Godot::print("player ded");
|
|
||||||
set_visible(true);
|
set_visible(true);
|
||||||
auto level_node = get_tree()->get_root()->get_node("Main")->find_node("Level");
|
auto level_node = get_tree()->get_root()->get_node("Main")->find_node("Level");
|
||||||
if (level_node != nullptr)
|
if (level_node != nullptr)
|
||||||
@ -74,6 +66,7 @@ void GameOverScreen::_on_player_died() //eliminar nivel
|
|||||||
auto child = level_node->get_child(0);
|
auto child = level_node->get_child(0);
|
||||||
if (child != nullptr)
|
if (child != nullptr)
|
||||||
{
|
{
|
||||||
|
// Delete the currently active level from the tree.
|
||||||
child->queue_free();
|
child->queue_free();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -85,14 +78,10 @@ void GameOverScreen::_on_player_died() //eliminar nivel
|
|||||||
{
|
{
|
||||||
WARN_PRINT("Node level not found!");
|
WARN_PRINT("Node level not found!");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void GameOverScreen::connect_signal()
|
void alai::GameOverScreen::connect_signal()
|
||||||
{
|
{
|
||||||
auto event = get_node<alai::Event>("/root/Event");
|
auto event = get_node<alai::Event>("/root/Event");
|
||||||
event->connect("player_died", this, "_on_player_died");
|
event->connect("player_died", this, "_on_player_died");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,23 +1,22 @@
|
|||||||
#ifndef ALAI_GAME_OVER_SCREEN_H
|
#ifndef ALAI_GAME_OVER_SCREEN_H
|
||||||
#define ALAI_GAME_OVER_SCREEN_H
|
#define ALAI_GAME_OVER_SCREEN_H
|
||||||
|
|
||||||
#include <Godot.hpp>
|
|
||||||
#include <CanvasLayer.hpp>
|
#include <CanvasLayer.hpp>
|
||||||
|
#include <Godot.hpp>
|
||||||
#include <ResourceLoader.hpp>
|
#include <ResourceLoader.hpp>
|
||||||
|
|
||||||
|
namespace alai
|
||||||
namespace godot
|
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @brief This class controls what happens when the Coin is in the collected .
|
* @brief This class controls what happens when the Coin is in the collected .
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
class GameOverScreen : public CanvasLayer
|
class GameOverScreen : public godot::CanvasLayer
|
||||||
{
|
{
|
||||||
GODOT_CLASS(GameOverScreen, CanvasLayer)
|
GODOT_CLASS(GameOverScreen, godot::CanvasLayer)
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ResourceLoader *_resource_loader;
|
godot::ResourceLoader *_resource_loader;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
@ -52,11 +51,9 @@ namespace godot
|
|||||||
*/
|
*/
|
||||||
void _ready();
|
void _ready();
|
||||||
void _on_player_died();
|
void _on_player_died();
|
||||||
void _on_botonreiniciar_pressed();
|
void _on_restart_button_pressed();
|
||||||
void connect_signal();
|
void connect_signal();
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
@ -3,45 +3,42 @@
|
|||||||
#include "Event.h"
|
#include "Event.h"
|
||||||
|
|
||||||
#include <Camera2D.hpp>
|
#include <Camera2D.hpp>
|
||||||
#include <TileMap.hpp>
|
#include <KinematicCollision2D.hpp>
|
||||||
#include <VisibilityNotifier2D.hpp>
|
#include <RayCast2D.hpp>
|
||||||
#include <SceneTree.hpp>
|
#include <SceneTree.hpp>
|
||||||
#include <Texture.hpp>
|
#include <Texture.hpp>
|
||||||
|
#include <TileMap.hpp>
|
||||||
#include <Viewport.hpp>
|
#include <Viewport.hpp>
|
||||||
#include <RayCast2D.hpp>
|
#include <VisibilityNotifier2D.hpp>
|
||||||
#include <KinematicCollision2D.hpp>
|
|
||||||
|
|
||||||
using namespace godot;
|
void alai::player::Player::_register_methods()
|
||||||
using namespace player;
|
|
||||||
|
|
||||||
void Player::_register_methods()
|
|
||||||
{
|
{
|
||||||
register_method("_ready", &Player::_ready);
|
godot::register_method("_ready", &Player::_ready);
|
||||||
register_method("_physics_process", &Player::_physics_process);
|
godot::register_method("_physics_process", &Player::_physics_process);
|
||||||
register_method("set_velocity", &Player::set_velocity);
|
godot::register_method("set_velocity", &Player::set_velocity);
|
||||||
register_method("get_velocity", &Player::get_velocity);
|
godot::register_method("get_velocity", &Player::get_velocity);
|
||||||
register_method("_on_player_touched", &Player::_on_player_touched);
|
godot::register_method("_on_player_touched", &Player::_on_player_touched);
|
||||||
register_method("_on_monitor_loaded", &Player::_on_monitor_loaded);
|
godot::register_method("_on_monitor_loaded", &Player::_on_monitor_loaded);
|
||||||
//register_property<Player, Ref<SpriteFrames>>("sprite_frames", &Player::set_sprite_frames, &Player::get_sprite_frames, Ref<SpriteFrames>(), GODOT_METHOD_RPC_MODE_DISABLED, GODOT_PROPERTY_USAGE_DEFAULT, GODOT_PROPERTY_HINT_RESOURCE_TYPE, String("SpriteFrames"));
|
//godot::register_property<Player, godot::Ref<godot::SpriteFrames>>("sprite_frames", &Player::set_sprite_frames, &Player::get_sprite_frames, godot::Ref<godot::SpriteFrames>(), GODOT_METHOD_RPC_MODE_DISABLED, GODOT_PROPERTY_USAGE_DEFAULT, GODOT_PROPERTY_HINT_RESOURCE_TYPE, godot::String("SpriteFrames"));
|
||||||
register_property<Player, float>("speed", &Player::set_speed, &Player::get_speed, player::speed);
|
godot::register_property<Player, float>("speed", &Player::set_speed, &Player::get_speed, player::speed);
|
||||||
register_property<Player, float>("jump_force", &Player::set_jump_force, &Player::get_jump_force, player::jump_force);
|
godot::register_property<Player, float>("jump_force", &Player::set_jump_force, &Player::get_jump_force, player::jump_force);
|
||||||
register_property<Player, float>("bounce_force", &Player::set_bounce_force, &Player::get_bounce_force, player::bounce_force);
|
godot::register_property<Player, float>("bounce_force", &Player::set_bounce_force, &Player::get_bounce_force, player::bounce_force);
|
||||||
register_property<Player, float>("gravity", &Player::set_gravity, &Player::get_gravity, player::gravity);
|
godot::register_property<Player, float>("gravity", &Player::set_gravity, &Player::get_gravity, player::gravity);
|
||||||
register_property<Player, float>("run_speed", &Player::set_run_speed, &Player::get_run_speed, player::run_speed);
|
godot::register_property<Player, float>("run_speed", &Player::set_run_speed, &Player::get_run_speed, player::run_speed);
|
||||||
register_property<Player, bool>("double_jump", &Player::set_double_jump, &Player::get_double_jump, player::double_jump);
|
godot::register_property<Player, bool>("double_jump", &Player::set_double_jump, &Player::get_double_jump, player::double_jump);
|
||||||
}
|
}
|
||||||
|
|
||||||
Player::Player()
|
alai::player::Player::Player()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
Player::~Player()
|
alai::player::Player::~Player()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void Player::_init()
|
void alai::player::Player::_init()
|
||||||
{
|
{
|
||||||
_resource_loader = ResourceLoader::get_singleton();
|
_resource_loader = godot::ResourceLoader::get_singleton();
|
||||||
|
|
||||||
//sprite_frames = _resource_loader->load(player::sprite_frames);
|
//sprite_frames = _resource_loader->load(player::sprite_frames);
|
||||||
set_speed(player::speed);
|
set_speed(player::speed);
|
||||||
@ -53,23 +50,23 @@ void Player::_init()
|
|||||||
|
|
||||||
coins = 0;
|
coins = 0;
|
||||||
|
|
||||||
velocity = Vector2();
|
velocity = godot::Vector2();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Player::_ready()
|
void alai::player::Player::_ready()
|
||||||
{
|
{
|
||||||
animated_sprite = get_node<AnimatedSprite>("AnimatedSprite");
|
animated_sprite = get_node<godot::AnimatedSprite>("AnimatedSprite");
|
||||||
if (!animated_sprite)
|
if (!animated_sprite)
|
||||||
{
|
{
|
||||||
ERR_PRINT("AnimateSprite not found!");
|
ERR_PRINT("AnimateSprite not found!");
|
||||||
animated_sprite = AnimatedSprite()._new();
|
animated_sprite = godot::AnimatedSprite()._new();
|
||||||
}
|
}
|
||||||
//animated_sprite->set_sprite_frames(sprite_frames);
|
//animated_sprite->set_sprite_frames(sprite_frames);
|
||||||
|
|
||||||
auto node = get_parent()->find_node("Middleground");
|
auto node = get_parent()->find_node("Middleground");
|
||||||
if (node != nullptr)
|
if (node != nullptr)
|
||||||
{
|
{
|
||||||
auto tile_map = Object::cast_to<TileMap>(node);
|
auto tile_map = Object::cast_to<godot::TileMap>(node);
|
||||||
get_parent()->call_deferred("remove_child", this);
|
get_parent()->call_deferred("remove_child", this);
|
||||||
tile_map->call_deferred("add_child", this);
|
tile_map->call_deferred("add_child", this);
|
||||||
}
|
}
|
||||||
@ -79,7 +76,7 @@ void Player::_ready()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Player::_on_monitor_loaded() {
|
void alai::player::Player::_on_monitor_loaded() {
|
||||||
auto state = get_node("StateMachine")->get_child(0);
|
auto state = get_node("StateMachine")->get_child(0);
|
||||||
if (state != nullptr)
|
if (state != nullptr)
|
||||||
{
|
{
|
||||||
@ -92,22 +89,22 @@ void Player::_on_monitor_loaded() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Player::_physics_process(float delta)
|
void alai::player::Player::_physics_process(float delta)
|
||||||
{
|
{
|
||||||
velocity.y += get_gravity();
|
velocity.y += get_gravity();
|
||||||
|
|
||||||
auto snap_vector = Vector2::ZERO;
|
auto snap_vector = godot::Vector2::ZERO;
|
||||||
if (!is_on_floor())
|
if (!is_on_floor())
|
||||||
{
|
{
|
||||||
snap_vector = Vector2::DOWN * 20.0;
|
snap_vector = godot::Vector2::DOWN * 20.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto platform_detector = get_node<RayCast2D>("PlatformDetector");
|
auto platform_detector = get_node<godot::RayCast2D>("PlatformDetector");
|
||||||
auto is_on_platform = platform_detector->is_colliding();
|
auto is_on_platform = platform_detector->is_colliding();
|
||||||
|
|
||||||
velocity = move_and_slide_with_snap(velocity, snap_vector, Vector2::UP, !is_on_platform, 4, 0.9, false);
|
velocity = move_and_slide_with_snap(velocity, snap_vector, godot::Vector2::UP, !is_on_platform, 4, 0.9, false);
|
||||||
//velocity = move_and_slide(velocity, Vector2::UP, !is_on_platform);
|
//velocity = move_and_slide(velocity, Vector2::UP, !is_on_platform);
|
||||||
velocity.x = Math::lerp((float) velocity.x, (float) 0, (float) 0.2);
|
velocity.x = godot::Math::lerp((float) velocity.x, (float) 0, (float) 0.2);
|
||||||
|
|
||||||
auto count = get_slide_count();
|
auto count = get_slide_count();
|
||||||
for (int64_t i = 0; i < count; i++)
|
for (int64_t i = 0; i < count; i++)
|
||||||
@ -115,7 +112,7 @@ void Player::_physics_process(float delta)
|
|||||||
auto collision = get_slide_collision(i);
|
auto collision = get_slide_collision(i);
|
||||||
auto collision_object = collision->get_collider();
|
auto collision_object = collision->get_collider();
|
||||||
auto collider = Object::cast_to<Node>(collision_object);
|
auto collider = Object::cast_to<Node>(collision_object);
|
||||||
if (collider->is_in_group("squashable") && Vector2::UP.dot(collision->get_normal()) > 0.1)
|
if (collider->is_in_group("squashable") && godot::Vector2::UP.dot(collision->get_normal()) > 0.1)
|
||||||
{
|
{
|
||||||
collider->call_deferred("squash");
|
collider->call_deferred("squash");
|
||||||
/*auto dup_node = collider->duplicate();
|
/*auto dup_node = collider->duplicate();
|
||||||
@ -134,7 +131,7 @@ void Player::_physics_process(float delta)
|
|||||||
}*/
|
}*/
|
||||||
velocity.y = -get_bounce_force();
|
velocity.y = -get_bounce_force();
|
||||||
}
|
}
|
||||||
else if (collider->is_in_group("enemy") && (collider->is_in_group("rideable") && Vector2::DOWN.dot(collision->get_normal()) > 0))
|
else if (collider->is_in_group("enemy") && (collider->is_in_group("rideable") && godot::Vector2::DOWN.dot(collision->get_normal()) > 0))
|
||||||
{
|
{
|
||||||
_on_player_touched();
|
_on_player_touched();
|
||||||
}
|
}
|
||||||
@ -145,23 +142,23 @@ void Player::_physics_process(float delta)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Clamp the player's position inside the camera's limits
|
// Clamp the player's position inside the camera's limits
|
||||||
auto camera = get_node<Camera2D>("Camera2D");
|
auto camera = get_node<godot::Camera2D>("Camera2D");
|
||||||
auto position = get_global_position();
|
auto position = get_global_position();
|
||||||
auto sprite_node = get_node<AnimatedSprite>("AnimatedSprite");
|
auto sprite_node = get_node<godot::AnimatedSprite>("AnimatedSprite");
|
||||||
if (sprite_node != nullptr)
|
if (sprite_node != nullptr)
|
||||||
{
|
{
|
||||||
position.x = Math::clamp((float) position.x, (float) camera->get_limit(0), (float) camera->get_limit(2) - sprite_node->get_sprite_frames()->get_frame("idle", 0)->get_size().x);
|
position.x = godot::Math::clamp((float) position.x, (float) camera->get_limit(0), (float) camera->get_limit(2) - sprite_node->get_sprite_frames()->get_frame("idle", 0)->get_size().x);
|
||||||
position.y = Math::clamp((float) position.y, (float) camera->get_limit(1), (float) camera->get_limit(3) + sprite_node->get_sprite_frames()->get_frame("idle", 0)->get_size().y);
|
position.y = godot::Math::clamp((float) position.y, (float) camera->get_limit(1), (float) camera->get_limit(3) + sprite_node->get_sprite_frames()->get_frame("idle", 0)->get_size().y);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
WARN_PRINT("Could not clamp player based on sprite frame size!");
|
WARN_PRINT("Could not clamp player based on sprite frame size!");
|
||||||
position.x = Math::clamp((float) position.x, (float) camera->get_limit(0), (float) camera->get_limit(2));
|
position.x = godot::Math::clamp((float) position.x, (float) camera->get_limit(0), (float) camera->get_limit(2));
|
||||||
position.y = Math::clamp((float) position.y, (float) camera->get_limit(1), (float) camera->get_limit(3));
|
position.y = godot::Math::clamp((float) position.y, (float) camera->get_limit(1), (float) camera->get_limit(3));
|
||||||
}
|
}
|
||||||
set_global_position(position);
|
set_global_position(position);
|
||||||
|
|
||||||
// If the player is off screen reload the scene
|
// If the player is off screen reload the scene
|
||||||
auto notifier = get_node<VisibilityNotifier2D>("Camera2D/VisibilityNotifier2D");
|
auto notifier = get_node<godot::VisibilityNotifier2D>("Camera2D/VisibilityNotifier2D");
|
||||||
if (notifier != nullptr)
|
if (notifier != nullptr)
|
||||||
{
|
{
|
||||||
if (!notifier->is_on_screen())
|
if (!notifier->is_on_screen())
|
||||||
@ -171,9 +168,9 @@ void Player::_physics_process(float delta)
|
|||||||
/*if (get_parent()->get_class() == "TileMap")
|
/*if (get_parent()->get_class() == "TileMap")
|
||||||
{
|
{
|
||||||
auto error = get_tree()->change_scene("res://Main.tscn");
|
auto error = get_tree()->change_scene("res://Main.tscn");
|
||||||
if (error != Error::OK)
|
if (error != godot::Error::OK)
|
||||||
{
|
{
|
||||||
ERR_PRINT(String().num((int) error) + " Could not load scene!");
|
ERR_PRINT(godot::String().num((int) error) + " Could not load scene!");
|
||||||
}
|
}
|
||||||
}*/
|
}*/
|
||||||
}
|
}
|
||||||
@ -191,91 +188,91 @@ void Player::_physics_process(float delta)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Player::set_sprite_frames(Ref<SpriteFrames> sprite_frames)
|
void alai::player::Player::set_sprite_frames(godot::Ref<godot::SpriteFrames> sprite_frames)
|
||||||
{
|
{
|
||||||
this->sprite_frames = sprite_frames;
|
this->sprite_frames = sprite_frames;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ref<SpriteFrames> Player::get_sprite_frames()
|
godot::Ref<godot::SpriteFrames> alai::player::Player::get_sprite_frames()
|
||||||
{
|
{
|
||||||
return this->sprite_frames;
|
return this->sprite_frames;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Player::set_speed(float speed)
|
void alai::player::Player::set_speed(float speed)
|
||||||
{
|
{
|
||||||
this->speed = speed;
|
this->speed = speed;
|
||||||
}
|
}
|
||||||
|
|
||||||
float Player::get_speed()
|
float alai::player::Player::get_speed()
|
||||||
{
|
{
|
||||||
return this->speed;
|
return this->speed;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Player::set_jump_force(float jump_force)
|
void alai::player::Player::set_jump_force(float jump_force)
|
||||||
{
|
{
|
||||||
this->jump_force = jump_force;
|
this->jump_force = jump_force;
|
||||||
}
|
}
|
||||||
|
|
||||||
float Player::get_jump_force()
|
float alai::player::Player::get_jump_force()
|
||||||
{
|
{
|
||||||
return this->jump_force;
|
return this->jump_force;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Player::set_bounce_force(float bounce_force)
|
void alai::player::Player::set_bounce_force(float bounce_force)
|
||||||
{
|
{
|
||||||
this->bounce_force = bounce_force;
|
this->bounce_force = bounce_force;
|
||||||
}
|
}
|
||||||
|
|
||||||
float Player::get_bounce_force()
|
float alai::player::Player::get_bounce_force()
|
||||||
{
|
{
|
||||||
return this->bounce_force;
|
return this->bounce_force;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Player::set_gravity(float gravity)
|
void alai::player::Player::set_gravity(float gravity)
|
||||||
{
|
{
|
||||||
this->gravity = gravity;
|
this->gravity = gravity;
|
||||||
}
|
}
|
||||||
|
|
||||||
float Player::get_gravity()
|
float alai::player::Player::get_gravity()
|
||||||
{
|
{
|
||||||
return this->gravity;
|
return this->gravity;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Player::set_run_speed(float run_speed)
|
void alai::player::Player::set_run_speed(float run_speed)
|
||||||
{
|
{
|
||||||
this->run_speed = run_speed;
|
this->run_speed = run_speed;
|
||||||
}
|
}
|
||||||
|
|
||||||
float Player::get_run_speed()
|
float alai::player::Player::get_run_speed()
|
||||||
{
|
{
|
||||||
return this->run_speed;
|
return this->run_speed;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Player::set_double_jump(bool double_jump)
|
void alai::player::Player::set_double_jump(bool double_jump)
|
||||||
{
|
{
|
||||||
this->double_jump = double_jump;
|
this->double_jump = double_jump;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Player::get_double_jump()
|
bool alai::player::Player::get_double_jump()
|
||||||
{
|
{
|
||||||
return this->double_jump;
|
return this->double_jump;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Player::set_velocity(Vector2 velocity)
|
void alai::player::Player::set_velocity(godot::Vector2 velocity)
|
||||||
{
|
{
|
||||||
this->velocity = velocity;
|
this->velocity = velocity;
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector2 Player::get_velocity()
|
godot::Vector2 alai::player::Player::get_velocity()
|
||||||
{
|
{
|
||||||
return this->velocity;
|
return this->velocity;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Player::_on_player_touched()
|
void alai::player::Player::_on_player_touched()
|
||||||
{
|
{
|
||||||
auto error = get_tree()->change_scene("res://Main.tscn");
|
auto error = get_tree()->change_scene("res://Main.tscn");
|
||||||
if (error != Error::OK)
|
if (error != godot::Error::OK)
|
||||||
{
|
{
|
||||||
ERR_PRINT(String().num((int) error) + " Could not load scene!");
|
ERR_PRINT(godot::String().num((int) error) + " Could not load scene!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,14 +1,13 @@
|
|||||||
#ifndef ALAI_PLAYER_H
|
#ifndef ALAI_PLAYER_PLAYER_H
|
||||||
#define ALAI_PLAYER_H
|
#define ALAI_PLAYER_PLAYER_H
|
||||||
|
|
||||||
|
#include <AnimatedSprite.hpp>
|
||||||
#include <Godot.hpp>
|
#include <Godot.hpp>
|
||||||
#include <KinematicBody2D.hpp>
|
#include <KinematicBody2D.hpp>
|
||||||
#include <Sprite.hpp>
|
|
||||||
#include <AnimatedSprite.hpp>
|
|
||||||
#include <SpriteFrames.hpp>
|
|
||||||
#include <ResourceLoader.hpp>
|
#include <ResourceLoader.hpp>
|
||||||
|
#include <SpriteFrames.hpp>
|
||||||
|
|
||||||
namespace godot
|
namespace alai
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @brief This namespace contains the global variables related to the player and its states.
|
* @brief This namespace contains the global variables related to the player and its states.
|
||||||
@ -57,27 +56,27 @@ namespace godot
|
|||||||
*
|
*
|
||||||
* @details This class allows the player to move, run, and jump as well as controls the sprite displayed for those actions.
|
* @details This class allows the player to move, run, and jump as well as controls the sprite displayed for those actions.
|
||||||
*/
|
*/
|
||||||
class Player : public KinematicBody2D
|
class Player : public godot::KinematicBody2D
|
||||||
{
|
{
|
||||||
GODOT_CLASS(Player, KinematicBody2D)
|
GODOT_CLASS(Player, godot::KinematicBody2D)
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/**
|
/**
|
||||||
* @brief ResourceLoader singleton.
|
* @brief ResourceLoader singleton.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
ResourceLoader *_resource_loader;
|
godot::ResourceLoader *_resource_loader;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief The animated sprite connected to the KinematicBody2D.
|
* @brief The animated sprite connected to the KinematicBody2D.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
AnimatedSprite *animated_sprite;
|
godot::AnimatedSprite *animated_sprite;
|
||||||
/**
|
/**
|
||||||
* @brief The sprite frames used in the animated sprite.
|
* @brief The sprite frames used in the animated sprite.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
Ref<SpriteFrames> sprite_frames;
|
godot::Ref<godot::SpriteFrames> sprite_frames;
|
||||||
/**
|
/**
|
||||||
* @brief The coins the player has collected.
|
* @brief The coins the player has collected.
|
||||||
*
|
*
|
||||||
@ -87,7 +86,7 @@ namespace godot
|
|||||||
* @brief The velocity at which moves the player moves.
|
* @brief The velocity at which moves the player moves.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
Vector2 velocity;
|
godot::Vector2 velocity;
|
||||||
/**
|
/**
|
||||||
* @brief The speed that the player moves in.
|
* @brief The speed that the player moves in.
|
||||||
*
|
*
|
||||||
@ -167,14 +166,14 @@ namespace godot
|
|||||||
*
|
*
|
||||||
* @param[in] sprite_frames The new sprite frame.
|
* @param[in] sprite_frames The new sprite frame.
|
||||||
*/
|
*/
|
||||||
void set_sprite_frames(Ref<SpriteFrames> sprite_frames);
|
void set_sprite_frames(godot::Ref<godot::SpriteFrames> sprite_frames);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Get the sprite frames object.
|
* @brief Get the sprite frames object.
|
||||||
*
|
*
|
||||||
* @return Ref<SpriteFrames> A reference to the sprite frames object.
|
* @return Ref<SpriteFrames> A reference to the sprite frames object.
|
||||||
*/
|
*/
|
||||||
Ref<SpriteFrames> get_sprite_frames();
|
godot::Ref<godot::SpriteFrames> get_sprite_frames();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Set the speed object.
|
* @brief Set the speed object.
|
||||||
@ -266,14 +265,14 @@ namespace godot
|
|||||||
*
|
*
|
||||||
* @param[in] velocity The new velocity of the player.
|
* @param[in] velocity The new velocity of the player.
|
||||||
*/
|
*/
|
||||||
void set_velocity(Vector2 velocity);
|
void set_velocity(godot::Vector2 velocity);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Get the velocity object.
|
* @brief Get the velocity object.
|
||||||
*
|
*
|
||||||
* @return Vector2 Returns the velocity of the player.
|
* @return Vector2 Returns the velocity of the player.
|
||||||
*/
|
*/
|
||||||
Vector2 get_velocity();
|
godot::Vector2 get_velocity();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief This function is called when an enemy touches the player.
|
* @brief This function is called when an enemy touches the player.
|
||||||
@ -281,6 +280,10 @@ namespace godot
|
|||||||
*/
|
*/
|
||||||
void _on_player_touched();
|
void _on_player_touched();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Called when the monitor is loaded to connect the player to it for tracking.
|
||||||
|
*
|
||||||
|
*/
|
||||||
void _on_monitor_loaded();
|
void _on_monitor_loaded();
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -1,45 +1,43 @@
|
|||||||
#include "player/states/PlayerFall.h"
|
#include "player/states/PlayerFall.h"
|
||||||
|
|
||||||
#include "player/Player.h"
|
#include "player/Player.h"
|
||||||
|
|
||||||
using namespace godot;
|
void alai::player::PlayerFall::_register_methods()
|
||||||
using namespace player;
|
|
||||||
|
|
||||||
void PlayerFall::_register_methods()
|
|
||||||
{
|
{
|
||||||
register_method("_state_enter", &PlayerFall::_state_enter);
|
register_method("_state_enter", &PlayerFall::_state_enter);
|
||||||
register_method("_state_exit", &PlayerFall::_state_exit);
|
register_method("_state_exit", &PlayerFall::_state_exit);
|
||||||
register_method("_physics_process", &PlayerFall::_physics_process);
|
register_method("_physics_process", &PlayerFall::_physics_process);
|
||||||
}
|
}
|
||||||
|
|
||||||
PlayerFall::PlayerFall()
|
alai::player::PlayerFall::PlayerFall()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
PlayerFall::~PlayerFall()
|
alai::player::PlayerFall::~PlayerFall()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void PlayerFall::_init()
|
void alai::player::PlayerFall::_init()
|
||||||
{
|
{
|
||||||
_input = Input::get_singleton();
|
_input = godot::Input::get_singleton();
|
||||||
}
|
}
|
||||||
|
|
||||||
void PlayerFall::_state_enter()
|
void alai::player::PlayerFall::_state_enter()
|
||||||
{
|
{
|
||||||
animated_sprite = get_parent()->get_node<AnimatedSprite>("AnimatedSprite");
|
animated_sprite = get_parent()->get_node<godot::AnimatedSprite>("AnimatedSprite");
|
||||||
animated_sprite->stop();
|
animated_sprite->stop();
|
||||||
animated_sprite->set_animation("air");
|
animated_sprite->set_animation("air");
|
||||||
}
|
}
|
||||||
|
|
||||||
void PlayerFall::_state_exit()
|
void alai::player::PlayerFall::_state_exit()
|
||||||
{
|
{
|
||||||
animated_sprite->set_animation("move");
|
animated_sprite->set_animation("move");
|
||||||
animated_sprite->set_frame(1);
|
animated_sprite->set_frame(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PlayerFall::_physics_process(float delta)
|
void alai::player::PlayerFall::_physics_process(float delta)
|
||||||
{
|
{
|
||||||
auto parent = Object::cast_to<player::Player>(get_parent());
|
auto parent = Object::cast_to<Player>(get_parent());
|
||||||
|
|
||||||
if (parent->is_on_floor())
|
if (parent->is_on_floor())
|
||||||
{
|
{
|
||||||
|
@ -1,13 +1,13 @@
|
|||||||
#ifndef JUEGO_PLAYER_FALL_H
|
#ifndef ALAI_PLAYER_STATES_PLAYER_FALL_H
|
||||||
#define JUEGO_PLAYER_FALL_H
|
#define ALAI_PLAYER_STATES_PLAYER_FALL_H
|
||||||
|
|
||||||
#include "state_machine/State.h"
|
#include "state_machine/State.h"
|
||||||
|
|
||||||
|
#include <AnimatedSprite.hpp>
|
||||||
#include <Godot.hpp>
|
#include <Godot.hpp>
|
||||||
#include <Input.hpp>
|
#include <Input.hpp>
|
||||||
#include <AnimatedSprite.hpp>
|
|
||||||
|
|
||||||
namespace godot
|
namespace alai
|
||||||
{
|
{
|
||||||
namespace player
|
namespace player
|
||||||
{
|
{
|
||||||
@ -24,13 +24,13 @@ namespace godot
|
|||||||
* @brief Input singleton.
|
* @brief Input singleton.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
Input *_input;
|
godot::Input *_input;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief The animated sprite connected to the Player.
|
* @brief The animated sprite connected to the Player.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
AnimatedSprite *animated_sprite;
|
godot::AnimatedSprite *animated_sprite;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
|
@ -1,43 +1,41 @@
|
|||||||
#include "player/states/PlayerIdle.h"
|
#include "player/states/PlayerIdle.h"
|
||||||
|
|
||||||
#include "player/Player.h"
|
#include "player/Player.h"
|
||||||
|
|
||||||
using namespace godot;
|
void alai::player::PlayerIdle::_register_methods()
|
||||||
using namespace player;
|
|
||||||
|
|
||||||
void PlayerIdle::_register_methods()
|
|
||||||
{
|
{
|
||||||
register_method("_state_enter", &PlayerIdle::_state_enter);
|
register_method("_state_enter", &PlayerIdle::_state_enter);
|
||||||
register_method("_state_exit", &PlayerIdle::_state_exit);
|
register_method("_state_exit", &PlayerIdle::_state_exit);
|
||||||
register_method("_physics_process", &PlayerIdle::_physics_process);
|
register_method("_physics_process", &PlayerIdle::_physics_process);
|
||||||
}
|
}
|
||||||
|
|
||||||
PlayerIdle::PlayerIdle()
|
alai::player::PlayerIdle::PlayerIdle()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
PlayerIdle::~PlayerIdle()
|
alai::player::PlayerIdle::~PlayerIdle()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void PlayerIdle::_init()
|
void alai::player::PlayerIdle::_init()
|
||||||
{
|
{
|
||||||
_input = Input::get_singleton();
|
_input = godot::Input::get_singleton();
|
||||||
}
|
}
|
||||||
|
|
||||||
void PlayerIdle::_state_enter()
|
void alai::player::PlayerIdle::_state_enter()
|
||||||
{
|
{
|
||||||
animated_sprite = get_parent()->get_node<AnimatedSprite>("AnimatedSprite");
|
animated_sprite = get_parent()->get_node<godot::AnimatedSprite>("AnimatedSprite");
|
||||||
animated_sprite->stop();
|
animated_sprite->stop();
|
||||||
animated_sprite->set_animation("idle");
|
animated_sprite->set_animation("idle");
|
||||||
}
|
}
|
||||||
|
|
||||||
void PlayerIdle::_state_exit()
|
void alai::player::PlayerIdle::_state_exit()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void PlayerIdle::_physics_process(float delta)
|
void alai::player::PlayerIdle::_physics_process(float delta)
|
||||||
{
|
{
|
||||||
auto parent = Object::cast_to<player::Player>(get_parent());
|
auto parent = Object::cast_to<Player>(get_parent());
|
||||||
|
|
||||||
if (_input->is_action_pressed("right"))
|
if (_input->is_action_pressed("right"))
|
||||||
{
|
{
|
||||||
|
@ -1,14 +1,13 @@
|
|||||||
#ifndef JUEGO_PLAYER_IDLE_H
|
#ifndef ALAI_PLAYER_STATES_PLAYER_IDLE_H
|
||||||
#define JUEGO_PLAYER_IDLE_H
|
#define ALAI_PLAYER_STATES_PLAYER_IDLE_H
|
||||||
|
|
||||||
#include "state_machine/State.h"
|
#include "state_machine/State.h"
|
||||||
|
|
||||||
#include <Godot.hpp>
|
|
||||||
#include <Node.hpp>
|
|
||||||
#include <Input.hpp>
|
|
||||||
#include <AnimatedSprite.hpp>
|
#include <AnimatedSprite.hpp>
|
||||||
|
#include <Godot.hpp>
|
||||||
|
#include <Input.hpp>
|
||||||
|
|
||||||
namespace godot
|
namespace alai
|
||||||
{
|
{
|
||||||
namespace player
|
namespace player
|
||||||
{
|
{
|
||||||
@ -25,12 +24,12 @@ namespace godot
|
|||||||
* @brief Input singleton.
|
* @brief Input singleton.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
Input *_input;
|
godot::Input *_input;
|
||||||
/**
|
/**
|
||||||
* @brief The animated sprite of the Player.
|
* @brief The animated sprite of the Player.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
AnimatedSprite *animated_sprite;
|
godot::AnimatedSprite *animated_sprite;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
|
@ -1,37 +1,35 @@
|
|||||||
#include "player/states/PlayerJump.h"
|
#include "player/states/PlayerJump.h"
|
||||||
|
|
||||||
#include "player/Player.h"
|
#include "player/Player.h"
|
||||||
|
|
||||||
#include <AudioStreamPlayer.hpp>
|
#include <AudioStreamPlayer.hpp>
|
||||||
|
|
||||||
using namespace godot;
|
void alai::player::PlayerJump::_register_methods()
|
||||||
using namespace player;
|
|
||||||
|
|
||||||
void PlayerJump::_register_methods()
|
|
||||||
{
|
{
|
||||||
register_method("_state_enter", &PlayerJump::_state_enter);
|
register_method("_state_enter", &PlayerJump::_state_enter);
|
||||||
register_method("_state_exit", &PlayerJump::_state_exit);
|
register_method("_state_exit", &PlayerJump::_state_exit);
|
||||||
register_method("_physics_process", &PlayerJump::_physics_process);
|
register_method("_physics_process", &PlayerJump::_physics_process);
|
||||||
}
|
}
|
||||||
|
|
||||||
PlayerJump::PlayerJump()
|
alai::player::PlayerJump::PlayerJump()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
PlayerJump::~PlayerJump()
|
alai::player::PlayerJump::~PlayerJump()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void PlayerJump::_init()
|
void alai::player::PlayerJump::_init()
|
||||||
{
|
{
|
||||||
_input = Input::get_singleton();
|
_input = godot::Input::get_singleton();
|
||||||
}
|
}
|
||||||
|
|
||||||
void PlayerJump::_state_enter(const String state)
|
void alai::player::PlayerJump::_state_enter(const godot::String state)
|
||||||
{
|
{
|
||||||
auto jump_sound = get_parent()->get_node<AudioStreamPlayer>("Sounds/Jump");
|
auto jump_sound = get_parent()->get_node<godot::AudioStreamPlayer>("Sounds/Jump");
|
||||||
jump_sound->play();
|
jump_sound->play();
|
||||||
|
|
||||||
animated_sprite = get_parent()->get_node<AnimatedSprite>("AnimatedSprite");
|
animated_sprite = get_parent()->get_node<godot::AnimatedSprite>("AnimatedSprite");
|
||||||
animated_sprite->stop();
|
animated_sprite->stop();
|
||||||
animated_sprite->set_animation("air");
|
animated_sprite->set_animation("air");
|
||||||
|
|
||||||
@ -44,21 +42,21 @@ void PlayerJump::_state_enter(const String state)
|
|||||||
double_jumped = false;
|
double_jumped = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto parent = Object::cast_to<player::Player>(get_parent());
|
auto parent = Object::cast_to<Player>(get_parent());
|
||||||
auto velocity = parent->get_velocity();
|
auto velocity = parent->get_velocity();
|
||||||
velocity.y = -parent->get_jump_force();
|
velocity.y = -parent->get_jump_force();
|
||||||
parent->set_velocity(velocity);
|
parent->set_velocity(velocity);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PlayerJump::_state_exit()
|
void alai::player::PlayerJump::_state_exit()
|
||||||
{
|
{
|
||||||
animated_sprite->set_animation("move");
|
animated_sprite->set_animation("move");
|
||||||
animated_sprite->set_frame(1);
|
animated_sprite->set_frame(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PlayerJump::_physics_process(float delta)
|
void alai::player::PlayerJump::_physics_process(float delta)
|
||||||
{
|
{
|
||||||
auto parent = Object::cast_to<player::Player>(get_parent());
|
auto parent = Object::cast_to<Player>(get_parent());
|
||||||
if (parent->is_on_floor())
|
if (parent->is_on_floor())
|
||||||
{
|
{
|
||||||
get_state_machine()->change("Move");
|
get_state_machine()->change("Move");
|
||||||
|
@ -1,13 +1,13 @@
|
|||||||
#ifndef JUEGO_PLAYER_JUMP_H
|
#ifndef ALAI_PLAYER_STATES_PLAYER_JUMP_H
|
||||||
#define JUEGO_PLAYER_JUMP_H
|
#define ALAI_PLAYER_STATES_PLAYER_JUMP_H
|
||||||
|
|
||||||
#include "state_machine/State.h"
|
#include "state_machine/State.h"
|
||||||
|
|
||||||
|
#include <AnimatedSprite.hpp>
|
||||||
#include <Godot.hpp>
|
#include <Godot.hpp>
|
||||||
#include <Input.hpp>
|
#include <Input.hpp>
|
||||||
#include <AnimatedSprite.hpp>
|
|
||||||
|
|
||||||
namespace godot
|
namespace alai
|
||||||
{
|
{
|
||||||
namespace player
|
namespace player
|
||||||
{
|
{
|
||||||
@ -24,12 +24,12 @@ namespace godot
|
|||||||
* @brief Input singleton.
|
* @brief Input singleton.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
Input *_input;
|
godot::Input *_input;
|
||||||
/**
|
/**
|
||||||
* @brief The animated sprite connected to the Player.
|
* @brief The animated sprite connected to the Player.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
AnimatedSprite *animated_sprite;
|
godot::AnimatedSprite *animated_sprite;
|
||||||
/**
|
/**
|
||||||
* @brief If the player has already performed a double jump or not.
|
* @brief If the player has already performed a double jump or not.
|
||||||
*
|
*
|
||||||
@ -70,7 +70,7 @@ namespace godot
|
|||||||
*
|
*
|
||||||
* @param[in] state The previous state before this one was entered.
|
* @param[in] state The previous state before this one was entered.
|
||||||
*/
|
*/
|
||||||
void _state_enter(const String state);
|
void _state_enter(const godot::String state);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Called when the player exits the jump state.
|
* @brief Called when the player exits the jump state.
|
||||||
|
@ -1,43 +1,41 @@
|
|||||||
#include "player/states/PlayerMove.h"
|
#include "player/states/PlayerMove.h"
|
||||||
|
|
||||||
#include "player/Player.h"
|
#include "player/Player.h"
|
||||||
|
|
||||||
using namespace godot;
|
void alai::player::PlayerMove::_register_methods()
|
||||||
using namespace player;
|
|
||||||
|
|
||||||
void PlayerMove::_register_methods()
|
|
||||||
{
|
{
|
||||||
register_method("_state_enter", &PlayerMove::_state_enter);
|
register_method("_state_enter", &PlayerMove::_state_enter);
|
||||||
register_method("_state_exit", &PlayerMove::_state_exit);
|
register_method("_state_exit", &PlayerMove::_state_exit);
|
||||||
register_method("_physics_process", &PlayerMove::_physics_process);
|
register_method("_physics_process", &PlayerMove::_physics_process);
|
||||||
}
|
}
|
||||||
|
|
||||||
PlayerMove::PlayerMove()
|
alai::player::PlayerMove::PlayerMove()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
PlayerMove::~PlayerMove()
|
alai::player::PlayerMove::~PlayerMove()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void PlayerMove::_init()
|
void alai::player::PlayerMove::_init()
|
||||||
{
|
{
|
||||||
_input = Input::get_singleton();
|
_input = godot::Input::get_singleton();
|
||||||
}
|
}
|
||||||
|
|
||||||
void PlayerMove::_state_enter()
|
void alai::player::PlayerMove::_state_enter()
|
||||||
{
|
{
|
||||||
animated_sprite = get_parent()->get_node<AnimatedSprite>("AnimatedSprite");
|
animated_sprite = get_parent()->get_node<godot::AnimatedSprite>("AnimatedSprite");
|
||||||
animated_sprite->set_animation("move");
|
animated_sprite->set_animation("move");
|
||||||
animated_sprite->play();
|
animated_sprite->play();
|
||||||
}
|
}
|
||||||
|
|
||||||
void PlayerMove::_state_exit()
|
void alai::player::PlayerMove::_state_exit()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void PlayerMove::_physics_process(float delta)
|
void alai::player::PlayerMove::_physics_process(float delta)
|
||||||
{
|
{
|
||||||
auto parent = Object::cast_to<player::Player>(get_parent());
|
auto parent = Object::cast_to<Player>(get_parent());
|
||||||
|
|
||||||
auto direction_pressed = false;
|
auto direction_pressed = false;
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
#ifndef JUEGO_PLAYER_MOVE_H
|
#ifndef ALAI_PLAYER_STATES_PLAYER_MOVE_H
|
||||||
#define JUEGO_PLAYER_MOVE_H
|
#define ALAI_PLAYER_STATES_PLAYER_MOVE_H
|
||||||
|
|
||||||
#include "state_machine/State.h"
|
#include "state_machine/State.h"
|
||||||
|
|
||||||
@ -7,7 +7,7 @@
|
|||||||
#include <Input.hpp>
|
#include <Input.hpp>
|
||||||
#include <AnimatedSprite.hpp>
|
#include <AnimatedSprite.hpp>
|
||||||
|
|
||||||
namespace godot
|
namespace alai
|
||||||
{
|
{
|
||||||
namespace player
|
namespace player
|
||||||
{
|
{
|
||||||
@ -24,12 +24,12 @@ namespace godot
|
|||||||
* @brief Input singleton.
|
* @brief Input singleton.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
Input *_input;
|
godot::Input *_input;
|
||||||
/**
|
/**
|
||||||
* @brief The animated sprite of the Player.
|
* @brief The animated sprite of the Player.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
AnimatedSprite *animated_sprite;
|
godot::AnimatedSprite *animated_sprite;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
#include "state_machine/State.h"
|
#include "state_machine/State.h"
|
||||||
|
|
||||||
using namespace godot;
|
void alai::State::_register_methods()
|
||||||
|
|
||||||
void State::_register_methods()
|
|
||||||
{
|
{
|
||||||
register_method("set_parent", &State::set_parent);
|
register_method("set_parent", &State::set_parent);
|
||||||
register_method("get_parent", &State::get_parent);
|
register_method("get_parent", &State::get_parent);
|
||||||
@ -11,44 +9,44 @@ void State::_register_methods()
|
|||||||
register_method("_state_exit", &State::_state_exit);
|
register_method("_state_exit", &State::_state_exit);
|
||||||
}
|
}
|
||||||
|
|
||||||
State::State()
|
alai::State::State()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
State::~State()
|
alai::State::~State()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void State::_init()
|
void alai::State::_init()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void State::_state_enter(const String state, const Array args)
|
void alai::State::_state_enter(const godot::String state, const godot::Array args)
|
||||||
{
|
{
|
||||||
WARN_PRINT("State " + get_state_machine()->get_current_state() + " is missing its _state_enter method!");
|
WARN_PRINT("State " + get_state_machine()->get_current_state() + " is missing its _state_enter method!");
|
||||||
}
|
}
|
||||||
|
|
||||||
void State::_state_exit(const String state, const Array args)
|
void alai::State::_state_exit(const godot::String state, const godot::Array args)
|
||||||
{
|
{
|
||||||
WARN_PRINT("State " + get_state_machine()->get_current_state() + " is missing its _state_exit method!");
|
WARN_PRINT("State " + get_state_machine()->get_current_state() + " is missing its _state_exit method!");
|
||||||
}
|
}
|
||||||
|
|
||||||
void State::set_parent(Node *parent)
|
void alai::State::set_parent(Node *parent)
|
||||||
{
|
{
|
||||||
this->parent = parent;
|
this->parent = parent;
|
||||||
}
|
}
|
||||||
|
|
||||||
Node *State::get_parent()
|
godot::Node *alai::State::get_parent()
|
||||||
{
|
{
|
||||||
return parent;
|
return parent;
|
||||||
}
|
}
|
||||||
|
|
||||||
void State::set_state_machine(StateMachine *state_machine)
|
void alai::State::set_state_machine(alai::StateMachine *state_machine)
|
||||||
{
|
{
|
||||||
this->state_machine = state_machine;
|
this->state_machine = state_machine;
|
||||||
}
|
}
|
||||||
|
|
||||||
StateMachine *State::get_state_machine()
|
alai::StateMachine *alai::State::get_state_machine()
|
||||||
{
|
{
|
||||||
return this->state_machine;
|
return this->state_machine;
|
||||||
}
|
}
|
||||||
|
@ -1,12 +1,11 @@
|
|||||||
#ifndef JUEGO_STATE_H
|
#ifndef ALAI_STATE_MACHINE_STATE_H
|
||||||
#define JUEGO_STATE_H
|
#define ALAI_STATE_MACHINE_STATE_H
|
||||||
|
|
||||||
#include "state_machine/StateMachine.h"
|
#include "state_machine/StateMachine.h"
|
||||||
|
|
||||||
#include <Godot.hpp>
|
#include <Godot.hpp>
|
||||||
#include <Node.hpp>
|
|
||||||
|
|
||||||
namespace godot
|
namespace alai
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @brief This class provides a virtual template state that real states should extend from and override.
|
* @brief This class provides a virtual template state that real states should extend from and override.
|
||||||
@ -21,7 +20,7 @@ namespace godot
|
|||||||
* @brief The state's parent, this is the node 1 level above the state machine.
|
* @brief The state's parent, this is the node 1 level above the state machine.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
Node *parent;
|
godot::Node *parent;
|
||||||
/**
|
/**
|
||||||
* @brief The state machine itself, used to handle all state related work.
|
* @brief The state machine itself, used to handle all state related work.
|
||||||
*
|
*
|
||||||
@ -61,7 +60,7 @@ namespace godot
|
|||||||
* @param[in] state This will contain the previous state.
|
* @param[in] state This will contain the previous state.
|
||||||
* @param[in] args The arguments passed to the state.
|
* @param[in] args The arguments passed to the state.
|
||||||
*/
|
*/
|
||||||
virtual void _state_enter(const String state, const Array args = Array());
|
virtual void _state_enter(const godot::String state, const godot::Array args = godot::Array());
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief This is called when a state is exited.
|
* @brief This is called when a state is exited.
|
||||||
@ -69,14 +68,14 @@ namespace godot
|
|||||||
* @param[in] state The state we are going to.
|
* @param[in] state The state we are going to.
|
||||||
* @param[in] args The arguments passed to the state.
|
* @param[in] args The arguments passed to the state.
|
||||||
*/
|
*/
|
||||||
virtual void _state_exit(const String state, const Array args = Array());
|
virtual void _state_exit(const godot::String state, const godot::Array args = godot::Array());
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Set the parent object.
|
* @brief Set the parent object.
|
||||||
*
|
*
|
||||||
* @param[in] parent The parent of the state.
|
* @param[in] parent The parent of the state.
|
||||||
*/
|
*/
|
||||||
virtual void set_parent(Node *parent) final;
|
virtual void set_parent(godot::Node *parent) final;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Get the parent object.
|
* @brief Get the parent object.
|
||||||
|
@ -1,35 +1,34 @@
|
|||||||
#include "state_machine/StateMachine.h"
|
#include "state_machine/StateMachine.h"
|
||||||
|
|
||||||
#include "state_machine/State.h"
|
#include "state_machine/State.h"
|
||||||
|
|
||||||
using namespace godot;
|
void alai::StateMachine::_register_methods()
|
||||||
|
|
||||||
void StateMachine::_register_methods()
|
|
||||||
{
|
{
|
||||||
register_method("_ready", &StateMachine::_ready);
|
godot::register_method("_ready", &StateMachine::_ready);
|
||||||
register_method("_on_StateMachine_tree_entered", &StateMachine::_on_StateMachine_tree_entered);
|
godot::register_method("_on_StateMachine_tree_entered", &StateMachine::_on_StateMachine_tree_entered);
|
||||||
register_method("_on_StateMachine_tree_exiting", &StateMachine::_on_StateMachine_tree_exiting);
|
godot::register_method("_on_StateMachine_tree_exiting", &StateMachine::_on_StateMachine_tree_exiting);
|
||||||
register_property<StateMachine, String>("default_state", &StateMachine::set_default_state, &StateMachine::get_default_state, String());
|
godot::register_property<StateMachine, godot::String>("default_state", &StateMachine::set_default_state, &StateMachine::get_default_state, godot::String());
|
||||||
register_property<StateMachine, bool>("debug", &StateMachine::set_debug, &StateMachine::get_debug, false);
|
godot::register_property<StateMachine, bool>("debug", &StateMachine::set_debug, &StateMachine::get_debug, false);
|
||||||
register_signal<StateMachine>("state_entered", "state", GODOT_VARIANT_TYPE_STRING);
|
godot::register_signal<StateMachine>("state_entered", "state", GODOT_VARIANT_TYPE_STRING);
|
||||||
register_signal<StateMachine>("state_exited", "state", GODOT_VARIANT_TYPE_STRING);
|
godot::register_signal<StateMachine>("state_exited", "state", GODOT_VARIANT_TYPE_STRING);
|
||||||
register_signal<StateMachine>("state_restarted", "state", GODOT_VARIANT_TYPE_STRING);
|
godot::register_signal<StateMachine>("state_restarted", "state", GODOT_VARIANT_TYPE_STRING);
|
||||||
}
|
}
|
||||||
|
|
||||||
StateMachine::StateMachine()
|
alai::StateMachine::StateMachine()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
StateMachine::~StateMachine()
|
alai::StateMachine::~StateMachine()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void StateMachine::_init()
|
void alai::StateMachine::_init()
|
||||||
{
|
{
|
||||||
set_default_state(String());
|
set_default_state(godot::String());
|
||||||
set_debug(false);
|
set_debug(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
void StateMachine::_ready()
|
void alai::StateMachine::_ready()
|
||||||
{
|
{
|
||||||
connect("tree_entered", this, "_on_StateMachine_tree_entered");
|
connect("tree_entered", this, "_on_StateMachine_tree_entered");
|
||||||
connect("tree_exiting", this, "_on_StateMachine_tree_exiting");
|
connect("tree_exiting", this, "_on_StateMachine_tree_exiting");
|
||||||
@ -46,7 +45,7 @@ void StateMachine::_ready()
|
|||||||
setup();
|
setup();
|
||||||
}
|
}
|
||||||
|
|
||||||
void StateMachine::setup()
|
void alai::StateMachine::setup()
|
||||||
{
|
{
|
||||||
auto children = get_children();
|
auto children = get_children();
|
||||||
|
|
||||||
@ -89,7 +88,7 @@ void StateMachine::setup()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void StateMachine::add_states()
|
void alai::StateMachine::add_states()
|
||||||
{
|
{
|
||||||
auto children = get_children();
|
auto children = get_children();
|
||||||
for (uint8_t i = 0; i < children.size(); i++)
|
for (uint8_t i = 0; i < children.size(); i++)
|
||||||
@ -99,12 +98,12 @@ void StateMachine::add_states()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void StateMachine::add_state(const String state, Node *child)
|
void alai::StateMachine::add_state(const godot::String state, Node *child)
|
||||||
{
|
{
|
||||||
states[state] = child;
|
states[state] = child;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool StateMachine::is_current(const String state)
|
bool alai::StateMachine::is_current(const godot::String state)
|
||||||
{
|
{
|
||||||
if (get_current_state() == "")
|
if (get_current_state() == "")
|
||||||
{
|
{
|
||||||
@ -116,19 +115,19 @@ bool StateMachine::is_current(const String state)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool StateMachine::has(const String state)
|
bool alai::StateMachine::has(const godot::String state)
|
||||||
{
|
{
|
||||||
return states.has(state);
|
return states.has(state);
|
||||||
}
|
}
|
||||||
|
|
||||||
void StateMachine::restart(const String state, const Array& args)
|
void alai::StateMachine::restart(const godot::String state, const godot::Array& args)
|
||||||
{
|
{
|
||||||
this->call("_state_exit", state, args);
|
this->call("_state_exit", state, args);
|
||||||
this->call("_state_enter", state, args);
|
this->call("_state_enter", state, args);
|
||||||
this->emit_signal("state_restarted", get_current_state());
|
this->emit_signal("state_restarted", get_current_state());
|
||||||
}
|
}
|
||||||
|
|
||||||
void StateMachine::change(const String state, const Array &args)
|
void alai::StateMachine::change(const godot::String state, const godot::Array &args)
|
||||||
{
|
{
|
||||||
if (is_current(state))
|
if (is_current(state))
|
||||||
{
|
{
|
||||||
@ -143,7 +142,7 @@ void StateMachine::change(const String state, const Array &args)
|
|||||||
|
|
||||||
auto previous_state = get_current_state();
|
auto previous_state = get_current_state();
|
||||||
|
|
||||||
Variant exiting;
|
godot::Variant exiting;
|
||||||
Node *state_node = Object::cast_to<Node>(this->states[previous_state]);
|
Node *state_node = Object::cast_to<Node>(this->states[previous_state]);
|
||||||
if (state_node)
|
if (state_node)
|
||||||
{
|
{
|
||||||
@ -171,7 +170,7 @@ void StateMachine::change(const String state, const Array &args)
|
|||||||
this->emit_signal("state_exited", get_current_state());
|
this->emit_signal("state_exited", get_current_state());
|
||||||
if (debug)
|
if (debug)
|
||||||
{
|
{
|
||||||
Godot::print(get_current_state() + " exited!");
|
godot::Godot::print(get_current_state() + " exited!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -199,11 +198,11 @@ void StateMachine::change(const String state, const Array &args)
|
|||||||
this->emit_signal("state_entered", get_current_state());
|
this->emit_signal("state_entered", get_current_state());
|
||||||
if (debug)
|
if (debug)
|
||||||
{
|
{
|
||||||
Godot::print(get_current_state() + " entered!");
|
godot::Godot::print(get_current_state() + " entered!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Variant StateMachine::call(const String method, const Array &args)
|
godot::Variant alai::StateMachine::call(const godot::String method, const godot::Array &args)
|
||||||
{
|
{
|
||||||
auto node = Object::cast_to<Node>(states[get_current_state()].operator Object*());
|
auto node = Object::cast_to<Node>(states[get_current_state()].operator Object*());
|
||||||
if (node)
|
if (node)
|
||||||
@ -215,57 +214,57 @@ Variant StateMachine::call(const String method, const Array &args)
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
WARN_PRINT("The state " + get_current_state() + " doesn't contain the method " + method + "!");
|
WARN_PRINT("The state " + get_current_state() + " doesn't contain the method " + method + "!");
|
||||||
return Variant();
|
return godot::Variant();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ERR_PRINT("Could not get current state node for " + get_current_state() + "!");
|
ERR_PRINT("Could not get current state node for " + get_current_state() + "!");
|
||||||
return Variant();
|
return godot::Variant();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Variant StateMachine::_call(const String method, const Array &args)
|
godot::Variant alai::StateMachine::_call(const godot::String method, const godot::Array &args)
|
||||||
{
|
{
|
||||||
return this->call(method, args);
|
return this->call(method, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
void StateMachine::set_default_state(const String default_state)
|
void alai::StateMachine::set_default_state(const godot::String default_state)
|
||||||
{
|
{
|
||||||
this->default_state = default_state;
|
this->default_state = default_state;
|
||||||
}
|
}
|
||||||
|
|
||||||
String StateMachine::get_default_state()
|
godot::String alai::StateMachine::get_default_state()
|
||||||
{
|
{
|
||||||
return this->default_state;
|
return this->default_state;
|
||||||
}
|
}
|
||||||
|
|
||||||
void StateMachine::set_current_state(const String current_sate)
|
void alai::StateMachine::set_current_state(const godot::String current_sate)
|
||||||
{
|
{
|
||||||
this->current_state = current_sate;
|
this->current_state = current_sate;
|
||||||
}
|
}
|
||||||
|
|
||||||
String StateMachine::get_current_state()
|
godot::String alai::StateMachine::get_current_state()
|
||||||
{
|
{
|
||||||
return this->current_state;
|
return this->current_state;
|
||||||
}
|
}
|
||||||
|
|
||||||
void StateMachine::set_debug(bool debug)
|
void alai::StateMachine::set_debug(bool debug)
|
||||||
{
|
{
|
||||||
this->debug = debug;
|
this->debug = debug;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool StateMachine::get_debug()
|
bool alai::StateMachine::get_debug()
|
||||||
{
|
{
|
||||||
return this->debug;
|
return this->debug;
|
||||||
}
|
}
|
||||||
|
|
||||||
void StateMachine::_on_StateMachine_tree_entered()
|
void alai::StateMachine::_on_StateMachine_tree_entered()
|
||||||
{
|
{
|
||||||
setup();
|
setup();
|
||||||
}
|
}
|
||||||
|
|
||||||
void StateMachine::_on_StateMachine_tree_exiting()
|
void alai::StateMachine::_on_StateMachine_tree_exiting()
|
||||||
{
|
{
|
||||||
auto keys = states.keys();
|
auto keys = states.keys();
|
||||||
for (uint8_t i = 0; i < keys.size(); i++)
|
for (uint8_t i = 0; i < keys.size(); i++)
|
||||||
|
@ -1,32 +1,32 @@
|
|||||||
#ifndef JUEGO_STATE_MACHINE_H
|
#ifndef ALAI_STATE_MACHINE_STATE_MACHINE_H
|
||||||
#define JUEGO_STATE_MACHINE_H
|
#define ALAI_STATE_MACHINE_STATE_MACHINE_H
|
||||||
|
|
||||||
#include <Godot.hpp>
|
#include <Godot.hpp>
|
||||||
#include <Node.hpp>
|
#include <Node.hpp>
|
||||||
|
|
||||||
namespace godot
|
namespace alai
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @brief This class provides a finite state machine that can be used with any scene and node.
|
* @brief This class provides a finite state machine that can be used with any scene and node.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
class StateMachine : public Node
|
class StateMachine : public godot::Node
|
||||||
{
|
{
|
||||||
GODOT_CLASS(StateMachine, Node)
|
GODOT_CLASS(StateMachine, godot::Node)
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/**
|
/**
|
||||||
* @brief The parent node which is one level above the state machine.
|
* @brief The parent node which is one level above the state machine.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
Node *parent;
|
godot::Node *parent;
|
||||||
/**
|
/**
|
||||||
* @brief The default state for the state machine to run.
|
* @brief The default state for the state machine to run.
|
||||||
*
|
*
|
||||||
* @details If this is not set, the state machine will try to run the first state node.
|
* @details If this is not set, the state machine will try to run the first state node.
|
||||||
* If no state nodes are present, an error will be printed and the state machine will not work.
|
* If no state nodes are present, an error will be printed and the state machine will not work.
|
||||||
*/
|
*/
|
||||||
String default_state;
|
godot::String default_state;
|
||||||
/**
|
/**
|
||||||
* @brief If set to true the state machine will print a message showing when it enters or exits a state.
|
* @brief If set to true the state machine will print a message showing when it enters or exits a state.
|
||||||
*
|
*
|
||||||
@ -36,12 +36,12 @@ namespace godot
|
|||||||
* @brief The current state the machine is in.
|
* @brief The current state the machine is in.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
String current_state;
|
godot::String current_state;
|
||||||
/**
|
/**
|
||||||
* @brief A list of the states in the state machine.
|
* @brief A list of the states in the state machine.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
Dictionary states;
|
godot::Dictionary states;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief This adds all nodes of the states machine as states in the machine.
|
* @brief This adds all nodes of the states machine as states in the machine.
|
||||||
@ -55,14 +55,14 @@ namespace godot
|
|||||||
* @param[in] state The new state.
|
* @param[in] state The new state.
|
||||||
* @param[in] child The godot node which represents the state.
|
* @param[in] child The godot node which represents the state.
|
||||||
*/
|
*/
|
||||||
void add_state(const String state, Node *child);
|
void add_state(const godot::String state, godot::Node *child);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Set the current state object.
|
* @brief Set the current state object.
|
||||||
*
|
*
|
||||||
* @param[in] current_state The current state that is running.
|
* @param[in] current_state The current state that is running.
|
||||||
*/
|
*/
|
||||||
void set_current_state(const String current_state);
|
void set_current_state(const godot::String current_state);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
@ -109,7 +109,7 @@ namespace godot
|
|||||||
* @return true If the running state and given state are the same.
|
* @return true If the running state and given state are the same.
|
||||||
* @return false If the running state and given state are not the same.
|
* @return false If the running state and given state are not the same.
|
||||||
*/
|
*/
|
||||||
bool is_current(const String state);
|
bool is_current(const godot::String state);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Check if the state machine has a given state.
|
* @brief Check if the state machine has a given state.
|
||||||
@ -118,7 +118,7 @@ namespace godot
|
|||||||
* @return true If the state exists.
|
* @return true If the state exists.
|
||||||
* @return false If the state doesn't exist.
|
* @return false If the state doesn't exist.
|
||||||
*/
|
*/
|
||||||
bool has(const String state);
|
bool has(const godot::String state);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Restar the running state by calling its enter and exit methods.
|
* @brief Restar the running state by calling its enter and exit methods.
|
||||||
@ -126,7 +126,7 @@ namespace godot
|
|||||||
* @param[in] state The state that is being restarted.
|
* @param[in] state The state that is being restarted.
|
||||||
* @param[in] args The arguments to pass to the state on exit and enter.
|
* @param[in] args The arguments to pass to the state on exit and enter.
|
||||||
*/
|
*/
|
||||||
void restart(const String state, const Array& args = Array());
|
void restart(const godot::String state, const godot::Array& args = godot::Array());
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Change to a different state.
|
* @brief Change to a different state.
|
||||||
@ -136,7 +136,7 @@ namespace godot
|
|||||||
* @param[in] state The state to change to.
|
* @param[in] state The state to change to.
|
||||||
* @param[in] args The arguments to pass to the exiting state and the entering state.
|
* @param[in] args The arguments to pass to the exiting state and the entering state.
|
||||||
*/
|
*/
|
||||||
void change(const String state, const Array &args = Array());
|
void change(const godot::String state, const godot::Array &args = godot::Array());
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Call a registered godot method in the class.
|
* @brief Call a registered godot method in the class.
|
||||||
@ -145,7 +145,7 @@ namespace godot
|
|||||||
* @param[in] args The arguments to pass to the method.
|
* @param[in] args The arguments to pass to the method.
|
||||||
* @return Variant Returns a Variant based off what the method returns.
|
* @return Variant Returns a Variant based off what the method returns.
|
||||||
*/
|
*/
|
||||||
Variant call(const String method, const Array &args = Array());
|
godot::Variant call(const godot::String method, const godot::Array &args = godot::Array());
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief This method is to link up a signal call back.
|
* @brief This method is to link up a signal call back.
|
||||||
@ -154,28 +154,28 @@ namespace godot
|
|||||||
* @param[in] args The arguments to pass to the method.
|
* @param[in] args The arguments to pass to the method.
|
||||||
* @return Variant Returns a Variant based off what the method returns.
|
* @return Variant Returns a Variant based off what the method returns.
|
||||||
*/
|
*/
|
||||||
Variant _call(const String method, const Array &args = Array());
|
godot::Variant _call(const godot::String method, const godot::Array &args = godot::Array());
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Set the default state object.
|
* @brief Set the default state object.
|
||||||
*
|
*
|
||||||
* @param[in] default_state The new default state.
|
* @param[in] default_state The new default state.
|
||||||
*/
|
*/
|
||||||
void set_default_state(const String default_state);
|
void set_default_state(const godot::String default_state);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Get the default state object.
|
* @brief Get the default state object.
|
||||||
*
|
*
|
||||||
* @return String The default state.
|
* @return String The default state.
|
||||||
*/
|
*/
|
||||||
String get_default_state();
|
godot::String get_default_state();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Get the current state object.
|
* @brief Get the current state object.
|
||||||
*
|
*
|
||||||
* @return String The current running state.
|
* @return String The current running state.
|
||||||
*/
|
*/
|
||||||
String get_current_state();
|
godot::String get_current_state();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Set the debug object.
|
* @brief Set the debug object.
|
||||||
@ -210,51 +210,51 @@ namespace godot
|
|||||||
/**
|
/**
|
||||||
* @brief Restarts the running state.
|
* @brief Restarts the running state.
|
||||||
*
|
*
|
||||||
* @tparam Args Variable number of arguments to pass to restart.
|
* @param Args Variable number of arguments to pass to restart.
|
||||||
* @param[in] state The state being restarted.
|
* @param[in] state The state being restarted.
|
||||||
* @param[in] args The arguments to pass when restarting.
|
* @param[in] args The arguments to pass when restarting.
|
||||||
*/
|
*/
|
||||||
template <class ...Args> void restart(const String state, Args ...args)
|
template <class ...Args> void restart(const godot::String state, Args ...args)
|
||||||
{
|
{
|
||||||
return restart(state, Array::make(args...));
|
return restart(state, godot::Array::make(args...));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Changes to a new state.
|
* @brief Changes to a new state.
|
||||||
*
|
*
|
||||||
* @tparam Args Variable number of arguments to pass when chaning states.
|
* @param Args Variable number of arguments to pass when changing states.
|
||||||
* @param[in] state The state to change to.
|
* @param[in] state The state to change to.
|
||||||
* @param[in] args The arguments to pass to the new state.
|
* @param[in] args The arguments to pass to the new state.
|
||||||
*/
|
*/
|
||||||
template <class ...Args> void change(const String state, Args ...args)
|
template <class ...Args> void change(const godot::String state, Args ...args)
|
||||||
{
|
{
|
||||||
return change(state, Array::make(args...));
|
return change(state, godot::Array::make(args...));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Call a registered godot method in the class.
|
* @brief Call a registered godot method in the class.
|
||||||
*
|
*
|
||||||
* @tparam Args The variable arguments to pass to the method.
|
* @param Args The variable arguments to pass to the method.
|
||||||
* @param[in] method The method to call.
|
* @param[in] method The method to call.
|
||||||
* @param[in] args The arguments to pass to it.
|
* @param[in] args The arguments to pass to it.
|
||||||
* @return Variant The Variant object returned by the method called.
|
* @return Variant The Variant object returned by the method called.
|
||||||
*/
|
*/
|
||||||
template <class ...Args> Variant call(const String method, Args ...args)
|
template <class ...Args> godot::Variant call(const godot::String method, Args ...args)
|
||||||
{
|
{
|
||||||
return call(method, Array::make(args...));
|
return call(method, godot::Array::make(args...));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief This is used to connect a callback from a signal.
|
* @brief This is used to connect a callback from a signal.
|
||||||
*
|
*
|
||||||
* @tparam Args The arguments to pass to the callback method.
|
* @param Args The arguments to pass to the callback method.
|
||||||
* @param[in] method The method to call.
|
* @param[in] method The method to call.
|
||||||
* @param[in] args The arguments to pass.
|
* @param[in] args The arguments to pass.
|
||||||
* @return Variant The Variant object returned by the method called.
|
* @return Variant The Variant object returned by the method called.
|
||||||
*/
|
*/
|
||||||
template <class ...Args> Variant _call(const String method, Args ...args)
|
template <class ...Args> godot::Variant _call(const godot::String method, Args ...args)
|
||||||
{
|
{
|
||||||
return _call(method, Array::make(args...));
|
return _call(method, godot::Array::make(args...));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user