Browse Source

Add support for picking up dropped blocks (no inventory yet)

pull/3/head
Ryan Reed 1 month ago
parent
commit
fc44326fea
5 changed files with 25 additions and 1 deletions
  1. +1
    -0
      autoloads/inventory_manager.gd
  2. +1
    -0
      project.godot
  3. +9
    -0
      scenes/blocks/dropped_block.gd
  4. +13
    -1
      scenes/blocks/dropped_block.tscn
  5. +1
    -0
      scenes/player/player.tscn

+ 1
- 0
autoloads/inventory_manager.gd View File

@ -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"


+ 1
- 0
project.godot View File

@ -139,3 +139,4 @@ quickslot_previous={
3d_physics/layer_1="World"
3d_physics/layer_2="Player"
3d_physics/layer_3="Pickups"

+ 9
- 0
scenes/blocks/dropped_block.gd View File

@ -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()

+ 13
- 1
scenes/blocks/dropped_block.tscn View File

@ -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"]

+ 1
- 0
scenes/player/player.tscn View File

@ -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="."]


Loading…
Cancel
Save