diff --git a/modules/wave_survival/player_interactor.cpp b/modules/wave_survival/player_interactor.cpp index 755dcfc2..1574cc53 100644 --- a/modules/wave_survival/player_interactor.cpp +++ b/modules/wave_survival/player_interactor.cpp @@ -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(get_node(NodePath("%PlayerInput"))) }; input->connect(PlayerInput::sig_activate, callable_mp(this, &self_type::activate)); + this->inventory = cast_to(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; +} diff --git a/modules/wave_survival/player_interactor.h b/modules/wave_survival/player_interactor.h index 7e6d5ed4..e18b14a1 100644 --- a/modules/wave_survival/player_interactor.h +++ b/modules/wave_survival/player_interactor.h @@ -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; }; diff --git a/modules/wave_survival/weapon_inventory.cpp b/modules/wave_survival/weapon_inventory.cpp index b847bbab..0f76a9bb 100644 --- a/modules/wave_survival/weapon_inventory.cpp +++ b/modules/wave_survival/weapon_inventory.cpp @@ -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() { diff --git a/modules/wave_survival/weapon_inventory.h b/modules/wave_survival/weapon_inventory.h index 6361041d..0b32242a 100644 --- a/modules/wave_survival/weapon_inventory.h +++ b/modules/wave_survival/weapon_inventory.h @@ -25,9 +25,6 @@ public: void set_starting_weapon(Ref weapon_scene); Ref 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; diff --git a/project/maps/industrial_area_map.tscn b/project/maps/industrial_area_map.tscn index 95134e03..0841ef57 100644 --- a/project/maps/industrial_area_map.tscn +++ b/project/maps/industrial_area_map.tscn @@ -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) diff --git a/project/objects/enemies/enemy_wretched.tscn b/project/objects/enemies/enemy_wretched.tscn index 060dbe80..7ea440d3 100644 --- a/project/objects/enemies/enemy_wretched.tscn +++ b/project/objects/enemies/enemy_wretched.tscn @@ -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")] diff --git a/project/objects/pickups/weapon_pickup.tscn b/project/objects/pickups/weapon_pickup.tscn new file mode 100644 index 00000000..c0cf5471 --- /dev/null +++ b/project/objects/pickups/weapon_pickup.tscn @@ -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") diff --git a/project/objects/player.tscn b/project/objects/player.tscn index 11fab8e3..4d01da7e 100644 --- a/project/objects/player.tscn +++ b/project/objects/player.tscn @@ -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"]