diff --git a/src/exit_door.cpp b/src/exit_door.cpp new file mode 100644 index 0000000..7f4cfeb --- /dev/null +++ b/src/exit_door.cpp @@ -0,0 +1,18 @@ +#include "exit_door.hpp" +#include "rally_rush_game_mode.hpp" +#include "utils/game_root.hpp" + +namespace godot { +void ExitDoor::_bind_methods() { +#define CLASSNAME ExitDoor +} + +void ExitDoor::_enter_tree() { + this->player = this->get_node("AnimationPlayer"); + Ref(GameRoot3D::get_singleton()->get_game_mode())->connect("all_keys_found", callable_mp(this, &ExitDoor::all_keys_found)); +} + +void ExitDoor::all_keys_found() { + this->player->play("open"); +} +} diff --git a/src/exit_door.hpp b/src/exit_door.hpp new file mode 100644 index 0000000..01c9eb5 --- /dev/null +++ b/src/exit_door.hpp @@ -0,0 +1,19 @@ +#ifndef EXIT_DOOR_HPP +#define EXIT_DOOR_HPP + +#include "godot_cpp/classes/animation_player.hpp" +#include + +namespace godot { +class ExitDoor : public Node3D { + GDCLASS(ExitDoor, Node3D); + static void _bind_methods(); +public: + virtual void _enter_tree() override; + void all_keys_found(); +private: + AnimationPlayer *player{nullptr}; +}; +} + +#endif // !EXIT_DOOR_HPP diff --git a/src/exit_trigger.cpp b/src/exit_trigger.cpp new file mode 100644 index 0000000..e40171d --- /dev/null +++ b/src/exit_trigger.cpp @@ -0,0 +1,19 @@ +#include "exit_trigger.hpp" +#include "rally_rush_game_mode.hpp" +#include "utils/game_root.hpp" + +namespace godot { +void ExitTrigger::_bind_methods() { +#define CLASSNAME ExitTrigger +} + +void ExitTrigger::_enter_tree() { + this->connect("body_entered", callable_mp(this, &ExitTrigger::body_entered)); +} + +void ExitTrigger::body_entered(Node3D *node) { + Ref game_mode{GameRoot3D::get_singleton()->get_game_mode()}; + if(game_mode->get_num_found_keys() == 3) + game_mode->notify_player_escaped(); +} +} diff --git a/src/exit_trigger.hpp b/src/exit_trigger.hpp new file mode 100644 index 0000000..6e1caaf --- /dev/null +++ b/src/exit_trigger.hpp @@ -0,0 +1,16 @@ +#ifndef EXIT_TRIGGER_HPP +#define EXIT_TRIGGER_HPP + +#include + +namespace godot { +class ExitTrigger : public Area3D { + GDCLASS(ExitTrigger, Area3D); + static void _bind_methods(); +public: + virtual void _enter_tree() override; + void body_entered(Node3D *node); +}; +} + +#endif // !EXIT_TRIGGER_HPP diff --git a/src/register_types.cpp b/src/register_types.cpp index 48139ff..3c721d7 100644 --- a/src/register_types.cpp +++ b/src/register_types.cpp @@ -3,6 +3,8 @@ #include "car_physics.hpp" #include "car_player.hpp" #include "end_screen.hpp" +#include "exit_door.hpp" +#include "exit_trigger.hpp" #include "game_ui.hpp" #include "key_pickup.hpp" #include "menu_ui.hpp" @@ -42,6 +44,8 @@ void initialize_gdextension_types(ModuleInitializationLevel p_level) ClassDB::register_class(); ClassDB::register_class(); ClassDB::register_class(); + ClassDB::register_class(); + ClassDB::register_class(); } extern "C"