feat: added exit door and trigger

This commit is contained in:
Sara 2024-05-21 15:59:04 +02:00
parent 6d71c7ee9d
commit 94be550654
5 changed files with 76 additions and 0 deletions

18
src/exit_door.cpp Normal file
View file

@ -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>("AnimationPlayer");
Ref<RallyRushGameMode>(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");
}
}

19
src/exit_door.hpp Normal file
View file

@ -0,0 +1,19 @@
#ifndef EXIT_DOOR_HPP
#define EXIT_DOOR_HPP
#include "godot_cpp/classes/animation_player.hpp"
#include <godot_cpp/classes/node3d.hpp>
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

19
src/exit_trigger.cpp Normal file
View file

@ -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<RallyRushGameMode> game_mode{GameRoot3D::get_singleton()->get_game_mode()};
if(game_mode->get_num_found_keys() == 3)
game_mode->notify_player_escaped();
}
}

16
src/exit_trigger.hpp Normal file
View file

@ -0,0 +1,16 @@
#ifndef EXIT_TRIGGER_HPP
#define EXIT_TRIGGER_HPP
#include <godot_cpp/classes/area3d.hpp>
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

View file

@ -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<EndScreen>();
ClassDB::register_class<Turret>();
ClassDB::register_class<Beam>();
ClassDB::register_class<ExitDoor>();
ClassDB::register_class<ExitTrigger>();
}
extern "C"