mirror of
https://github.com/Steffo99/hella-farm.git
synced 2024-11-21 23:54:23 +00:00
Sheep now work! Almost. Missing speed.
This commit is contained in:
parent
17e87b06d0
commit
3341c86e39
11 changed files with 100 additions and 61 deletions
|
@ -19,3 +19,10 @@ func _on_body_exited(body: Node2D) -> void:
|
||||||
if body is Cursor:
|
if body is Cursor:
|
||||||
mouse_inside = true
|
mouse_inside = true
|
||||||
cursor_exited.emit(body)
|
cursor_exited.emit(body)
|
||||||
|
|
||||||
|
|
||||||
|
func _on_cursor_entered(cursor: Cursor) -> void:
|
||||||
|
Log.p(self, "Cursor entered: %s" % cursor)
|
||||||
|
|
||||||
|
func _on_cursor_exited(cursor: Cursor) -> void:
|
||||||
|
Log.p(self, "Cursor exited: %s" % cursor)
|
||||||
|
|
|
@ -10,3 +10,5 @@ script = ExtResource("1_4hcxj")
|
||||||
|
|
||||||
[connection signal="body_entered" from="." to="." method="_on_body_entered"]
|
[connection signal="body_entered" from="." to="." method="_on_body_entered"]
|
||||||
[connection signal="body_exited" from="." to="." method="_on_body_exited"]
|
[connection signal="body_exited" from="." to="." method="_on_body_exited"]
|
||||||
|
[connection signal="cursor_entered" from="." to="." method="_on_cursor_entered"]
|
||||||
|
[connection signal="cursor_exited" from="." to="." method="_on_cursor_exited"]
|
||||||
|
|
|
@ -15,6 +15,12 @@ signal changed_direction(new: Vector2)
|
||||||
changed_direction.emit(direction)
|
changed_direction.emit(direction)
|
||||||
|
|
||||||
|
|
||||||
|
func set_direction(value: Vector2) -> void:
|
||||||
|
direction = value
|
||||||
|
|
||||||
|
func clear_direction() -> void:
|
||||||
|
direction = Vector2.ZERO
|
||||||
|
|
||||||
func randomize_direction() -> void:
|
func randomize_direction() -> void:
|
||||||
direction = Vector2.from_angle(Random.rng.randf_range(0, 2*PI))
|
direction = Vector2.from_angle(Random.rng.randf_range(0, 2*PI))
|
||||||
|
|
||||||
|
@ -22,3 +28,6 @@ func randomize_direction() -> void:
|
||||||
func _physics_process(_delta: float) -> void:
|
func _physics_process(_delta: float) -> void:
|
||||||
if enabled:
|
if enabled:
|
||||||
move.emit(direction)
|
move.emit(direction)
|
||||||
|
|
||||||
|
func _on_changed_direction(new: Vector2) -> void:
|
||||||
|
Log.p(self, "Changed direction to: %s" % new)
|
||||||
|
|
|
@ -4,3 +4,5 @@
|
||||||
|
|
||||||
[node name="MoveStraight" type="Node2D"]
|
[node name="MoveStraight" type="Node2D"]
|
||||||
script = ExtResource("1_8yf73")
|
script = ExtResource("1_8yf73")
|
||||||
|
|
||||||
|
[connection signal="changed_direction" from="." to="." method="_on_changed_direction"]
|
||||||
|
|
|
@ -5,15 +5,15 @@ class_name MoveTowards
|
||||||
## A [Move] that moves towards the [field position] of a [field target].
|
## A [Move] that moves towards the [field position] of a [field target].
|
||||||
|
|
||||||
|
|
||||||
signal changed_target(target: Node2D)
|
signal changed_target(new: Node2D)
|
||||||
|
|
||||||
|
|
||||||
@export var target: Node2D = null:
|
@export var target: Node2D = null:
|
||||||
get:
|
get:
|
||||||
return target
|
return target
|
||||||
set(value):
|
set(value):
|
||||||
value = target
|
target = value
|
||||||
changed_target.emit()
|
changed_target.emit(value)
|
||||||
|
|
||||||
|
|
||||||
func set_target(value: Node2D) -> void:
|
func set_target(value: Node2D) -> void:
|
||||||
|
@ -31,3 +31,6 @@ func _physics_process(_delta: float) -> void:
|
||||||
move.emit(norm)
|
move.emit(norm)
|
||||||
else:
|
else:
|
||||||
move.emit(Vector2.ZERO)
|
move.emit(Vector2.ZERO)
|
||||||
|
|
||||||
|
func _on_changed_target(new: Node2D) -> void:
|
||||||
|
Log.p(self, "Changed target to: %s" % new)
|
||||||
|
|
|
@ -4,3 +4,5 @@
|
||||||
|
|
||||||
[node name="MoveTowards" type="Node2D"]
|
[node name="MoveTowards" type="Node2D"]
|
||||||
script = ExtResource("1_256ue")
|
script = ExtResource("1_256ue")
|
||||||
|
|
||||||
|
[connection signal="changed_target" from="." to="." method="_on_changed_target"]
|
||||||
|
|
|
@ -13,13 +13,14 @@ func sample() -> Priority:
|
||||||
# FIXME: Change this to something more efficient when needed
|
# FIXME: Change this to something more efficient when needed
|
||||||
var highest_possibility: Priority = null
|
var highest_possibility: Priority = null
|
||||||
for possibility in possibilities:
|
for possibility in possibilities:
|
||||||
|
Log.p(self, "Possibility: %s (%d)" % [possibility, possibility.priority])
|
||||||
if highest_possibility == null or possibility.priority > highest_possibility.priority:
|
if highest_possibility == null or possibility.priority > highest_possibility.priority:
|
||||||
highest_possibility = possibility
|
highest_possibility = possibility
|
||||||
|
|
||||||
if highest_possibility == null:
|
if highest_possibility == null:
|
||||||
return null
|
return null
|
||||||
|
|
||||||
Log.p(self, "Sampled: %s" % highest_possibility)
|
Log.p(self, "Sampled: %s (%d)" % [highest_possibility, highest_possibility.priority])
|
||||||
return highest_possibility.get_ref()
|
return highest_possibility.get_ref()
|
||||||
|
|
||||||
func get_refs() -> Array[Node]:
|
func get_refs() -> Array[Node]:
|
||||||
|
|
|
@ -113,69 +113,67 @@ libraries = {
|
||||||
|
|
||||||
[node name="Edible" parent="." instance=ExtResource("6_3odsh")]
|
[node name="Edible" parent="." instance=ExtResource("6_3odsh")]
|
||||||
|
|
||||||
[node name="Movement" parent="." node_paths=PackedStringArray("possibilities") instance=ExtResource("9_s5lod")]
|
[node name="MovementSampler" parent="." node_paths=PackedStringArray("possibilities") instance=ExtResource("9_s5lod")]
|
||||||
possibilities = [NodePath("Idle/IdlePriority"), NodePath("Wander/WanderPriority"), NodePath("RunFromMouse/RunFromMousePriority"), NodePath("RunFromHunter/RunFromHunterPriority")]
|
possibilities = [NodePath("../MovementIdle/IdlePriority"), NodePath("../MovementWander/WanderPriority"), NodePath("../MovementRunFromMouse/RunFromMousePriority"), NodePath("../MovementRunFromHunter/RunFromHunterPriority")]
|
||||||
|
|
||||||
[node name="Idle" parent="Movement" instance=ExtResource("10_05kcd")]
|
[node name="MovementIdle" parent="." instance=ExtResource("10_05kcd")]
|
||||||
enabled = false
|
enabled = false
|
||||||
|
|
||||||
[node name="IdlePriority" parent="Movement/Idle" instance=ExtResource("11_0jlmk")]
|
[node name="IdlePriority" parent="MovementIdle" instance=ExtResource("11_0jlmk")]
|
||||||
priority = 10
|
priority = 10
|
||||||
|
|
||||||
[node name="BoredTimer" type="Timer" parent="Movement/Idle"]
|
[node name="BoredTimer" type="Timer" parent="MovementIdle"]
|
||||||
one_shot = true
|
one_shot = true
|
||||||
|
|
||||||
[node name="Wander" parent="Movement" instance=ExtResource("10_05kcd")]
|
[node name="MovementWander" parent="." instance=ExtResource("10_05kcd")]
|
||||||
enabled = false
|
enabled = false
|
||||||
|
|
||||||
[node name="WanderPriority" parent="Movement/Wander" instance=ExtResource("11_0jlmk")]
|
[node name="WanderPriority" parent="MovementWander" instance=ExtResource("11_0jlmk")]
|
||||||
|
|
||||||
[node name="TiredTimer" type="Timer" parent="Movement/Wander"]
|
[node name="TiredTimer" type="Timer" parent="MovementWander"]
|
||||||
one_shot = true
|
one_shot = true
|
||||||
|
|
||||||
[node name="RunFromMouse" parent="Movement" instance=ExtResource("12_x2g3x")]
|
[node name="MovementRunFromMouse" parent="." instance=ExtResource("12_x2g3x")]
|
||||||
enabled = false
|
enabled = false
|
||||||
|
|
||||||
[node name="RunFromMousePriority" parent="Movement/RunFromMouse" instance=ExtResource("11_0jlmk")]
|
[node name="RunFromMousePriority" parent="MovementRunFromMouse" instance=ExtResource("11_0jlmk")]
|
||||||
|
|
||||||
[node name="CursorDetector" parent="Movement/RunFromMouse" instance=ExtResource("13_5fkdr")]
|
[node name="CursorSense" parent="MovementRunFromMouse" instance=ExtResource("13_5fkdr")]
|
||||||
|
|
||||||
[node name="Shape" type="CollisionShape2D" parent="Movement/RunFromMouse/CursorDetector"]
|
[node name="Shape" type="CollisionShape2D" parent="MovementRunFromMouse/CursorSense"]
|
||||||
shape = SubResource("CircleShape2D_etpf6")
|
shape = SubResource("CircleShape2D_etpf6")
|
||||||
debug_color = Color(1, 0, 0, 0.0470588)
|
debug_color = Color(1, 0, 0, 0.0470588)
|
||||||
|
|
||||||
[node name="RunFromHunter" parent="Movement" instance=ExtResource("12_x2g3x")]
|
[node name="MovementRunFromHunter" parent="." instance=ExtResource("12_x2g3x")]
|
||||||
enabled = false
|
enabled = false
|
||||||
|
|
||||||
[node name="RunFromHunterPriority" parent="Movement/RunFromHunter" instance=ExtResource("11_0jlmk")]
|
[node name="RunFromHunterPriority" parent="MovementRunFromHunter" instance=ExtResource("11_0jlmk")]
|
||||||
|
|
||||||
[node name="TrackerTracker" parent="Movement/RunFromHunter" instance=ExtResource("14_eqowb")]
|
[node name="HunterSense" parent="MovementRunFromHunter" instance=ExtResource("14_eqowb")]
|
||||||
|
|
||||||
[node name="Camera2D" type="Camera2D" parent="."]
|
|
||||||
position_smoothing_enabled = true
|
|
||||||
position_smoothing_speed = 1.0
|
|
||||||
|
|
||||||
[connection signal="dragged" from="Draggable" to="." method="_on_draggable_dragged"]
|
[connection signal="dragged" from="Draggable" to="." method="_on_draggable_dragged"]
|
||||||
[connection signal="dropped" from="Draggable" to="." method="_on_draggable_dropped"]
|
[connection signal="dropped" from="Draggable" to="." method="_on_draggable_dropped"]
|
||||||
[connection signal="ready" from="Movement" to="Movement" method="enable"]
|
[connection signal="ready" from="MovementSampler" to="MovementSampler" method="enable"]
|
||||||
[connection signal="move" from="Movement/Idle" to="." method="_on_move"]
|
[connection signal="move" from="MovementIdle" to="." method="_on_move"]
|
||||||
[connection signal="move_disabled" from="Movement/Idle" to="Movement/Idle/BoredTimer" method="stop"]
|
[connection signal="move_disabled" from="MovementIdle" to="MovementIdle/BoredTimer" method="stop"]
|
||||||
[connection signal="move_enabled" from="Movement/Idle" to="Movement/Idle/BoredTimer" method="start"]
|
[connection signal="move_enabled" from="MovementIdle" to="MovementIdle/BoredTimer" method="start"]
|
||||||
[connection signal="priority_changed_no_args" from="Movement/Idle/IdlePriority" to="Movement" method="enable"]
|
[connection signal="priority_changed_no_args" from="MovementIdle/IdlePriority" to="MovementSampler" method="enable"]
|
||||||
[connection signal="timeout" from="Movement/Idle/BoredTimer" to="Movement/Wander" method="randomize_direction"]
|
[connection signal="timeout" from="MovementIdle/BoredTimer" to="MovementWander" method="randomize_direction"]
|
||||||
[connection signal="changed_direction" from="Movement/Wander" to="Movement/Wander/WanderPriority" method="set_priority_if_truthy" binds= [20]]
|
[connection signal="changed_direction" from="MovementWander" to="MovementWander/WanderPriority" method="set_priority_if_truthy" binds= [20]]
|
||||||
[connection signal="move" from="Movement/Wander" to="." method="_on_move"]
|
[connection signal="move" from="MovementWander" to="." method="_on_move"]
|
||||||
[connection signal="move_disabled" from="Movement/Wander" to="Movement/Wander/TiredTimer" method="stop"]
|
[connection signal="move_disabled" from="MovementWander" to="MovementWander/TiredTimer" method="stop"]
|
||||||
[connection signal="move_enabled" from="Movement/Wander" to="Movement/Wander/TiredTimer" method="start"]
|
[connection signal="move_enabled" from="MovementWander" to="MovementWander/TiredTimer" method="start"]
|
||||||
[connection signal="priority_changed_no_args" from="Movement/Wander/WanderPriority" to="Movement" method="enable"]
|
[connection signal="priority_changed_no_args" from="MovementWander/WanderPriority" to="MovementSampler" method="enable"]
|
||||||
[connection signal="timeout" from="Movement/Wander/TiredTimer" to="Movement/Wander/WanderPriority" method="set_priority" binds= [0]]
|
[connection signal="timeout" from="MovementWander/TiredTimer" to="MovementWander" method="clear_direction"]
|
||||||
[connection signal="changed_target" from="Movement/RunFromMouse" to="Movement/RunFromMouse/RunFromMousePriority" method="set_priority_if_truthy" binds= [30]]
|
[connection signal="changed_target" from="MovementRunFromMouse" to="MovementRunFromMouse/RunFromMousePriority" method="set_priority_if_truthy" binds= [30]]
|
||||||
[connection signal="move" from="Movement/RunFromMouse" to="." method="_on_move"]
|
[connection signal="move" from="MovementRunFromMouse" to="." method="_on_move"]
|
||||||
[connection signal="priority_changed_no_args" from="Movement/RunFromMouse/RunFromMousePriority" to="Movement" method="enable"]
|
[connection signal="move_enabled" from="MovementRunFromMouse" to="MovementWander" method="clear_direction"]
|
||||||
[connection signal="cursor_entered" from="Movement/RunFromMouse/CursorDetector" to="Movement/RunFromMouse" method="set_target"]
|
[connection signal="priority_changed_no_args" from="MovementRunFromMouse/RunFromMousePriority" to="MovementSampler" method="enable"]
|
||||||
[connection signal="cursor_exited" from="Movement/RunFromMouse/CursorDetector" to="Movement/RunFromMouse" method="clear_target" unbinds=1]
|
[connection signal="cursor_entered" from="MovementRunFromMouse/CursorSense" to="MovementRunFromMouse" method="set_target"]
|
||||||
[connection signal="changed_target" from="Movement/RunFromHunter" to="Movement/RunFromHunter/RunFromHunterPriority" method="set_priority_if_truthy" binds= [40]]
|
[connection signal="cursor_exited" from="MovementRunFromMouse/CursorSense" to="MovementRunFromMouse" method="clear_target" unbinds=1]
|
||||||
[connection signal="move" from="Movement/RunFromHunter" to="." method="_on_move"]
|
[connection signal="changed_target" from="MovementRunFromHunter" to="MovementRunFromHunter/RunFromHunterPriority" method="set_priority_if_truthy" binds= [40]]
|
||||||
[connection signal="priority_changed_no_args" from="Movement/RunFromHunter/RunFromHunterPriority" to="Movement" method="enable"]
|
[connection signal="move" from="MovementRunFromHunter" to="." method="_on_move"]
|
||||||
[connection signal="tracked" from="Movement/RunFromHunter/TrackerTracker" to="Movement/RunFromHunter" method="set_target"]
|
[connection signal="move_disabled" from="MovementRunFromHunter" to="MovementWander" method="clear_direction"]
|
||||||
[connection signal="untracked" from="Movement/RunFromHunter/TrackerTracker" to="Movement/RunFromHunter" method="clear_target" unbinds=1]
|
[connection signal="priority_changed_no_args" from="MovementRunFromHunter/RunFromHunterPriority" to="MovementSampler" method="enable"]
|
||||||
|
[connection signal="tracked" from="MovementRunFromHunter/HunterSense" to="MovementRunFromHunter" method="set_target"]
|
||||||
|
[connection signal="untracked" from="MovementRunFromHunter/HunterSense" to="MovementRunFromHunter" method="clear_target" unbinds=1]
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
extends Node2D
|
extends CharacterBody2D
|
||||||
class_name Cursor
|
class_name Cursor
|
||||||
|
|
||||||
## A [Node2D] syncing its position with the mouse on each physics timestep.
|
## A [CharacterBody2D] syncing its position with the mouse on each physics timestep.
|
||||||
|
|
||||||
|
|
||||||
@onready var game := MainGame.get_ancestor(self)
|
@onready var game := MainGame.get_ancestor(self)
|
||||||
|
|
||||||
|
|
||||||
func _physics_process(_delta: float) -> void:
|
func _physics_process(_delta: float) -> void:
|
||||||
global_position = game.camera.get_global_mouse_position()
|
move_and_collide(game.camera.get_global_mouse_position() - global_position)
|
||||||
|
|
|
@ -1,8 +1,16 @@
|
||||||
[gd_scene load_steps=2 format=3 uid="uid://col1q3elvkfwk"]
|
[gd_scene load_steps=3 format=3 uid="uid://col1q3elvkfwk"]
|
||||||
|
|
||||||
[ext_resource type="Script" path="res://scenes/game/cursor.gd" id="1_1og6v"]
|
[ext_resource type="Script" path="res://scenes/game/cursor.gd" id="1_1og6v"]
|
||||||
|
|
||||||
|
[sub_resource type="CircleShape2D" id="CircleShape2D_j2mj5"]
|
||||||
|
radius = 4.0
|
||||||
|
|
||||||
[node name="Cursor" type="CharacterBody2D"]
|
[node name="Cursor" type="CharacterBody2D"]
|
||||||
collision_layer = 64
|
collision_layer = 64
|
||||||
collision_mask = 0
|
collision_mask = 0
|
||||||
|
motion_mode = 1
|
||||||
script = ExtResource("1_1og6v")
|
script = ExtResource("1_1og6v")
|
||||||
|
|
||||||
|
[node name="Shape" type="CollisionShape2D" parent="."]
|
||||||
|
shape = SubResource("CircleShape2D_j2mj5")
|
||||||
|
debug_color = Color(1, 1, 1, 1)
|
||||||
|
|
File diff suppressed because one or more lines are too long
Loading…
Reference in a new issue