diff --git a/behaviours/draggable.gd b/behaviours/draggable.gd index 5587747..d52eaad 100644 --- a/behaviours/draggable.gd +++ b/behaviours/draggable.gd @@ -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() diff --git a/behaviours/move_towards_physics.gd b/behaviours/move_towards_physics.gd new file mode 100644 index 0000000..22069cb --- /dev/null +++ b/behaviours/move_towards_physics.gd @@ -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) diff --git a/behaviours/move_towards_physics.tscn b/behaviours/move_towards_physics.tscn new file mode 100644 index 0000000..bc2bedf --- /dev/null +++ b/behaviours/move_towards_physics.tscn @@ -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") diff --git a/entities/sheep.gd b/entities/sheep.gd index a8ba3e3..68aa731 100644 --- a/entities/sheep.gd +++ b/entities/sheep.gd @@ -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 diff --git a/entities/sheep.tscn b/entities/sheep.tscn index cd39098..79d5516 100644 --- a/entities/sheep.tscn +++ b/entities/sheep.tscn @@ -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"] diff --git a/scenes/game/cursor.gd b/scenes/game/cursor.gd index 7f9a360..d211b0f 100644 --- a/scenes/game/cursor.gd +++ b/scenes/game/cursor.gd @@ -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: diff --git a/scenes/game/main_game.tscn b/scenes/game/main_game.tscn index 91b2b5c..cfd6081 100644 --- a/scenes/game/main_game.tscn +++ b/scenes/game/main_game.tscn @@ -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"]