From 5cf006e4d7545efce7ff0b6ea16f6ded71d8efad Mon Sep 17 00:00:00 2001 From: Sara Date: Fri, 17 May 2024 15:09:23 +0200 Subject: [PATCH] feat: added rally rush gamemode class --- src/rally_rush_game_mode.cpp | 21 +++++++++++++++++++++ src/rally_rush_game_mode.hpp | 18 ++++++++++++++++++ src/register_types.cpp | 2 ++ 3 files changed, 41 insertions(+) create mode 100644 src/rally_rush_game_mode.cpp create mode 100644 src/rally_rush_game_mode.hpp diff --git a/src/rally_rush_game_mode.cpp b/src/rally_rush_game_mode.cpp new file mode 100644 index 0000000..78f0fad --- /dev/null +++ b/src/rally_rush_game_mode.cpp @@ -0,0 +1,21 @@ +#include "rally_rush_game_mode.hpp" +#include "utils/godot_macros.h" + +namespace godot { +void RallyRushGameMode::_bind_methods() { +#define CLASSNAME RallyRushGameMode + GDSIGNAL("key_found", PropertyInfo(Variant::INT, "total_found")); + GDSIGNAL("all_keys_found"); +} + +int RallyRushGameMode::get_num_found_keys() { + return this->num_keys_found; +} + +void RallyRushGameMode::notify_key_found() { + ++this->num_keys_found; + this->emit_signal("key_found", num_keys_found); + if(num_keys_found == 3) + this->emit_signal("all_keys_found"); +} +} diff --git a/src/rally_rush_game_mode.hpp b/src/rally_rush_game_mode.hpp new file mode 100644 index 0000000..f8c5f0d --- /dev/null +++ b/src/rally_rush_game_mode.hpp @@ -0,0 +1,18 @@ +#ifndef RALLY_RUSH_GAME_MODE_HPP +#define RALLY_RUSH_GAME_MODE_HPP + +#include "utils/game_mode.hpp" + +namespace godot { +class RallyRushGameMode : public GameMode { + GDCLASS(RallyRushGameMode, GameMode); + static void _bind_methods(); +public: + int get_num_found_keys(); + void notify_key_found(); +private: + int num_keys_found{0}; +}; +} + +#endif // !RALLY_RUSH_GAME_MODE_HPP diff --git a/src/register_types.cpp b/src/register_types.cpp index 113767f..cb22453 100644 --- a/src/register_types.cpp +++ b/src/register_types.cpp @@ -1,6 +1,7 @@ #include "register_types.h" #include "car_physics.hpp" #include "car_player.hpp" +#include "rally_rush_game_mode.hpp" #include "utils/game_mode.hpp" #include "utils/game_root.hpp" #include "utils/game_state.hpp" @@ -28,6 +29,7 @@ void initialize_gdextension_types(ModuleInitializationLevel p_level) ClassDB::register_class(); ClassDB::register_class(); + ClassDB::register_class(); } extern "C"