mlpcardgame/Scenes/Components/Card.gd

29 lines
851 B
GDScript3
Raw Normal View History

2019-05-04 21:42:07 +00:00
extends Spatial
2019-05-04 22:01:00 +00:00
signal card_selected()
signal card_unselected()
2019-05-04 21:42:07 +00:00
2019-05-04 23:18:55 +00:00
var lifted := false
onready var animation := $Border/AnimationPlayer
2019-05-04 21:42:07 +00:00
func _mouse_hover():
2019-05-04 22:01:00 +00:00
emit_signal("card_selected")
2019-05-04 21:42:07 +00:00
2019-05-04 22:01:00 +00:00
func _mouse_blur():
2019-05-04 23:18:55 +00:00
emit_signal("card_unselected")
func _input_event(camera, event, click_position, click_normal, shape_idx):
if event is InputEventMouseButton and event.button_index == BUTTON_LEFT:
if event.pressed:
lifted = true
animation.play("lift")
else:
lifted = false
animation.play_backwards("lift")
if lifted and event is InputEventMouseMotion:
var origin: Vector3 = camera.project_ray_origin(event.position)
var direction: Vector3 = camera.project_ray_normal(event.position)
var denom := Vector3.UP.dot(direction)
var t: float = (-camera.transform.origin).dot(Vector3.UP) / denom;
transform.origin = origin + direction * t