tool
extends Enemy


func _on_Area2D_body_entered(body: Node) -> void:
	if not _damage_enabled: return
	if body.name == 'Player':
		var player:Player = body
		player.die()

func _physics_process(delta: float) -> void:
	if not _is_alive: return
	if _triggerd and _damage_enabled:
		var player_direction = (_player_ref.position - global_position).normalized()
		$Sprite.scale = Vector2(-1 if player_direction.x < 0 else 1, 1)
		if _get_pit_direction() == 0 and dont_fall_patrol:
			_velocity.x = $Sprite.scale.x * walking_speed * 2
		else:
			_velocity.x = 0
		_velocity.y += gravity * delta
		$AnimationPlayer.play("attack")
		_velocity = move_and_slide(_velocity, Vector2.UP)
		pass
		



func _on_TriggerZone_body_entered(body: Node) -> void:
	if body.name == 'Player':
		_triggerd = true
		_player_ref = body


func _on_TriggerZone_body_exited(body: Node) -> void:
	if body.name == 'Player':
		_triggerd = false
		_player_ref = null
