mirror of
https://github.com/Steffo99/hella-farm.git
synced 2024-11-21 23:54:23 +00:00
Break Draggable
This commit is contained in:
parent
6d5360ec35
commit
36c1743979
6 changed files with 79 additions and 85 deletions
|
@ -1,21 +1,13 @@
|
||||||
|
@icon("res://behaviours/draggable.svg")
|
||||||
extends Area2D
|
extends Area2D
|
||||||
class_name Draggable
|
class_name Draggable
|
||||||
|
|
||||||
|
|
||||||
signal move(movement: Vector2)
|
|
||||||
signal dragged
|
signal dragged
|
||||||
signal dropped
|
signal dropped
|
||||||
|
|
||||||
|
|
||||||
@onready var mover: Node2D = $"MatchMousePosition"
|
var being_dragged: bool = false
|
||||||
|
|
||||||
var being_dragged: bool:
|
|
||||||
get:
|
|
||||||
return being_dragged
|
|
||||||
set(value):
|
|
||||||
being_dragged = value
|
|
||||||
mover.set_process(being_dragged)
|
|
||||||
mover.set_physics_process(being_dragged)
|
|
||||||
|
|
||||||
|
|
||||||
func drag():
|
func drag():
|
||||||
|
@ -25,10 +17,3 @@ func drag():
|
||||||
func drop():
|
func drop():
|
||||||
being_dragged = false
|
being_dragged = false
|
||||||
dropped.emit()
|
dropped.emit()
|
||||||
|
|
||||||
|
|
||||||
func _ready():
|
|
||||||
being_dragged = false
|
|
||||||
|
|
||||||
func _on_move(movement: Vector2):
|
|
||||||
move.emit(movement)
|
|
||||||
|
|
39
behaviours/draggable.svg
Normal file
39
behaviours/draggable.svg
Normal file
|
@ -0,0 +1,39 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||||
|
<svg
|
||||||
|
viewBox="0 0 512 512"
|
||||||
|
version="1.1"
|
||||||
|
id="svg1"
|
||||||
|
sodipodi:docname="draggable.svg"
|
||||||
|
inkscape:version="1.3.2 (091e20ef0f, 2023-11-25, custom)"
|
||||||
|
width="16"
|
||||||
|
height="16"
|
||||||
|
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
|
||||||
|
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
|
||||||
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
|
xmlns:svg="http://www.w3.org/2000/svg">
|
||||||
|
<defs
|
||||||
|
id="defs1" />
|
||||||
|
<sodipodi:namedview
|
||||||
|
id="namedview1"
|
||||||
|
pagecolor="#ffffff"
|
||||||
|
bordercolor="#000000"
|
||||||
|
borderopacity="0.25"
|
||||||
|
inkscape:showpageshadow="2"
|
||||||
|
inkscape:pageopacity="0.0"
|
||||||
|
inkscape:pagecheckerboard="0"
|
||||||
|
inkscape:deskcolor="#d1d1d1"
|
||||||
|
inkscape:zoom="1.6464844"
|
||||||
|
inkscape:cx="217.1293"
|
||||||
|
inkscape:cy="209.84104"
|
||||||
|
inkscape:window-width="1920"
|
||||||
|
inkscape:window-height="1020"
|
||||||
|
inkscape:window-x="3200"
|
||||||
|
inkscape:window-y="32"
|
||||||
|
inkscape:window-maximized="1"
|
||||||
|
inkscape:current-layer="svg1" />
|
||||||
|
<!--! Font Awesome Free 6.5.2 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) Copyright 2024 Fonticons, Inc. -->
|
||||||
|
<path
|
||||||
|
d="m 278.6,9.4 c -12.5,-12.5 -32.8,-12.5 -45.3,0 l -64,64 c -12.5,12.5 -12.5,32.8 0,45.3 12.5,12.5 32.8,12.5 45.3,0 l 9.4,-9.4 V 224 H 109.3 l 9.4,-9.4 c 12.5,-12.5 12.5,-32.8 0,-45.3 -12.5,-12.5 -32.8,-12.5 -45.3,0 l -64,64 c -12.5,12.5 -12.5,32.8 0,45.3 l 64,64 c 12.5,12.5 32.8,12.5 45.3,0 12.5,-12.5 12.5,-32.8 0,-45.3 l -9.4,-9.4 H 224 v 114.8 l -9.4,-9.4 c -12.5,-12.5 -32.8,-12.5 -45.3,0 -12.5,12.5 -12.5,32.8 0,45.3 l 64,64 c 12.5,12.5 32.8,12.5 45.3,0 l 64,-64 c 12.5,-12.5 12.5,-32.8 0,-45.3 -12.5,-12.5 -32.8,-12.5 -45.3,0 l -9.4,9.4 V 288 h 114.8 l -9.4,9.4 c -12.5,12.5 -12.5,32.8 0,45.3 12.5,12.5 32.8,12.5 45.3,0 l 64,-64 c 12.5,-12.5 12.5,-32.8 0,-45.3 l -64,-64 c -12.5,-12.5 -32.8,-12.5 -45.3,0 -12.5,12.5 -12.5,32.8 0,45.3 l 9.4,9.4 H 288 V 109.3 l 9.4,9.4 c 12.5,12.5 32.8,12.5 45.3,0 12.5,-12.5 12.5,-32.8 0,-45.3 l -64,-64 z"
|
||||||
|
id="path1"
|
||||||
|
style="fill:#8da5f3" />
|
||||||
|
</svg>
|
After Width: | Height: | Size: 2.1 KiB |
37
behaviours/draggable.svg.import
Normal file
37
behaviours/draggable.svg.import
Normal file
|
@ -0,0 +1,37 @@
|
||||||
|
[remap]
|
||||||
|
|
||||||
|
importer="texture"
|
||||||
|
type="CompressedTexture2D"
|
||||||
|
uid="uid://bepjyaq1y3g7w"
|
||||||
|
path="res://.godot/imported/draggable.svg-7f8260afa88b76990683b55fd9af07eb.ctex"
|
||||||
|
metadata={
|
||||||
|
"vram_texture": false
|
||||||
|
}
|
||||||
|
|
||||||
|
[deps]
|
||||||
|
|
||||||
|
source_file="res://behaviours/draggable.svg"
|
||||||
|
dest_files=["res://.godot/imported/draggable.svg-7f8260afa88b76990683b55fd9af07eb.ctex"]
|
||||||
|
|
||||||
|
[params]
|
||||||
|
|
||||||
|
compress/mode=0
|
||||||
|
compress/high_quality=false
|
||||||
|
compress/lossy_quality=0.7
|
||||||
|
compress/hdr_compression=1
|
||||||
|
compress/normal_map=0
|
||||||
|
compress/channel_pack=0
|
||||||
|
mipmaps/generate=false
|
||||||
|
mipmaps/limit=-1
|
||||||
|
roughness/mode=0
|
||||||
|
roughness/src_normal=""
|
||||||
|
process/fix_alpha_border=true
|
||||||
|
process/premult_alpha=false
|
||||||
|
process/normal_map_invert_y=false
|
||||||
|
process/hdr_as_srgb=false
|
||||||
|
process/hdr_clamp_exposure=false
|
||||||
|
process/size_limit=0
|
||||||
|
detect_3d/compress_to=1
|
||||||
|
svg/scale=1.0
|
||||||
|
editor/scale_with_editor_scale=false
|
||||||
|
editor/convert_colors_with_editor_theme=false
|
|
@ -1,15 +1,8 @@
|
||||||
[gd_scene load_steps=3 format=3 uid="uid://dijcjahkddudv"]
|
[gd_scene load_steps=2 format=3 uid="uid://dijcjahkddudv"]
|
||||||
|
|
||||||
[ext_resource type="Script" path="res://behaviours/draggable.gd" id="1_hdedq"]
|
[ext_resource type="Script" path="res://behaviours/draggable.gd" id="1_hdedq"]
|
||||||
[ext_resource type="PackedScene" uid="uid://bvrxvrjlo5130" path="res://behaviours/move_towards_mouse.tscn" id="2_gi6xd"]
|
|
||||||
|
|
||||||
[node name="Draggable" type="Area2D"]
|
[node name="Draggable" type="Area2D"]
|
||||||
collision_layer = 0
|
collision_layer = 0
|
||||||
collision_mask = 0
|
collision_mask = 0
|
||||||
script = ExtResource("1_hdedq")
|
script = ExtResource("1_hdedq")
|
||||||
|
|
||||||
[node name="MatchMousePosition" parent="." instance=ExtResource("2_gi6xd")]
|
|
||||||
scale = Vector2(10000, 10000)
|
|
||||||
speed = 3600.0
|
|
||||||
|
|
||||||
[connection signal="move" from="MatchMousePosition" to="." method="_on_move"]
|
|
||||||
|
|
|
@ -1,37 +0,0 @@
|
||||||
extends Node2D
|
|
||||||
class_name EatTarget
|
|
||||||
|
|
||||||
|
|
||||||
signal eaten(target: Node2D)
|
|
||||||
signal move(movement: Vector2)
|
|
||||||
|
|
||||||
@export var tag: StringName:
|
|
||||||
get:
|
|
||||||
return tag
|
|
||||||
set(value):
|
|
||||||
tag = value
|
|
||||||
if hunt_target != null:
|
|
||||||
hunt_target.tag = value
|
|
||||||
if eater != null:
|
|
||||||
eater.tag = value
|
|
||||||
|
|
||||||
|
|
||||||
@onready var hunt_target: HuntTarget = $"HuntTarget"
|
|
||||||
@onready var eater: Eater = $"Eater"
|
|
||||||
@onready var move_towards: MoveTowardsTarget = $"MoveTowardsTarget"
|
|
||||||
|
|
||||||
func _ready():
|
|
||||||
hunt_target.tag = tag
|
|
||||||
eater.tag = tag
|
|
||||||
|
|
||||||
func _on_target_selected(body: Node2D) -> void:
|
|
||||||
move_towards.target = body
|
|
||||||
|
|
||||||
func _on_target_abandoned(_body: Node2D) -> void:
|
|
||||||
move_towards.target = null
|
|
||||||
|
|
||||||
func _on_eater_eaten(edible):
|
|
||||||
eaten.emit(edible)
|
|
||||||
|
|
||||||
func _on_move_towards_target_move(movement):
|
|
||||||
move.emit(movement)
|
|
|
@ -1,23 +0,0 @@
|
||||||
[gd_scene load_steps=5 format=3 uid="uid://b7bdlh5akhi8s"]
|
|
||||||
|
|
||||||
[ext_resource type="Script" path="res://behaviours/eat_target.gd" id="1_tlnlt"]
|
|
||||||
[ext_resource type="PackedScene" uid="uid://dxmodn8mbvw0i" path="res://behaviours/hunt_target.tscn" id="2_c8wdv"]
|
|
||||||
[ext_resource type="PackedScene" uid="uid://jg7qkbswgqjc" path="res://behaviours/eater.tscn" id="3_ir2yh"]
|
|
||||||
[ext_resource type="PackedScene" uid="uid://kceb2v2dm0qn" path="res://behaviours/move_towards_target.tscn" id="4_1qc2q"]
|
|
||||||
|
|
||||||
[node name="EatTarget" type="Node2D"]
|
|
||||||
script = ExtResource("1_tlnlt")
|
|
||||||
|
|
||||||
[node name="HuntTarget" parent="." instance=ExtResource("2_c8wdv")]
|
|
||||||
scale = Vector2(16, 16)
|
|
||||||
give_up_secs = 5.0
|
|
||||||
|
|
||||||
[node name="Eater" parent="." instance=ExtResource("3_ir2yh")]
|
|
||||||
scale = Vector2(2.5, 2.5)
|
|
||||||
|
|
||||||
[node name="MoveTowardsTarget" parent="." instance=ExtResource("4_1qc2q")]
|
|
||||||
|
|
||||||
[connection signal="target_abandoned" from="HuntTarget" to="." method="_on_target_abandoned"]
|
|
||||||
[connection signal="target_selected" from="HuntTarget" to="." method="_on_target_selected"]
|
|
||||||
[connection signal="eaten" from="Eater" to="." method="_on_eater_eaten"]
|
|
||||||
[connection signal="move" from="MoveTowardsTarget" to="." method="_on_move_towards_target_move"]
|
|
Loading…
Reference in a new issue