mirror of
https://github.com/Steffo99/hella-farm.git
synced 2024-11-25 09:34:24 +00:00
Remove MoveTowardsMouse
and MoveTowardsTarget
This commit is contained in:
parent
5e7fde7999
commit
fd0d973658
7 changed files with 21 additions and 135 deletions
|
@ -1,46 +0,0 @@
|
||||||
extends Node2D
|
|
||||||
class_name MoveTowardsMouse
|
|
||||||
|
|
||||||
|
|
||||||
signal move(movement: Vector2)
|
|
||||||
signal detached
|
|
||||||
signal captured
|
|
||||||
|
|
||||||
@onready var game := MainGame.get_ancestor(self)
|
|
||||||
|
|
||||||
@export var speed: float = 100.0
|
|
||||||
@export var can_detach: bool = false
|
|
||||||
|
|
||||||
|
|
||||||
enum State { DETACHED, CAPTURED }
|
|
||||||
|
|
||||||
var state: State = State.DETACHED
|
|
||||||
|
|
||||||
func get_followed_global_position():
|
|
||||||
return game.camera.get_global_mouse_position()
|
|
||||||
|
|
||||||
|
|
||||||
func get_followed_mouse_position():
|
|
||||||
var global_followed_position: Vector2 = get_followed_global_position()
|
|
||||||
var relative_followed_position: Vector2 = global_followed_position - global_position
|
|
||||||
return relative_followed_position
|
|
||||||
|
|
||||||
|
|
||||||
func _physics_process(delta: float) -> void:
|
|
||||||
match state:
|
|
||||||
State.CAPTURED:
|
|
||||||
var relative_followed_position: Vector2 = get_followed_mouse_position()
|
|
||||||
var direction: Vector2 = position.direction_to(relative_followed_position)
|
|
||||||
var actual_speed: float = min(delta * speed, relative_followed_position.length()) # Don't overshoot.
|
|
||||||
var movement: Vector2 = direction * actual_speed
|
|
||||||
move.emit(movement)
|
|
||||||
|
|
||||||
func _on_capture_area_mouse_entered() -> void:
|
|
||||||
state = State.CAPTURED
|
|
||||||
captured.emit()
|
|
||||||
|
|
||||||
func _on_capture_area_mouse_exited() -> void:
|
|
||||||
if can_detach:
|
|
||||||
state = State.DETACHED
|
|
||||||
detached.emit()
|
|
||||||
|
|
|
@ -1,12 +0,0 @@
|
||||||
[gd_scene load_steps=3 format=3 uid="uid://bvrxvrjlo5130"]
|
|
||||||
|
|
||||||
[ext_resource type="Script" path="res://behaviours/move_towards_mouse.gd" id="1_nbja1"]
|
|
||||||
[ext_resource type="PackedScene" uid="uid://cbg5kgwxusvxf" path="res://behaviours/cursor_detector.tscn" id="2_qru2e"]
|
|
||||||
|
|
||||||
[node name="MoveTowardsMouse" type="Node2D"]
|
|
||||||
script = ExtResource("1_nbja1")
|
|
||||||
|
|
||||||
[node name="CaptureArea" parent="." instance=ExtResource("2_qru2e")]
|
|
||||||
|
|
||||||
[connection signal="mouse_entered" from="CaptureArea" to="." method="_on_capture_area_mouse_entered"]
|
|
||||||
[connection signal="mouse_exited" from="CaptureArea" to="." method="_on_capture_area_mouse_exited"]
|
|
|
@ -1,29 +0,0 @@
|
||||||
extends Node2D
|
|
||||||
class_name MoveTowardsTarget
|
|
||||||
|
|
||||||
|
|
||||||
signal move(movement: Vector2)
|
|
||||||
|
|
||||||
|
|
||||||
@export var speed: float = 100.0
|
|
||||||
@export var target: Node2D
|
|
||||||
|
|
||||||
|
|
||||||
func get_followed_global_position():
|
|
||||||
return target.global_position
|
|
||||||
|
|
||||||
|
|
||||||
func get_followed_mouse_position():
|
|
||||||
var global_followed_position: Vector2 = get_followed_global_position()
|
|
||||||
var relative_followed_position: Vector2 = global_followed_position - global_position
|
|
||||||
return relative_followed_position
|
|
||||||
|
|
||||||
|
|
||||||
func _physics_process(delta: float) -> void:
|
|
||||||
if target == null:
|
|
||||||
return
|
|
||||||
var relative_followed_position: Vector2 = get_followed_mouse_position()
|
|
||||||
var direction: Vector2 = position.direction_to(relative_followed_position)
|
|
||||||
var actual_speed: float = min(delta * speed, relative_followed_position.length()) # Don't overshoot.
|
|
||||||
var movement: Vector2 = direction * actual_speed
|
|
||||||
move.emit(movement)
|
|
|
@ -1,6 +0,0 @@
|
||||||
[gd_scene load_steps=2 format=3 uid="uid://kceb2v2dm0qn"]
|
|
||||||
|
|
||||||
[ext_resource type="Script" path="res://behaviours/move_towards_target.gd" id="1_703gy"]
|
|
||||||
|
|
||||||
[node name="MoveTowardsTarget" type="Node2D"]
|
|
||||||
script = ExtResource("1_703gy")
|
|
|
@ -1,7 +1,6 @@
|
||||||
[gd_scene load_steps=7 format=3 uid="uid://uoxwjpmgg27a"]
|
[gd_scene load_steps=6 format=3 uid="uid://uoxwjpmgg27a"]
|
||||||
|
|
||||||
[ext_resource type="Script" path="res://entities/gold.gd" id="1_lbls1"]
|
[ext_resource type="Script" path="res://entities/gold.gd" id="1_lbls1"]
|
||||||
[ext_resource type="PackedScene" uid="uid://bvrxvrjlo5130" path="res://behaviours/move_towards_mouse.tscn" id="2_lso1v"]
|
|
||||||
[ext_resource type="Texture2D" uid="uid://bfl0tkg85cvb8" path="res://entities/gold.png" id="2_tt3v6"]
|
[ext_resource type="Texture2D" uid="uid://bfl0tkg85cvb8" path="res://entities/gold.png" id="2_tt3v6"]
|
||||||
[ext_resource type="PackedScene" uid="uid://dj72yshd25ucx" path="res://behaviours/collectable.tscn" id="3_q0bno"]
|
[ext_resource type="PackedScene" uid="uid://dj72yshd25ucx" path="res://behaviours/collectable.tscn" id="3_q0bno"]
|
||||||
[ext_resource type="PackedScene" uid="uid://tx1qi6ahlxjp" path="res://behaviours/spawner.tscn" id="5_t7ey8"]
|
[ext_resource type="PackedScene" uid="uid://tx1qi6ahlxjp" path="res://behaviours/spawner.tscn" id="5_t7ey8"]
|
||||||
|
@ -14,10 +13,6 @@ script = ExtResource("1_lbls1")
|
||||||
scale = Vector2(2, 2)
|
scale = Vector2(2, 2)
|
||||||
texture = ExtResource("2_tt3v6")
|
texture = ExtResource("2_tt3v6")
|
||||||
|
|
||||||
[node name="MoveTowardsMouse" parent="." instance=ExtResource("2_lso1v")]
|
|
||||||
scale = Vector2(8, 8)
|
|
||||||
speed = 555.0
|
|
||||||
|
|
||||||
[node name="Collectable" parent="." instance=ExtResource("3_q0bno")]
|
[node name="Collectable" parent="." instance=ExtResource("3_q0bno")]
|
||||||
scale = Vector2(0.6, 0.6)
|
scale = Vector2(0.6, 0.6)
|
||||||
tag = &"Gold"
|
tag = &"Gold"
|
||||||
|
@ -25,5 +20,4 @@ tag = &"Gold"
|
||||||
[node name="Spawner" parent="." instance=ExtResource("5_t7ey8")]
|
[node name="Spawner" parent="." instance=ExtResource("5_t7ey8")]
|
||||||
scene = ExtResource("6_eoeje")
|
scene = ExtResource("6_eoeje")
|
||||||
|
|
||||||
[connection signal="move" from="MoveTowardsMouse" to="." method="_on_move"]
|
|
||||||
[connection signal="collected" from="Collectable" to="." method="_on_collected"]
|
[connection signal="collected" from="Collectable" to="." method="_on_collected"]
|
||||||
|
|
|
@ -1,8 +1,7 @@
|
||||||
[gd_scene load_steps=15 format=3 uid="uid://bc2bm8lbol18w"]
|
[gd_scene load_steps=14 format=3 uid="uid://bc2bm8lbol18w"]
|
||||||
|
|
||||||
[ext_resource type="Script" path="res://entities/sheep.gd" id="1_4dmll"]
|
[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"]
|
[ext_resource type="Texture2D" uid="uid://iljp5yn3ehfk" path="res://entities/sheep_left.png" id="2_t13f5"]
|
||||||
[ext_resource type="PackedScene" uid="uid://bvrxvrjlo5130" path="res://behaviours/move_towards_mouse.tscn" id="2_tfd2i"]
|
|
||||||
[ext_resource type="PackedScene" uid="uid://bxbjfev0lhwws" path="res://behaviours/sprite_left_right.tscn" id="2_xbkrm"]
|
[ext_resource type="PackedScene" uid="uid://bxbjfev0lhwws" path="res://behaviours/sprite_left_right.tscn" id="2_xbkrm"]
|
||||||
[ext_resource type="PackedScene" uid="uid://dijcjahkddudv" path="res://behaviours/draggable.tscn" id="3_8ku7r"]
|
[ext_resource type="PackedScene" uid="uid://dijcjahkddudv" path="res://behaviours/draggable.tscn" id="3_8ku7r"]
|
||||||
[ext_resource type="Texture2D" uid="uid://cxtmas4g0v6en" path="res://entities/sheep_right.png" id="4_5qoof"]
|
[ext_resource type="Texture2D" uid="uid://cxtmas4g0v6en" path="res://entities/sheep_right.png" id="4_5qoof"]
|
||||||
|
@ -13,24 +12,6 @@
|
||||||
[sub_resource type="CircleShape2D" id="CircleShape2D_c5tcn"]
|
[sub_resource type="CircleShape2D" id="CircleShape2D_c5tcn"]
|
||||||
radius = 8.0
|
radius = 8.0
|
||||||
|
|
||||||
[sub_resource type="Animation" id="Animation_lxieb"]
|
|
||||||
resource_name = "wobble"
|
|
||||||
length = 3.0
|
|
||||||
loop_mode = 1
|
|
||||||
step = 0.5
|
|
||||||
tracks/0/type = "value"
|
|
||||||
tracks/0/imported = false
|
|
||||||
tracks/0/enabled = true
|
|
||||||
tracks/0/path = NodePath("Sprite:rotation")
|
|
||||||
tracks/0/interp = 2
|
|
||||||
tracks/0/loop_wrap = true
|
|
||||||
tracks/0/keys = {
|
|
||||||
"times": PackedFloat32Array(0, 0.5, 1.5, 2, 3),
|
|
||||||
"transitions": PackedFloat32Array(1, 1, 1, 1, 1),
|
|
||||||
"update": 0,
|
|
||||||
"values": [0.0, -0.261799, 0.0, 0.261799, 0.0]
|
|
||||||
}
|
|
||||||
|
|
||||||
[sub_resource type="Animation" id="Animation_gokbg"]
|
[sub_resource type="Animation" id="Animation_gokbg"]
|
||||||
length = 0.001
|
length = 0.001
|
||||||
tracks/0/type = "value"
|
tracks/0/type = "value"
|
||||||
|
@ -64,6 +45,24 @@ tracks/0/keys = {
|
||||||
"values": [Vector2(0, 0), Vector2(1, 1), Vector2(-1, -1), Vector2(-1, 0), Vector2(1, -1), Vector2(-1, 1), Vector2(1, 1), Vector2(1, 0), Vector2(-1, -1), Vector2(1, 0), Vector2(0, -1)]
|
"values": [Vector2(0, 0), Vector2(1, 1), Vector2(-1, -1), Vector2(-1, 0), Vector2(1, -1), Vector2(-1, 1), Vector2(1, 1), Vector2(1, 0), Vector2(-1, -1), Vector2(1, 0), Vector2(0, -1)]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[sub_resource type="Animation" id="Animation_lxieb"]
|
||||||
|
resource_name = "wobble"
|
||||||
|
length = 3.0
|
||||||
|
loop_mode = 1
|
||||||
|
step = 0.5
|
||||||
|
tracks/0/type = "value"
|
||||||
|
tracks/0/imported = false
|
||||||
|
tracks/0/enabled = true
|
||||||
|
tracks/0/path = NodePath("Sprite:rotation")
|
||||||
|
tracks/0/interp = 2
|
||||||
|
tracks/0/loop_wrap = true
|
||||||
|
tracks/0/keys = {
|
||||||
|
"times": PackedFloat32Array(0, 0.5, 1.5, 2, 3),
|
||||||
|
"transitions": PackedFloat32Array(1, 1, 1, 1, 1),
|
||||||
|
"update": 0,
|
||||||
|
"values": [0.0, -0.261799, 0.0, 0.261799, 0.0]
|
||||||
|
}
|
||||||
|
|
||||||
[sub_resource type="AnimationLibrary" id="AnimationLibrary_6mutq"]
|
[sub_resource type="AnimationLibrary" id="AnimationLibrary_6mutq"]
|
||||||
_data = {
|
_data = {
|
||||||
"RESET": SubResource("Animation_gokbg"),
|
"RESET": SubResource("Animation_gokbg"),
|
||||||
|
@ -87,11 +86,6 @@ right_texture = ExtResource("4_5qoof")
|
||||||
scale = Vector2(3, 3)
|
scale = Vector2(3, 3)
|
||||||
shape = SubResource("CircleShape2D_c5tcn")
|
shape = SubResource("CircleShape2D_c5tcn")
|
||||||
|
|
||||||
[node name="MoveTowardsMouse" parent="." instance=ExtResource("2_tfd2i")]
|
|
||||||
scale = Vector2(30, 30)
|
|
||||||
speed = -30.0
|
|
||||||
can_detach = true
|
|
||||||
|
|
||||||
[node name="Draggable" parent="." instance=ExtResource("3_8ku7r")]
|
[node name="Draggable" parent="." instance=ExtResource("3_8ku7r")]
|
||||||
scale = Vector2(3, 3)
|
scale = Vector2(3, 3)
|
||||||
|
|
||||||
|
@ -104,14 +98,11 @@ scale = Vector2(0.5, 0.5)
|
||||||
stream = ExtResource("4_nxjnl")
|
stream = ExtResource("4_nxjnl")
|
||||||
|
|
||||||
[node name="Edible" parent="." instance=ExtResource("6_3odsh")]
|
[node name="Edible" parent="." instance=ExtResource("6_3odsh")]
|
||||||
tag = &"Sheep"
|
|
||||||
|
|
||||||
[node name="Animator" type="AnimationPlayer" parent="."]
|
[node name="Animator" type="AnimationPlayer" parent="."]
|
||||||
libraries = {
|
libraries = {
|
||||||
"": SubResource("AnimationLibrary_6mutq")
|
"": SubResource("AnimationLibrary_6mutq")
|
||||||
}
|
}
|
||||||
|
|
||||||
[connection signal="move" from="MoveTowardsMouse" to="." method="_on_move"]
|
|
||||||
[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="move" from="Draggable" to="." method="_on_drag_move"]
|
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
[gd_scene load_steps=4 format=3 uid="uid://7j1b55t8tafg"]
|
[gd_scene load_steps=3 format=3 uid="uid://7j1b55t8tafg"]
|
||||||
|
|
||||||
[ext_resource type="Script" path="res://scenes/game/cursor_magnet.gd" id="1_xk040"]
|
[ext_resource type="Script" path="res://scenes/game/cursor_magnet.gd" id="1_xk040"]
|
||||||
[ext_resource type="PackedScene" uid="uid://bvrxvrjlo5130" path="res://behaviours/move_towards_mouse.tscn" id="2_ljil3"]
|
|
||||||
|
|
||||||
[sub_resource type="CircleShape2D" id="CircleShape2D_6mkjn"]
|
[sub_resource type="CircleShape2D" id="CircleShape2D_6mkjn"]
|
||||||
radius = 16.0
|
radius = 16.0
|
||||||
|
@ -16,10 +15,5 @@ scale = Vector2(0.5, 0.5)
|
||||||
shape = SubResource("CircleShape2D_6mkjn")
|
shape = SubResource("CircleShape2D_6mkjn")
|
||||||
debug_color = Color(1, 1, 1, 0.67451)
|
debug_color = Color(1, 1, 1, 0.67451)
|
||||||
|
|
||||||
[node name="MoveTowardsMouse" parent="." instance=ExtResource("2_ljil3")]
|
|
||||||
scale = Vector2(10000, 10000)
|
|
||||||
speed = 100000.0
|
|
||||||
|
|
||||||
[connection signal="dragged" from="." to="." method="_on_dragged"]
|
[connection signal="dragged" from="." to="." method="_on_dragged"]
|
||||||
[connection signal="dropped" from="." to="." method="_on_dropped"]
|
[connection signal="dropped" from="." to="." method="_on_dropped"]
|
||||||
[connection signal="move" from="MoveTowardsMouse" to="." method="_on_move"]
|
|
||||||
|
|
Loading…
Reference in a new issue