feat: rifle pickup added to map

This commit is contained in:
Sara 2025-08-11 16:10:16 +02:00
parent 2511ac69c0
commit 6b7a092961
8 changed files with 57 additions and 6 deletions

View file

@ -2,10 +2,12 @@
#include "interactable.h"
#include "player_body.h"
#include "player_input.h"
#include "weapon_inventory.h"
void PlayerInteractor::_bind_methods() {
ClassDB::bind_method(D_METHOD("pickup_demo_pack"), &self_type::pickup_demo_pack);
ClassDB::bind_method(D_METHOD("try_use_demo_pack"), &self_type::try_use_demo_pack);
ClassDB::bind_method(D_METHOD("get_inventory"), &self_type::get_inventory);
}
void PlayerInteractor::highlight_removed() {
@ -23,6 +25,7 @@ void PlayerInteractor::activate() {
void PlayerInteractor::ready() {
PlayerInput *input{ cast_to<PlayerInput>(get_node(NodePath("%PlayerInput"))) };
input->connect(PlayerInput::sig_activate, callable_mp(this, &self_type::activate));
this->inventory = cast_to<WeaponInventory>(get_node(NodePath("%WeaponInventory")));
}
void PlayerInteractor::process(double delta) {
@ -85,3 +88,7 @@ bool PlayerInteractor::try_use_demo_pack() {
}
return false;
}
WeaponInventory *PlayerInteractor::get_inventory() const {
return this->inventory;
}

View file

@ -3,6 +3,7 @@
#include "scene/3d/physics/shape_cast_3d.h"
class Interactable;
class WeaponInventory;
class PlayerInteractor : public ShapeCast3D {
GDCLASS(PlayerInteractor, ShapeCast3D);
@ -19,11 +20,13 @@ public:
virtual PackedStringArray get_configuration_warnings() const override;
void pickup_demo_pack();
bool try_use_demo_pack();
WeaponInventory *get_inventory() const;
private:
int num_demo_packs{ 0 };
Interactable *interactable{ nullptr };
Callable on_highlight_removed{ callable_mp(this, &self_type::highlight_removed) };
WeaponInventory *inventory{ nullptr };
static String activate_method_name;
};

View file

@ -6,6 +6,7 @@ void WeaponInventory::_bind_methods() {
BIND_HPROPERTY(Variant::OBJECT, starting_weapon, PROPERTY_HINT_RESOURCE_TYPE, "PackedScene");
BIND_PROPERTY(Variant::INT, pistol_ammo);
BIND_PROPERTY(Variant::INT, rifle_ammo);
ClassDB::bind_method(D_METHOD("pickup_weapon"), &self_type::pickup_weapon);
}
void WeaponInventory::on_switch_input() {

View file

@ -25,9 +25,6 @@ public:
void set_starting_weapon(Ref<PackedScene> weapon_scene);
Ref<PackedScene> get_starting_weapon() const;
void pickup_demo_pack();
bool try_use_demo_pack();
void deposit_pistol_ammo(int amount);
void set_pistol_ammo(int amount);
int get_pistol_ammo() const;