feat: defined Key Pickup class
This commit is contained in:
parent
9a783a13fe
commit
3ec14aef92
21
src/key_pickup.cpp
Normal file
21
src/key_pickup.cpp
Normal file
|
@ -0,0 +1,21 @@
|
|||
#include "key_pickup.hpp"
|
||||
#include "car_player.hpp"
|
||||
#include "rally_rush_game_mode.hpp"
|
||||
#include "utils/game_root.hpp"
|
||||
|
||||
namespace godot {
|
||||
void KeyPickup::_bind_methods() {
|
||||
#define CLASSNAME KeyPickup
|
||||
}
|
||||
|
||||
void KeyPickup::_enter_tree() {
|
||||
this->connect("body_entered", callable_mp(this, &KeyPickup::on_body_entered));
|
||||
}
|
||||
|
||||
void KeyPickup::on_body_entered(Node *node) {
|
||||
if(!this->is_queued_for_deletion() && cast_to<CarPlayer>(node) != nullptr) {
|
||||
Ref<RallyRushGameMode>(GameRoot3D::get_singleton()->get_game_mode())->notify_key_found();
|
||||
this->queue_free();
|
||||
}
|
||||
}
|
||||
}
|
17
src/key_pickup.hpp
Normal file
17
src/key_pickup.hpp
Normal file
|
@ -0,0 +1,17 @@
|
|||
#ifndef KEY_PICKUP_HPP
|
||||
#define KEY_PICKUP_HPP
|
||||
|
||||
#include "godot_cpp/classes/area3d.hpp"
|
||||
|
||||
namespace godot {
|
||||
class KeyPickup : public Area3D {
|
||||
GDCLASS(KeyPickup, Area3D);
|
||||
static void _bind_methods();
|
||||
public:
|
||||
virtual void _enter_tree() override;
|
||||
protected:
|
||||
void on_body_entered(Node *node);
|
||||
};
|
||||
}
|
||||
|
||||
#endif // !KEY_PICKUP_HPP
|
|
@ -1,6 +1,7 @@
|
|||
#include "register_types.h"
|
||||
#include "car_physics.hpp"
|
||||
#include "car_player.hpp"
|
||||
#include "key_pickup.hpp"
|
||||
#include "rally_rush_game_mode.hpp"
|
||||
#include "utils/game_mode.hpp"
|
||||
#include "utils/game_root.hpp"
|
||||
|
@ -30,6 +31,7 @@ void initialize_gdextension_types(ModuleInitializationLevel p_level)
|
|||
ClassDB::register_class<CarPhysics>();
|
||||
ClassDB::register_class<CarPlayer>();
|
||||
ClassDB::register_class<RallyRushGameMode>();
|
||||
ClassDB::register_class<KeyPickup>()
|
||||
}
|
||||
|
||||
extern "C"
|
||||
|
|
Loading…
Reference in a new issue