extends KinematicBody2D

const GRAVITY = 700.0

var speed = Vector2(300.0, 400.0)
var _velocity = Vector2.ZERO
var dir = -1

func _physics_process(delta):
	var is_on_floor = $floor_detector.is_colliding()
	if is_on_floor:
		_velocity.y = -200.0
	else:
		_velocity.y += GRAVITY * delta
	_velocity.x = dir * speed.x
	move_and_slide(_velocity)
	
func death():
	$AnimationPlayer.play("death")
	
func _on_damage_area_body_entered(body):
	if body.has_method("apply_damage"):
		body.apply_damage(1, "damage")

func _ready():
	$life_time.connect("timeout", self, "death")
	$damage_area.connect("body_entered", self, "_on_damage_area_body_entered")



