require "Dialogs"

Arena.Resize(130, 130)
timer = 0
contador = 0
auxang = 0
Status = "Alive"

Player.sprite.color = {1, 0, 0}

Encounter.Call("AttackAnim", 1)

function Update()
	DialogUpdate()
	if (Bubbles[1] and not Bubbles[1].Activo) or not Bubbles[1] then
		timer = timer + 1
	end
	if timer == 1 then
		Bone = CreateProjectileAbs("Bullets/Bones/Long Bone", 326, 354)
		HandL = CreateProjectileAbs("Papyrus/Arms/Left Hand", 276, 348)
		HandR = CreateProjectileAbs("Papyrus/Arms/Right Hand", 371, 351)
		Bone.sprite.rotation = 4
		Bone.sprite.xscale = 1.2
		Bone.SetVar("X", 326)
		HandR.SetVar("X", 371)
	elseif (timer >= 30 and timer < 40) or (timer >= 65 and timer < 75) then
		auxang = auxang + 1
		Bone.MoveToAbs(Bone.GetVar("X") + 16 - 16*math.cos(math.rad(18*auxang)), 354 + 16*math.sin(math.rad(18*auxang)))
		HandR.MoveToAbs(HandR.GetVar("X") + 16 - 16*math.cos(math.rad(18*auxang)), 351 + 16*math.sin(math.rad(18*auxang)))
		if timer == 39 or timer == 74 then
			Bone.SetVar("X", Bone.GetVar("X") + 32)
			HandR.SetVar("X", HandR.GetVar("X") + 32)
			auxang = 0
		end
	elseif timer >= 50 and timer < 55 then
		HandR.MoveToAbs(HandR.GetVar("X") - 32/5, 351)
		HandR.SetVar("X", HandR.GetVar("X") - 32/5)
	elseif timer == 85 then
		Encounter.Call("AttackAnim", 2)
		HandR.Remove()
		HandR = nil
	elseif timer == 110 then
		if GetAlMightyGlobal("Idioma") == "Spanish" then
			Bubble("[noskip][font:papyrus][voice:papyrus]Todavía debes\naprender tu\nlección...", "rightwide", 490.5, 385, 40, 90, 1)
		elseif GetAlMightyGlobal("Idioma") == "Russian" then
			Bubble("[noskip][font:papyrus][voice:papyrus]Ты всё ещё\nдолжен выучить\nсвой урок...", "rightwide", 490.5, 385, 40, 90, 1)
		else
			Bubble("[noskip][font:papyrus][voice:papyrus]You still need\nto learn your\nlesson...", "rightwide", 490.5, 385, 40, 90, 1)
		end
		timer = 111
	elseif timer >= 135 and timer < 145 then
		Bone.sprite.rotation = 4 + 10*math.sin(math.rad(9*(timer - 134)))
		Bone.MoveToAbs(276 + 114*math.cos(math.rad(Bone.sprite.rotation)), 346 + 114*math.sin(math.rad(Bone.sprite.rotation)))
	elseif timer >= 145 and timer < 180 then
		Bone.sprite.rotation = 14 - 120*math.sin(math.rad(90/35*(timer - 144)))
		Bone.MoveToAbs(276 + 114*math.cos(math.rad(Bone.sprite.rotation)), 346 + 114*math.sin(math.rad(Bone.sprite.rotation)))
	end
	if Status == "Dead" then
		contador = contador + 1
		if contador == 1 then
			Black = CreateSprite("Bullets/Bones/Body","Top")
			Black.color = {0,0,0}
			Black.Scale(640/5, 480)
			Black.MoveTo(320, 240)
			Audio.PlaySound("damage")
		elseif contador == 120 then
			Black.Remove()
			Bone.Remove()
			HandL.Remove()
			Encounter.Call("Reset")
		end
	end
end

function OnHit(bullet)
	Status = "Dead"
end