diff --git a/autoloads/inventory_manager.gd b/autoloads/inventory_manager.gd index 905fff2..5384c5b 100644 --- a/autoloads/inventory_manager.gd +++ b/autoloads/inventory_manager.gd @@ -4,6 +4,7 @@ signal next_quick_slot signal previous_quick_slot signal select_quick_slot(slot_index: int) signal quick_slot_item_changed(item_id: String) +signal item_picked_up(item_id: String, amount: int) var quick_slot_item_id: String = "001" diff --git a/project.godot b/project.godot index 8af8f34..8f0e814 100644 --- a/project.godot +++ b/project.godot @@ -139,3 +139,4 @@ quickslot_previous={ 3d_physics/layer_1="World" 3d_physics/layer_2="Player" +3d_physics/layer_3="Pickups" diff --git a/scenes/blocks/dropped_block.gd b/scenes/blocks/dropped_block.gd index 4d2f76e..a02c22e 100644 --- a/scenes/blocks/dropped_block.gd +++ b/scenes/blocks/dropped_block.gd @@ -15,3 +15,12 @@ func initialize(id: String, _position: Vector3) -> void: block.collision_shape.disabled = true block.scale = Vector3(block_scale, block_scale, block_scale) animation_player.play("start_animation") + + +func _on_pickup_area_body_entered(body: Node3D) -> void: + if not body is Player: return + + # TODO: Update stack_count when we start storing that information + var stack_count: int = 1 + InventoryManager.item_picked_up.emit(block.get_id(), stack_count) + queue_free() diff --git a/scenes/blocks/dropped_block.tscn b/scenes/blocks/dropped_block.tscn index fefe431..05cc913 100644 --- a/scenes/blocks/dropped_block.tscn +++ b/scenes/blocks/dropped_block.tscn @@ -1,8 +1,11 @@ -[gd_scene load_steps=6 format=3 uid="uid://bn2olldntd7a6"] +[gd_scene load_steps=7 format=3 uid="uid://bn2olldntd7a6"] [ext_resource type="Script" uid="uid://dkd2qbndc3q1o" path="res://scenes/blocks/dropped_block.gd" id="1_50ggx"] [ext_resource type="PackedScene" uid="uid://col07xd76y60h" path="res://scenes/blocks/block.tscn" id="1_chlk1"] +[sub_resource type="SphereShape3D" id="SphereShape3D_5kft2"] +radius = 1.0 + [sub_resource type="Animation" id="Animation_kym7p"] length = 0.001 tracks/0/type = "value" @@ -72,8 +75,17 @@ script = ExtResource("1_50ggx") [node name="Block" parent="." instance=ExtResource("1_chlk1")] transform = Transform3D(0.965926, -0.258819, 0, 0.258819, 0.965926, 0, 0, 0, 1, 0, 0, 0) +[node name="PickupArea" type="Area3D" parent="Block"] +collision_layer = 4 +collision_mask = 2 + +[node name="CollisionShape3D" type="CollisionShape3D" parent="Block/PickupArea"] +shape = SubResource("SphereShape3D_5kft2") + [node name="AnimationPlayer" type="AnimationPlayer" parent="."] libraries = { &"": SubResource("AnimationLibrary_kym7p") } autoplay = "start_animation" + +[connection signal="body_entered" from="Block/PickupArea" to="." method="_on_pickup_area_body_entered"] diff --git a/scenes/player/player.tscn b/scenes/player/player.tscn index 9fe5d2b..fd3d139 100644 --- a/scenes/player/player.tscn +++ b/scenes/player/player.tscn @@ -14,6 +14,7 @@ height = 0.89 [sub_resource type="CapsuleMesh" id="CapsuleMesh_gmlin"] [node name="Player" type="CharacterBody3D"] +collision_layer = 2 script = ExtResource("1_rp718") [node name="CollisionShapeStanding" type="CollisionShape3D" parent="."]