51 lines
1.7 KiB (Stored with Git LFS)
GDScript3
51 lines
1.7 KiB (Stored with Git LFS)
GDScript3
extends Panel
|
|
|
|
|
|
# Declare member variables here. Examples:
|
|
# var a = 2
|
|
# var b = "text"
|
|
|
|
var snap_position = Vector2(0,0)
|
|
var snap_velocity = 800
|
|
var is_dragged = false
|
|
export var is_mergable = false
|
|
export(String) var caption
|
|
export(Texture) var texture
|
|
|
|
# Called when the node enters the scene tree for the first time.
|
|
func _ready():
|
|
snap_position = rect_position
|
|
$Label.text = caption
|
|
$TextureRect.texture = texture
|
|
|
|
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
|
func _process(delta):
|
|
if not rect_position == snap_position and not is_dragged:
|
|
if (snap_position - rect_position).length() < 10:
|
|
rect_position = snap_position
|
|
else:
|
|
var deltapos_angle = (snap_position - rect_position).angle()
|
|
rect_position += Vector2(
|
|
snap_velocity * cos(deltapos_angle),
|
|
snap_velocity * sin(deltapos_angle)
|
|
) * delta
|
|
if is_mergable:
|
|
var areas = $Area2D.get_overlapping_areas()
|
|
var card_areas = Array()
|
|
for a in areas:
|
|
if "is_mergable" in a.get_parent() and a.get_parent().is_mergable:
|
|
card_areas.append(a)
|
|
if card_areas.size() == 1:
|
|
var parent = card_areas[0].get_parent()
|
|
if not parent.is_dragged and not is_dragged and not snap_position == rect_position:
|
|
queue_free()
|
|
if not snap_position == rect_position:
|
|
pass #TODO: reskin card
|
|
|
|
func _on_Card_gui_input(event):
|
|
if event is InputEventScreenDrag:
|
|
is_dragged = true;
|
|
rect_position += event.relative
|
|
elif Input.is_action_just_released("click"):
|
|
is_dragged = false
|