extends "res://Bad.gd"

# class member variables go here, for example:
# var a = 2
# var b = "textvar"

var rot_speed = 1

func _ready():
	starting_health = 5000
	health = starting_health
	speed = 10
	position.x = 700
	position.y = 300

var splitting = false

func _process(delta):
	rotation += delta*rot_speed
	if rotation > 2*PI:
		rotation = 0
	
	if health < starting_health*0.88:
		$MainSprite.frame = 1
	if health < starting_health*0.76:
		$MainSprite.frame = 2
	if health < starting_health*0.64:
		$MainSprite.frame = 3
	if health < starting_health*0.52:
		$MainSprite.frame = 4
	if health < starting_health*0.40:
		$MainSprite.frame = 5
	if health < starting_health*0.28:
		$MainSprite.frame = 6
	if health < starting_health*0.16:
		$CollisionBox.disabled = true
		$TopHalf.visible = true
		$BotHalf.visible = true
		$MainSprite.visible = false
		if rotation_degrees > 45 && rotation_degrees < 70:
			splitting = true
	
	if splitting:
		rot_speed = 0
		$TopHalf.position.y -= delta*500
		$TopHalf.position.x -= delta*250
		$BotHalf.position.y += delta*500
		$BotHalf.position.x += delta*250
		
		$TopHalf.rotation += delta
		$BotHalf.rotation -= delta