2021-10-21 06:24:27 +00:00
|
|
|
extends RigidBody2D
|
2021-10-21 03:33:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
# Declare member variables here. Examples:
|
|
|
|
# var a = 2
|
|
|
|
# var b = "text"
|
2021-10-21 06:24:27 +00:00
|
|
|
var held = false
|
2021-11-01 03:48:20 +00:00
|
|
|
var originalPos
|
|
|
|
var snapOriginalPos = false
|
2021-10-21 03:33:14 +00:00
|
|
|
|
|
|
|
# Called when the node enters the scene tree for the first time.
|
|
|
|
func _ready():
|
2021-11-01 03:48:20 +00:00
|
|
|
pass
|
2021-10-21 03:33:14 +00:00
|
|
|
|
2021-10-21 08:18:31 +00:00
|
|
|
var click_radius = 16
|
2021-10-21 03:33:14 +00:00
|
|
|
var orient = 0;
|
|
|
|
|
|
|
|
func _input(event):
|
|
|
|
if event is InputEventMouseButton and event.button_index == BUTTON_LEFT:
|
2021-10-21 06:24:27 +00:00
|
|
|
if (event.position - position).length() < click_radius:
|
|
|
|
if not held and event.pressed:
|
|
|
|
held = true;
|
2021-10-21 03:33:14 +00:00
|
|
|
|
2021-10-21 06:24:27 +00:00
|
|
|
if held and not event.pressed:
|
|
|
|
held = false;
|
2021-11-01 03:48:20 +00:00
|
|
|
if (position.x > 17.4 and position.x < 337.5) and (position.y > 20.2 and position.y < 335.5):
|
|
|
|
position = position.snapped(Vector2(32, 32)) + Vector2(2, 2)
|
|
|
|
else:
|
|
|
|
position = originalPos
|
|
|
|
|
2021-10-21 03:33:14 +00:00
|
|
|
|
2021-10-21 06:24:27 +00:00
|
|
|
if event is InputEventMouseMotion and held:
|
2021-11-01 03:48:20 +00:00
|
|
|
if snapOriginalPos == false:
|
|
|
|
originalPos = position
|
|
|
|
snapOriginalPos = true
|
2021-10-21 03:33:14 +00:00
|
|
|
position = event.position;
|
|
|
|
|
|
|
|
if event.is_action_pressed("ui_rotate"):
|
|
|
|
if(event.position - position).length() < click_radius:
|
|
|
|
rotate(PI/2);
|
|
|
|
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
|
|
|
#func _process(delta):
|
|
|
|
# pass
|
2021-10-21 06:24:27 +00:00
|
|
|
|
|
|
|
func pickup():
|
|
|
|
if held:
|
|
|
|
return
|
|
|
|
mode = RigidBody2D.MODE_STATIC
|
|
|
|
held = true
|
|
|
|
|
|
|
|
func drop(impulse=Vector2.ZERO):
|
|
|
|
if held:
|
|
|
|
mode = RigidBody2D.MODE_RIGID
|
|
|
|
apply_central_impulse(impulse)
|
|
|
|
held = false
|
2021-11-01 03:48:20 +00:00
|
|
|
snapOriginalPos = false
|