create Gathering component for picking up honeydew

This commit is contained in:
2024-10-06 20:00:14 +10:00
parent 78cb85eb92
commit 0e1dd1b2f2
5 changed files with 66 additions and 2 deletions

View File

@@ -1,9 +1,10 @@
[gd_scene load_steps=12 format=3 uid="uid://k11usj2shbtr"] [gd_scene load_steps=13 format=3 uid="uid://k11usj2shbtr"]
[ext_resource type="PackedScene" uid="uid://bi231xk2sp410" path="res://assets/models/ant.glb" id="1_1u65s"] [ext_resource type="PackedScene" uid="uid://bi231xk2sp410" path="res://assets/models/ant.glb" id="1_1u65s"]
[ext_resource type="Script" path="res://scripts/units/ant_nitwit.gd" id="2_f1bdv"] [ext_resource type="Script" path="res://scripts/units/ant_nitwit.gd" id="2_f1bdv"]
[ext_resource type="Texture2D" uid="uid://dehqm00kiljut" path="res://assets/textures/selection_unit_decal.png" id="3_hxm2m"] [ext_resource type="Texture2D" uid="uid://dehqm00kiljut" path="res://assets/textures/selection_unit_decal.png" id="3_hxm2m"]
[ext_resource type="Texture2D" uid="uid://duf132faskeid" path="res://assets/textures/selection_unit_hover_decal.png" id="4_vrkmw"] [ext_resource type="Texture2D" uid="uid://duf132faskeid" path="res://assets/textures/selection_unit_hover_decal.png" id="4_vrkmw"]
[ext_resource type="PackedScene" uid="uid://fal1ond30jey" path="res://scenes/units/components/gathering.tscn" id="5_j8w6w"]
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_0iwx2"] [sub_resource type="StandardMaterial3D" id="StandardMaterial3D_0iwx2"]
albedo_color = Color(0.344076, 0.344076, 0.344076, 1) albedo_color = Color(0.344076, 0.344076, 0.344076, 1)
@@ -74,3 +75,5 @@ neighbor_distance = 10.0
[node name="VisibleOnScreenNotifier3D" type="VisibleOnScreenNotifier3D" parent="." index="7"] [node name="VisibleOnScreenNotifier3D" type="VisibleOnScreenNotifier3D" parent="." index="7"]
aabb = AABB(-0.5, 0, -0.5, 1, 0.5, 1) aabb = AABB(-0.5, 0, -0.5, 1, 0.5, 1)
[node name="Gathering" parent="." index="8" instance=ExtResource("5_j8w6w")]

View File

@@ -0,0 +1,13 @@
[gd_scene load_steps=3 format=3 uid="uid://fal1ond30jey"]
[ext_resource type="Script" path="res://scripts/units/components/gathering.gd" id="1_ciwtf"]
[sub_resource type="SphereShape3D" id="SphereShape3D_eqrj3"]
radius = 15.0
[node name="Gathering" type="Area3D"]
input_ray_pickable = false
script = ExtResource("1_ciwtf")
[node name="NearbyItemsSearch" type="CollisionShape3D" parent="."]
shape = SubResource("SphereShape3D_eqrj3")

View File

@@ -14,6 +14,8 @@ func _ready() -> void:
func _input(event: InputEvent) -> void: func _input(event: InputEvent) -> void:
if event is InputEventMouseButton: if event is InputEventMouseButton:
if disable_confinement:
return
var button_event := event as InputEventMouseButton var button_event := event as InputEventMouseButton
if ( if (
button_event.button_index == MOUSE_BUTTON_LEFT button_event.button_index == MOUSE_BUTTON_LEFT
@@ -28,9 +30,10 @@ func _input(event: InputEvent) -> void:
disable_confinement = not disable_confinement disable_confinement = not disable_confinement
if disable_confinement: if disable_confinement:
Input.mouse_mode = Input.MOUSE_MODE_VISIBLE Input.mouse_mode = Input.MOUSE_MODE_VISIBLE
Input.set_custom_mouse_cursor(null)
else: else:
Input.mouse_mode = Input.MOUSE_MODE_CONFINED Input.mouse_mode = Input.MOUSE_MODE_CONFINED
_set_cursor(cursor_normal)
func _set_cursor(image: Resource) -> void: func _set_cursor(image: Resource) -> void:

View File

@@ -7,6 +7,9 @@ var mouse_pos: Vector2 = Vector2.ZERO
func _physics_process(_delta: float) -> void: func _physics_process(_delta: float) -> void:
if SelectionManager.selecting:
return
var space_state := get_world_3d().direct_space_state var space_state := get_world_3d().direct_space_state
var from := camera.project_ray_origin(mouse_pos) var from := camera.project_ray_origin(mouse_pos)
var to := from + camera.project_ray_normal(mouse_pos) * (camera.far - 1) var to := from + camera.project_ray_normal(mouse_pos) * (camera.far - 1)

View File

@@ -0,0 +1,42 @@
extends Area3D
class_name Gathering
enum GatherState {
PICKING_UP,
DEPOSITING,
}
var items: Dictionary = {}
var max_carrying: int = 3
var carrying: int = 0
var state: GatherState = GatherState.PICKING_UP
var target: Honeydew
func _ready() -> void:
body_entered.connect(_on_body_entered)
body_exited.connect(_on_body_exited)
func gather(item: Honeydew)->void:
target = item
state = GatherState.PICKING_UP
func _on_body_entered(item: Node3D) -> void:
if item is not Honeydew:
return
var item_id := item.get_instance_id()
if items.keys().has(item_id):
return
items[item_id] = item
func _on_body_exited(item: Node3D) -> void:
var item_id := item.get_instance_id()
if not items.keys().has(item_id):
return
items.erase(item_id)