52 lines
1.2 KiB
GDScript
52 lines
1.2 KiB
GDScript
extends KinematicBody2D
|
|
|
|
class_name PersonBody
|
|
|
|
onready var person : PersonRoot = get_parent()
|
|
onready var sprite : AnimatedSprite = $PersonSprite
|
|
|
|
var hover = false
|
|
var held = false
|
|
var in_spot = false
|
|
|
|
func pickup():
|
|
hover = false
|
|
held = true
|
|
#change cursor to clenched hand
|
|
|
|
func drop():
|
|
held = false
|
|
hover = true
|
|
# ensure collisions to avoid stacking persons
|
|
# warning-ignore:return_value_discarded
|
|
move_and_slide(Vector2.ZERO, Vector2.UP)
|
|
# apply the collision movement back to the root of the person
|
|
person.global_position += position
|
|
position = Vector2.ZERO
|
|
#change cursor to idle hand
|
|
|
|
func _input_event(_viewport: Object, event: InputEvent, _shape_idx: int):
|
|
if event is InputEventMouseButton:
|
|
if event.button_index == BUTTON_LEFT and event.pressed:
|
|
pickup()
|
|
elif held and event.button_index == BUTTON_LEFT and !event.pressed:
|
|
drop()
|
|
|
|
func _physics_process(_delta):
|
|
if held:
|
|
person.global_transform.origin = get_global_mouse_position()
|
|
|
|
func _process(_delta):
|
|
return
|
|
# warning-ignore:unreachable_code
|
|
if hover:
|
|
sprite.self_modulate = Color(randf(),randf(),randf(), 1)
|
|
|
|
func onMouseEnter():
|
|
hover = true
|
|
person.start_display()
|
|
|
|
func onMouseLeft():
|
|
hover = false
|
|
person.stop_display()
|