mirror of
https://github.com/Steffo99/hella-farm.git
synced 2024-11-21 15:44:23 +00:00
Start working on MoveTowardsPhysics
This commit is contained in:
parent
9e25d08020
commit
f9f52c4f4a
7 changed files with 51 additions and 13 deletions
|
@ -4,7 +4,7 @@ class_name Draggable
|
|||
|
||||
|
||||
signal dragged(cursor: Cursor)
|
||||
signal dropped(cursor: Cursor)
|
||||
signal dropped
|
||||
|
||||
|
||||
var being_dragged: bool = false
|
||||
|
@ -14,6 +14,6 @@ func drag(cursor: Cursor):
|
|||
being_dragged = true
|
||||
dragged.emit(cursor)
|
||||
|
||||
func drop(cursor: Cursor):
|
||||
func drop():
|
||||
being_dragged = false
|
||||
dropped.emit(cursor)
|
||||
dropped.emit()
|
||||
|
|
17
behaviours/move_towards_physics.gd
Normal file
17
behaviours/move_towards_physics.gd
Normal file
|
@ -0,0 +1,17 @@
|
|||
extends MoveTowards
|
||||
class_name MoveTowardsGravity
|
||||
|
||||
|
||||
# [field speed] is actually used as acceleration. Oh well.
|
||||
|
||||
var velocity := Vector2.ZERO
|
||||
|
||||
|
||||
func _physics_process(delta: float) -> void:
|
||||
if enabled:
|
||||
if target:
|
||||
var gap = target.global_position - global_position
|
||||
var norm = gap.normalized()
|
||||
velocity += norm * delta * speed
|
||||
Log.p(self, "Velocity: %s" % velocity)
|
||||
move.emit(velocity * delta)
|
6
behaviours/move_towards_physics.tscn
Normal file
6
behaviours/move_towards_physics.tscn
Normal file
|
@ -0,0 +1,6 @@
|
|||
[gd_scene load_steps=2 format=3 uid="uid://rx24bppccih7"]
|
||||
|
||||
[ext_resource type="Script" path="res://behaviours/move_towards_physics.gd" id="1_u02i3"]
|
||||
|
||||
[node name="MoveTowardsPhysics" type="Node2D"]
|
||||
script = ExtResource("1_u02i3")
|
|
@ -14,8 +14,12 @@ func _on_move(movement: Vector2) -> void:
|
|||
sprite.handle_move(movement)
|
||||
|
||||
|
||||
func _on_draggable_dragged() -> void:
|
||||
func _on_draggable_dragged(_cursor: Cursor) -> void:
|
||||
collision_layer = 16
|
||||
collision_mask = 18
|
||||
z_index = 1
|
||||
|
||||
func _on_draggable_dropped() -> void:
|
||||
collision_layer = 8
|
||||
collision_mask = 14
|
||||
z_index = 0
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
[gd_scene load_steps=21 format=3 uid="uid://bc2bm8lbol18w"]
|
||||
[gd_scene load_steps=22 format=3 uid="uid://bc2bm8lbol18w"]
|
||||
|
||||
[ext_resource type="Script" path="res://entities/sheep.gd" id="1_4dmll"]
|
||||
[ext_resource type="Texture2D" uid="uid://iljp5yn3ehfk" path="res://entities/sheep_left.png" id="2_t13f5"]
|
||||
|
@ -13,6 +13,7 @@
|
|||
[ext_resource type="PackedScene" uid="uid://cbg5kgwxusvxf" path="res://behaviours/cursor_detector.tscn" id="13_5fkdr"]
|
||||
[ext_resource type="PackedScene" uid="uid://dti7l0d40hhgt" path="res://behaviours/target_picker.tscn" id="13_jf6em"]
|
||||
[ext_resource type="PackedScene" uid="uid://dijcjahkddudv" path="res://behaviours/draggable.tscn" id="14_0b1hs"]
|
||||
[ext_resource type="PackedScene" uid="uid://rx24bppccih7" path="res://behaviours/move_towards_physics.tscn" id="14_3wojv"]
|
||||
[ext_resource type="PackedScene" uid="uid://c5pyp5hvthdof" path="res://behaviours/tracker_tracker.tscn" id="14_eqowb"]
|
||||
|
||||
[sub_resource type="CircleShape2D" id="CircleShape2D_c5tcn"]
|
||||
|
@ -105,7 +106,7 @@ libraries = {
|
|||
diet = &"Meat"
|
||||
|
||||
[node name="MovementSampler" parent="." node_paths=PackedStringArray("possibilities") instance=ExtResource("9_s5lod")]
|
||||
possibilities = [NodePath("../MovementIdle/IdlePriority"), NodePath("../MovementWander/WanderPriority"), NodePath("../MovementRunFromMouse/RunFromMousePriority"), NodePath("../MovementRunFromHunter/RunFromHunterPriority")]
|
||||
possibilities = [NodePath("../MovementIdle/IdlePriority"), NodePath("../MovementWander/WanderPriority"), NodePath("../MovementRunFromMouse/RunFromMousePriority"), NodePath("../MovementRunFromHunter/RunFromHunterPriority"), NodePath("../MovementDrag/DragPriority")]
|
||||
|
||||
[node name="MovementIdle" parent="." instance=ExtResource("10_05kcd")]
|
||||
speed = 0.0
|
||||
|
@ -162,9 +163,15 @@ debug_color = Color(1, 1, 0, 0)
|
|||
[node name="TargetPicker" parent="MovementRunFromHunter/HunterSense" node_paths=PackedStringArray("tracker") instance=ExtResource("13_jf6em")]
|
||||
tracker = NodePath("..")
|
||||
|
||||
[node name="Draggable" parent="." instance=ExtResource("14_0b1hs")]
|
||||
[node name="MovementDrag" parent="." instance=ExtResource("14_3wojv")]
|
||||
speed = 1200.0
|
||||
|
||||
[node name="Shape" type="CollisionShape2D" parent="Draggable"]
|
||||
[node name="DragPriority" parent="MovementDrag" instance=ExtResource("11_0jlmk")]
|
||||
alternative_priority = 50
|
||||
|
||||
[node name="Draggable" parent="MovementDrag" instance=ExtResource("14_0b1hs")]
|
||||
|
||||
[node name="Shape" type="CollisionShape2D" parent="MovementDrag/Draggable"]
|
||||
scale = Vector2(3, 3)
|
||||
shape = SubResource("CircleShape2D_c5tcn")
|
||||
debug_color = Color(1, 1, 1, 0)
|
||||
|
@ -194,5 +201,11 @@ debug_color = Color(1, 1, 1, 0)
|
|||
[connection signal="tracked" from="MovementRunFromHunter/HunterSense" to="MovementRunFromHunter/HunterSense/TargetPicker" method="set_target_if_null"]
|
||||
[connection signal="untracked" from="MovementRunFromHunter/HunterSense" to="MovementRunFromHunter/HunterSense/TargetPicker" method="clear_if_target"]
|
||||
[connection signal="target_changed" from="MovementRunFromHunter/HunterSense/TargetPicker" to="MovementRunFromHunter" method="set_target" unbinds=1]
|
||||
[connection signal="dragged" from="Draggable" to="." method="_on_draggable_dragged"]
|
||||
[connection signal="dropped" from="Draggable" to="." method="_on_draggable_dropped"]
|
||||
[connection signal="changed_target" from="MovementDrag" to="MovementDrag/DragPriority" method="priority_conditional"]
|
||||
[connection signal="move" from="MovementDrag" to="." method="_on_move"]
|
||||
[connection signal="move_enabled" from="MovementDrag" to="MovementWander" method="clear_direction"]
|
||||
[connection signal="priority_changed_no_args" from="MovementDrag/DragPriority" to="MovementSampler" method="enable"]
|
||||
[connection signal="dragged" from="MovementDrag/Draggable" to="." method="_on_draggable_dragged"]
|
||||
[connection signal="dragged" from="MovementDrag/Draggable" to="MovementDrag" method="set_target"]
|
||||
[connection signal="dropped" from="MovementDrag/Draggable" to="." method="_on_draggable_dropped"]
|
||||
[connection signal="dropped" from="MovementDrag/Draggable" to="MovementDrag" method="clear_target"]
|
||||
|
|
|
@ -43,7 +43,7 @@ func drop():
|
|||
if dragging:
|
||||
var target = dragging
|
||||
dragging = null
|
||||
target.drop(self)
|
||||
target.drop()
|
||||
dropped.emit(target)
|
||||
|
||||
func log_dragging() -> void:
|
||||
|
|
|
@ -893,6 +893,4 @@ max_secs = 9.0
|
|||
shape = SubResource("CircleShape2D_h5qsh")
|
||||
debug_color = Color(0, 1, 0, 0.152941)
|
||||
|
||||
[connection signal="dragged" from="Cursor" to="Cursor" method="log_dragging" unbinds=1]
|
||||
[connection signal="dropped" from="Cursor" to="Cursor" method="log_dragging" unbinds=1]
|
||||
[connection signal="timeout" from="Spawner/TimerStddev" to="Spawner" method="spawn"]
|
||||
|
|
Loading…
Reference in a new issue