feat: rifle pickup added to map
This commit is contained in:
parent
2511ac69c0
commit
6b7a092961
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
[gd_scene load_steps=31 format=4 uid="uid://dllho5nkq2smw"]
|
||||
[gd_scene load_steps=32 format=4 uid="uid://dllho5nkq2smw"]
|
||||
|
||||
[ext_resource type="PackedScene" uid="uid://eu0yil2ylm0q" path="res://objects/props/box_car_fully_enclosed.tscn" id="1_ti8jp"]
|
||||
[ext_resource type="PackedScene" uid="uid://hf7yyyiep30l" path="res://objects/props/box_car_enclosed.tscn" id="2_cfpv2"]
|
||||
|
@ -12,6 +12,7 @@
|
|||
[ext_resource type="PackedScene" uid="uid://22j1too6rheq" path="res://objects/props/sand_bag_half_circle.tscn" id="9_ug5on"]
|
||||
[ext_resource type="PackedScene" uid="uid://cclghy01gblif" path="res://objects/pickups/demo_pack_pickup.tscn" id="11_foo0w"]
|
||||
[ext_resource type="PackedScene" uid="uid://5hg5eirw7v8n" path="res://objects/units/unit_4_wretched.tscn" id="12_plog7"]
|
||||
[ext_resource type="PackedScene" uid="uid://crml35t12hx2h" path="res://objects/pickups/weapon_pickup.tscn" id="13_qwrat"]
|
||||
|
||||
[sub_resource type="GDScript" id="GDScript_ug5on"]
|
||||
script/source = "extends Interactable
|
||||
|
@ -802,3 +803,6 @@ use_collision = true
|
|||
collision_layer = 19
|
||||
collision_mask = 0
|
||||
size = Vector3(5.7617188, 4.102051, 0.33398438)
|
||||
|
||||
[node name="WeaponPickup" parent="." instance=ExtResource("13_qwrat")]
|
||||
transform = Transform3D(-4.371139e-08, 0, 1, 0, 1, 0, -1, 0, -4.371139e-08, -17.444277, 0.05698805, -22.7964)
|
||||
|
|
|
@ -17,7 +17,7 @@ func _on_health_status_death() -> void:
|
|||
radius = 0.26953125
|
||||
|
||||
[node name="EnemyWretched" type="EnemyWretched"]
|
||||
chase_speed = 4.0
|
||||
chase_speed = 7.0
|
||||
script = SubResource("GDScript_qot2n")
|
||||
|
||||
[node name="wretched" parent="." instance=ExtResource("1_qot2n")]
|
||||
|
|
39
project/objects/pickups/weapon_pickup.tscn
Normal file
39
project/objects/pickups/weapon_pickup.tscn
Normal file
|
@ -0,0 +1,39 @@
|
|||
[gd_scene load_steps=5 format=3 uid="uid://crml35t12hx2h"]
|
||||
|
||||
[ext_resource type="PackedScene" uid="uid://ce40pq785yoyi" path="res://objects/weapons/rifle.tscn" id="1_y6dn2"]
|
||||
|
||||
[sub_resource type="GDScript" id="GDScript_fn0cd"]
|
||||
script/source = "extends Interactable
|
||||
|
||||
@export var weapon_name : String = \"Rifle\"
|
||||
@export var weapon_scene : PackedScene
|
||||
|
||||
func _highlight_changed(_interactor: PlayerInteractor, value: bool) -> void:
|
||||
var hud := HeadsUpDisplay.get_singleton()
|
||||
if hud:
|
||||
hud.set_tooltip(\"Pick up %s\" % weapon_name if value else \"\")
|
||||
|
||||
func _activated(interactor: PlayerInteractor) -> void:
|
||||
interactor.get_inventory().pickup_weapon(weapon_scene)
|
||||
get_parent().queue_free()
|
||||
"
|
||||
|
||||
[sub_resource type="BoxMesh" id="BoxMesh_fn0cd"]
|
||||
size = Vector3(0.2, 0.1, 0.7)
|
||||
|
||||
[sub_resource type="BoxShape3D" id="BoxShape3D_fn0cd"]
|
||||
size = Vector3(0.20874023, 0.115478516, 0.7109375)
|
||||
|
||||
[node name="WeaponPickup" type="StaticBody3D"]
|
||||
collision_layer = 16
|
||||
collision_mask = 0
|
||||
|
||||
[node name="Interactable" type="Interactable" parent="."]
|
||||
script = SubResource("GDScript_fn0cd")
|
||||
weapon_scene = ExtResource("1_y6dn2")
|
||||
|
||||
[node name="MeshInstance3D" type="MeshInstance3D" parent="."]
|
||||
mesh = SubResource("BoxMesh_fn0cd")
|
||||
|
||||
[node name="CollisionShape3D" type="CollisionShape3D" parent="."]
|
||||
shape = SubResource("BoxShape3D_fn0cd")
|
|
@ -9,7 +9,7 @@ radius = 0.2
|
|||
script/source = "extends HealthStatus
|
||||
|
||||
func _on_death() -> void:
|
||||
get_tree().change_scene_to_file.call_deferred(\"res://menus/main_menu.tscn\")
|
||||
get_tree().change_scene_to_file.call_deferred(\"res://guis/main_menu.tscn\")
|
||||
"
|
||||
|
||||
[sub_resource type="CapsuleShape3D" id="CapsuleShape3D_bxedw"]
|
||||
|
|
Loading…
Reference in a new issue