tool
extends Node2D
class_name Stomp

export var to_point := Vector2(0, 0) setget set_to_position
export var duration := 2.0 setget set_duration
export var delay := .5 setget set_delay
export(String, "UP_DOWN", "LEFT_RIGHT") var g = "UP_DOWN"

var sprite:Sprite
var tween:Tween
var _is_ready = false

  
func _ready() -> void:
  _is_ready = true
  sprite = $Sprite
  tween = $Tween
  tween.repeat = true
  start_motion()
func _enter_tree() -> void:
  if _is_ready: tween.resume_all()

func _on_DeathZone_body_entered(body:Node) -> void:
  if body.name == "Player":
	  body.die()

func set_to_position(val):
  print("set_to_position")

  to_point = val
  start_motion()
  
func set_duration(val):
  print("set_duration")
  duration = val
  start_motion()
  
func set_delay(val):
  print("set_delay")
  delay = val
  start_motion()
	  
func start_motion():
  if not _is_ready: return

  print("Stomp Start Motion")
  sprite.position = Vector2.ZERO
  tween.stop_all()
  tween.remove_all()
  print(tween.interpolate_property(sprite, "position", Vector2.ZERO, to_point, duration, Tween.TRANS_LINEAR, Tween.EASE_IN, delay))
  print(tween.interpolate_property(sprite, "position", to_point, Vector2.ZERO, duration, Tween.TRANS_LINEAR, Tween.EASE_IN, duration+(delay*2)))
  print(tween.start())
