jump = 0
maxjump = 50
state = 1
timer = 0
newpX = Player.x
newpY = -100
Volumen = 1
intro = 1
wait = 0
Hits = 0
tableaux = 0

FireBalls = {}
FireExplotions = {}
Explotions = {}
Flames = {}
Shells = {}
Smoke = {}
Mines = {}
Hammers = {}

Black = CreateSprite("Rotatory Arena Pixel","Top")
Black2 = CreateProjectileAbs("Rotatory Arena Pixel", 320, 30, "BelowArena")
Black3 = CreateProjectileAbs("Rotatory Arena Pixel", 60, 60, "BelowArena")
Bowsy = CreateProjectileAbs("Bowsy Attacks Sprites/Bowsy/Intro/1", Arena.x + 90, Arena.y + 5 + 16*1.8, "BelowBullet")
Ventilator = CreateProjectileAbs("Bowsy Attacks Sprites/Helikoopa/1", Arena.x + 150, Arena.y + 9, "BelowBullet")
Helikoopa = CreateProjectileAbs("Bowsy Attacks Sprites/Helikoopa/Front/Confuse", Ventilator.absx, Ventilator.absy + 32, "BelowBullet")
HeliBowsy = CreateProjectileAbs("Bowsy Attacks Sprites/Bowsy/Car/Empty", Helikoopa.absx, Helikoopa.absy + 24*1.8, "BelowBullet")
Black.color = {0,0,0}
Black.Scale(640, 480)
Black2.sprite.color = {0,0,0}
Black2.sprite.Scale(640, 60)
Black3.sprite.color = {0,0,0}
Black3.sprite.Scale(120, 60)
Bowsy.sprite.Scale(1.8,1.8)
Ventilator.sprite.Scale(2,2)
Helikoopa.sprite.Scale(2,2)
HeliBowsy.sprite.Scale(1.8,1.8)
Helikoopa.sprite.SetParent(Ventilator.sprite)
HeliBowsy.sprite.SetParent(Helikoopa.sprite)
Black.MoveTo(320, 240)

Player.lv = 1
Player.hp = 20
Encounter.Call("ConfigurateKR", {false, false})
Arena.ResizeImmediate(400, 200)
Player.sprite.color = {0, 60/255, 1}
Player.SetControlOverride(true)
SetPPCollision(true)

topedge = Arena.height/2 - 8
bottomedge = -Arena.height/2 + 8

function Update()
	if intro > 0 then
		intro = intro + 1
		if intro >= 30 and intro < 60 then
			Black.alpha = 1/30*(60 - intro)
		elseif intro == 60 then
			Black.alpha = 0
			Bowsy.sprite.SetAnimation({"Bowsy Attacks Sprites/Bowsy/Intro/1","Bowsy Attacks Sprites/Bowsy/Intro/2","Bowsy Attacks Sprites/Bowsy/Intro/3","Bowsy Attacks Sprites/Bowsy/Intro/4","Bowsy Attacks Sprites/Bowsy/Intro/5"},0.08)
			Bowsy.sprite.loopmode = "ONESHOT"
			Audio.PlaySound("uh")
		elseif intro == 110 then
			Bowsy.sprite.SetAnimation({"Bowsy Attacks Sprites/Bowsy/Intro/6","Bowsy Attacks Sprites/Bowsy/Intro/7","Bowsy Attacks Sprites/Bowsy/Intro/8","Bowsy Attacks Sprites/Bowsy/Intro/9"},0.1)
			Bowsy.sprite.loopmode = "ONESHOT"
		elseif intro == 160 then
			Bowsy.sprite.SetAnimation({"Bowsy Attacks Sprites/Bowsy/Intro/10","Bowsy Attacks Sprites/Bowsy/Intro/11"},0.08)
			Bowsy.sprite.loopmode = "ONESHOT"
			Bowsy.SetVar("diffX", 1.5)
			Bowsy.SetVar("velY", 8)
			Audio.PlaySound("jump")
			Audio.PlaySound("laugh1")
		elseif intro > 160 and intro <= 200 then
			Bowsy.Move(Bowsy.GetVar("diffX"), Bowsy.GetVar("velY"))
			Bowsy.SetVar("velY", Bowsy.GetVar("velY") - 0.4)
		elseif intro == 201 then
			Bowsy.Remove()
			Helikoopa.sprite.Set("Bowsy Attacks Sprites/Helikoopa/Front/Normal")
			HeliBowsy.sprite.SetAnimation({"Bowsy Attacks Sprites/Bowsy/Car/Coming Out Front/4","Bowsy Attacks Sprites/Bowsy/Car/Coming Out Front/3","Bowsy Attacks Sprites/Bowsy/Car/Coming Out Front/2","Bowsy Attacks Sprites/Bowsy/Car/Coming Out Front/1"}, 0.07)
			HeliBowsy.sprite.loopmode = "ONESHOT"
			ventanim = 0
			framevel = 3
			framevent = 1
			bowsymusic = true
			Audio.PlaySound("bowsypoundhelikoopa")
		elseif intro == 202 and Ventilator.absy < Arena.y + Arena.height - 40 then
			Ventilator.Move(0, 1)
			intro = 201
		elseif intro == 203 then
			MovementFloating = 0
		elseif intro > 203 and NewAudio.isStopped("Bowsy Jr") then
			intro = 0
			X = 0
			direction = "Right"
			status = "Normal"
			Frame = 1
		end
	else
		timer = timer + 1
		if Hits == 0 then --The wave patterns is here --------------------------------------------------------------------------------------------------------
			if timer == 30 then
				ThrowFire = 0
			elseif timer == 1400 then
				Pound = 0
				wait = 0
			elseif timer%480 == 0 and not Pound and not Hurt then
				ThrowKoopas = 0
			elseif timer%180 == 0 and not Pound and not Hurt then
				ThrowFire = 0
			end 
		elseif Hits == 1 then
			if timer == 30 then
				ThrowHammers = 0
			elseif timer == 840 then
				Cannon = 0
			elseif timer == 2120 then
				Pound = 0
				wait = 0
			elseif timer%480 == 0 and not Pound and not Hurt and not Cannon then
				ThrowKoopas = 0
			elseif timer%180 == 0 and not Pound and not Hurt and not Cannon then
				ThrowFire = 0
			end 
		elseif Hits == 2 then
			if timer == 30 then
				ThrowHammers = 0
			elseif timer == 840 then
				Cannon = 0
			elseif timer == 2120 then
				Pound = 0
				wait = 0
			elseif timer%480 == 0 and not Pound and not Hurt and not Cannon then
				ThrowKoopas = 0
			elseif timer%180 == 0 and not Pound and not Hurt and not Cannon then
				ThrowFire = 0
			end 
		end --And ends here -----------------------------------------------------------------------------------------------------------------------------------
		if Hurt then
			Hurt = Hurt + 1
			if Hits < 3 then
				if Hurt == 60 then
					hurtfase = "Derecha"
					ventanim = 0
					framevel = 3
				elseif Hurt == 61 and Ventilator.absy < Arena.y + Arena.height - 40 then
					Ventilator.Move(0, 1)
					Hurt = 60
				elseif Hurt == 62 then
					if hurtfase then
						Hurt = 61
					else
						HeliBowsy.sprite.SetAnimation({"Bowsy Attacks Sprites/Bowsy/Car/Coming Inside Front/1","Bowsy Attacks Sprites/Bowsy/Car/Coming Inside Front/2","Bowsy Attacks Sprites/Bowsy/Car/Coming Inside Front/3","Bowsy Attacks Sprites/Bowsy/Car/Coming Inside Front/4","Bowsy Attacks Sprites/Bowsy/Car/Empty"}, 0.08)
						HeliBowsy.sprite.loopmode = "ONESHOT"
						MovementFloating = 0
					end
				elseif Hurt == 102 then
					Helikoopa.sprite.Set("Bowsy Attacks Sprites/Helikoopa/Front/Confuse")
					HeliBowsy.sprite.SetAnimation({"Bowsy Attacks Sprites/Bowsy/Car/Coming Out Front/4","Bowsy Attacks Sprites/Bowsy/Car/Coming Out Front/3","Bowsy Attacks Sprites/Bowsy/Car/Coming Out Front/2","Bowsy Attacks Sprites/Bowsy/Car/Coming Out Front/1"}, 0.08)
					HeliBowsy.sprite.loopmode = "ONESHOT"
				elseif Hurt == 142 then
					HeliBowsy.sprite.Set("Bowsy Attacks Sprites/Bowsy/Car/Smiling/2")
					Audio.PlaySound("laugh2")
				elseif Hurt == 152 then
					HeliBowsy.sprite.Set("Bowsy Attacks Sprites/Bowsy/Car/Smiling/3")
				elseif Hurt == 172 then
					Hurt = nil
					timer = 0
					if Hits == 2 then
						status = "Angry"
					end
				end
				if hurtfase then
					if hurtfase == "Derecha" then
						Ventilator.sprite.rotation = Ventilator.sprite.rotation + 3
						if Ventilator.sprite.rotation >= 15 and Ventilator.sprite.rotation < 180 then
							hurtfase = "Izquierda"
						elseif Ventilator.sprite.rotation == 0 and Hurt >= 61 then
							hurtfase = nil
						end
					elseif hurtfase == "Izquierda" then
						Ventilator.sprite.rotation = Ventilator.sprite.rotation - 3
						if Ventilator.sprite.rotation <= 345 and Ventilator.sprite.rotation > 180 then
							hurtfase = "Derecha"
						elseif Ventilator.sprite.rotation == 0 and Hurt >= 61 then
							hurtfase = nil
						end
					end
				end
			else
				if Hurt == 60 then
					ventanim = 0
					altervel = true
				elseif Hurt == 61 and Helikoopa.absy < 130 + Arena.height/2 then
					Helikoopa.MoveTo(Helikoopa.x + math.random(-2,2), Helikoopa.y + 0.5)
					if Helikoopa.y > Arena.y - 40 + Arena.height/2 and not explotion1 then
						back = 5
						explotion1 = true
						Explotion = CreateProjectileAbs("Bowsy Attacks Sprites/boom", Helikoopa.x + math.random(-30,26), Helikoopa.y,"Top")
						Explotion.sprite.Scale(0,0)
						Explotion.SetVar("dead", true)
						table.insert(Explotions, Explotion)
						Audio.PlaySound("Bomb")
					elseif Helikoopa.y > Arena.y - 10 + Arena.height/2 and not explotion2 then
						back = 5
						explotion2 = true
						Explotion = CreateProjectileAbs("Bowsy Attacks Sprites/boom", Helikoopa.x + math.random(-30,26), Helikoopa.y,"Top")
						Explotion.sprite.Scale(0,0)
						Explotion.SetVar("dead", true)
						table.insert(Explotions, Explotion)
						Audio.PlaySound("Bomb")
					elseif Helikoopa.y > Arena.y + 20 + Arena.height/2 and not explotion3 then
						back = 5
						explotion3 = true
						Explotion = CreateProjectileAbs("Bowsy Attacks Sprites/boom", Helikoopa.x + math.random(-30,26), Helikoopa.y,"Top")
						Explotion.sprite.Scale(0,0)
						Explotion.SetVar("dead", true)
						table.insert(Explotions, Explotion)
						Audio.PlaySound("Bomb")
					end
					Hurt = 60
					Xkoopa = Helikoopa.x
					Ykoopa = Helikoopa.y
				elseif Hurt > 61 and Hurt < 180 then
					Helikoopa.MoveTo(Xkoopa + math.random(-2,2), Ykoopa + math.random(-2,2))
				elseif Hurt == 180 then
					local XHelikoopa = Helikoopa.x
					local YHelikoopa = Helikoopa.y
					HeliBowsy.Remove()
					Ventilator.Remove()
					Helikoopa.Remove()
					Shocks.Remove()
					ventanim = nil
					altervel = nil
					framevel = nil
					framevent = nil
					HeliBowsy = CreateSprite("Bowsy Attacks Sprites/Bowsy/Dead","Top")
					HeliBowsy.MoveTo(XHelikoopa, YHelikoopa + 24*1.8)
					HeliBowsy.Scale(1.8,1.8)
					HeliBowsy.SetVar("Y", 3)
					HeliBowsy.SetVar("X", math.random(-2,2))
					HeliBowsy.SetVar("rot", math.random(6,11))
					Helikoopa = CreateProjectileAbs("Bowsy Attacks Sprites/boom", XHelikoopa, YHelikoopa, "Top")
					Helikoopa.sprite.Scale(2,2)
					Helikoopa.SetVar("dead", true)
					table.insert(Explotions, Helikoopa)
					Audio.PlaySound("explode")
					Audio.PlaySound("bowsydead")
				elseif Hurt > 180 then
					HeliBowsy.MoveTo(HeliBowsy.x + HeliBowsy.GetVar("X"), HeliBowsy.y + HeliBowsy.GetVar("Y"))
					HeliBowsy.rotation = HeliBowsy.rotation + HeliBowsy.GetVar("rot")
					HeliBowsy.SetVar("Y", HeliBowsy.GetVar("Y") - 0.1)
					if HeliBowsy.y < -1000 then
						Black.alpha = Black.alpha + 1/30
						if Black.alpha >= 1 and not wait2 then
							wait2 = 0
						end
					end
				end
				if Hurt%30 == 0 and altervel then
					framevel = math.random(6)
				end
				if back then
					back = back - 1
					Helikoopa.MoveTo(Helikoopa.x + math.random(-2,2), Helikoopa.y - 3.5)
					if back == 0 then
						back = nil
					end
				end
			end
		elseif Cannon then
			Cannon = Cannon + 1
			if Cannon <= 1 then
				HeliBowsy.sprite.Set("Bowsy Attacks Sprites/Bowsy/Car/Smiling/1")
				Frame = 1
			elseif Cannon%5 == 0 and ((Cannon < 40 and status == "Normal") or (Cannon < 45 and status == "Angry")) then
				Frame = Frame + 1
			elseif (Cannon == 60 and status == "Normal") or (Cannon == 65 and status == "Angry") then
				HeliBowsy.sprite.Set("Bowsy Attacks Sprites/Bowsy/Car/Smiling/2")
				Audio.PlaySound("laugh3")
			elseif (Cannon == 70 and status == "Normal") or (Cannon == 75 and status == "Angry") then
				HeliBowsy.sprite.Set("Bowsy Attacks Sprites/Bowsy/Car/Smiling/3")
			elseif (Cannon == 100 and status == "Normal") or (Cannon == 105 and status == "Angry") then
				Frame = Frame - 2
				Ventilator.Move(0, 6)
				GenerateMine(Hits)
				Audio.PlaySound("shootbomb")
			elseif Cannon%5 == 0 and ((Cannon > 100 and Cannon < 115 and status == "Normal") or (Cannon > 105 and Cannon < 120 and status == "Angry")) then
				Frame = Frame + 1
				Ventilator.Move(0, -3)
			elseif Cannon%5 == 0 and ((Cannon > 135 and Cannon < 175 and status == "Normal") or (Cannon > 140 and Cannon < 180 and status == "Angry")) then
				Frame = Frame - 1
				if Frame == 7 then
					HeliBowsy.sprite.Set("Bowsy Attacks Sprites/Bowsy/Car/Smiling/2")
				elseif Frame == 4 then
					HeliBowsy.sprite.Set("Bowsy Attacks Sprites/Bowsy/Car/Smiling/1")
				end
			elseif (Cannon == 190 and status == "Normal") or (Cannon == 195 and status == "Angry") then
				Cannon = nil
			end
		elseif not Pound then
			if Ventilator.absx <= Player.absx and X < 1.5 then
				X = X + 0.025
			elseif Ventilator.absx >= Player.absx and X > -1.5 then
				X = X - 0.025
			end
		elseif not Fall then
			wait = wait + 1
			if Ventilator.absx <= Player.absx and X < 2 and not Fall then
				X = X + 0.05
			elseif Ventilator.absx >= Player.absx and X > -2 and not Fall then
				X = X - 0.05
			end
			if Ventilator.absx > Player.absx - 25 and Ventilator.absx < Player.absx + 25 and wait > 150 then
				Fall = true
				MovementFloating = nil
				framevel = 1
				X = 0
				Y = 2
				Audio.PlaySound("throwthings")
			end
		else
			if Ventilator.absy > Arena.y + 5 + Ventilator.sprite.height and Pound <= 0 then
				Ventilator.Move(0, Y)
				Y = Y - 0.2
				Pound = Pound - 1
				if Pound == -10 then
					Frame = 2
				elseif Pound == -20 then
					Frame = 3
				end
			else
				if Pound < 0 and Fall then
					Pound = 0
					Ventilator.SetVar("posX", Ventilator.absx)
				end
				Pound = Pound + 1
				if Pound == 1 then
					Ventilator.MoveToAbs(Ventilator.absx, Arena.y + 9)
					Frame = 2
					for i=1,2 do
						Dust = CreateSprite("Bowsy Attacks Sprites/Smoke/1","Top")
						Dust.MoveTo(Ventilator.absx, Ventilator.absy)
						Dust.Scale(2,2)
						Dust.SetVar("frame", 1)
						Dust.SetVar("velX", -3 + i*2)
						Dust.SetVar("timer", 0)
						table.insert(Smoke, Dust)
					end
					framevent = 1
					ventanim = nil
					Audio.PlaySound("poundbigbomb")
				elseif Pound == 180 then
					ventanim = 0
					framevel = 3
					Frame = 1
				end
				if Pound >= 180 and Ventilator.absy < Arena.y + Arena.height - 40 then
					Ventilator.Move(0, 1)
				elseif Pound >= 180 then
					Pound = nil
					Fall = nil
					MovementFloating = 0
					timer = 0
				end
			end
		end
		if not Hurt and not Cannon then
			if Ventilator.absx > Player.absx + 3 then
				direction = "Left"
			elseif Ventilator.absx >= Player.absx - 3 and Ventilator.absx <= Player.absx + 3 then
				direction = "Front"
			elseif Ventilator.absx < Player.absx - 3 then
				direction = "Right"
			end
			Ventilator.Move(X, 0)
			Helikoopa.sprite.Set("Bowsy Attacks Sprites/Helikoopa/"..direction.."/"..status)
		end
		if ThrowFire and not ThrowKoopas and not ThrowHammers and not Pound and not Hurt and not Cannon then
			ThrowFire = ThrowFire + 1
			if ThrowFire == 1 then
				Frame = 2
			elseif ThrowFire == 31 then
				Frame = 3
				GenerateFire()
				Audio.PlaySound("throwfire")
			elseif ThrowFire == 51 then
				Frame = 1
				ThrowFire = nil
				ThrowKoopas = nil
				ThrowHammers = nil
			end
		elseif (ThrowKoopas or ThrowHammers) and not Pound and not Hurt and not Cannon then
			if ThrowKoopas then
				ThrowKoopas = ThrowKoopas + 1
				if ThrowKoopas%5 == 0 and ThrowKoopas <= 20 then
					Frame = Frame + 1
				elseif ThrowKoopas%5 == 0 and ThrowKoopas >= 60 and Frame <= 13 then
					Frame = Frame + 1
					if Frame == 9 then
						Generate("Shells", math.random(1,3))
						Audio.PlaySound("throwthings")
					elseif Frame == 13 then
						Frame = 1
						ThrowKoopas = nil
						ThrowFire = nil
						ThrowHammers = nil
					end
				end
			elseif ThrowHammers then
				ThrowHammers = ThrowHammers + 1
				if ThrowHammers%5 == 0 and ThrowHammers <= 20 then
					Frame = Frame + 1
				elseif ThrowHammers%5 == 0 and ThrowHammers >= 60 and Frame <= 13 then
					Frame = Frame + 1
					if Frame == 9 then
						Generate("Hammers", 2*Hits)
						Audio.PlaySound("throwthings")
					elseif Frame == 13 then
						Frame = 1
						ThrowKoopas = nil
						ThrowFire = nil
						ThrowHammers = nil
					end
				end
			end
		end
		if Cannon then
			Helikoopa.sprite.Set("Bowsy Attacks Sprites/Helikoopa/Front/Cannon "..status.."/"..Frame)
		elseif not ThrowKoopas and not ThrowHammers and not Pound and not Hurt and not Cannon then
			HeliBowsy.sprite.Set("Bowsy Attacks Sprites/Bowsy/Car/Shooting "..direction.."/"..Frame)
		elseif (ThrowKoopas or ThrowHammers) and Frame < 5 and not Hurt and not Cannon then
			HeliBowsy.sprite.Set("Bowsy Attacks Sprites/Bowsy/Car/Coming Out "..direction.."/"..Frame)	
		elseif (ThrowKoopas or ThrowHammers) and Frame >= 5 and not Hurt and not Cannon then
			HeliBowsy.sprite.Set("Bowsy Attacks Sprites/Bowsy/Car/Throwing Front/"..Frame)
		elseif Pound and not Hurt and not Cannon then
			if Pound <= 0 then
				HeliBowsy.sprite.Set("Bowsy Attacks Sprites/Bowsy/Car/Smiling/"..Frame)
				Helikoopa.sprite.Set("Bowsy Attacks Sprites/Helikoopa/Front/"..status)
			elseif Pound < 180 then
				HeliBowsy.sprite.Set("Bowsy Attacks Sprites/Bowsy/Car/Aturded/"..Frame)
				Helikoopa.sprite.Set("Bowsy Attacks Sprites/Helikoopa/Front/Aturded/"..Frame)
				Ventilator.MoveToAbs(Ventilator.GetVar("posX") + math.random(-1,1), Arena.y + 9)
				Ventilator.SetVar("dead", true)
				Helikoopa.SetVar("dead", true)
				HeliBowsy.SetVar("dead", true)
				if CYFversion <= "0.5.3" then
					Aux = Ventilator.absy + Helikoopa.absy + HeliBowsy.absy
				else
					Aux = HeliBowsy.absy
				end
				if not Arrow and Hits == 0 then
					Arrow = CreateSprite("Bowsy Attacks Sprites/Arrow","BelowPlayer")
					Arrow.MoveTo(Ventilator.absx, Aux + Arrow.height + 20)
				elseif Arrow then
					Arrow.MoveTo(Arrow.absx, Arrow.absy + math.cos(Pound/5)/4)
				end
				if Pound%3 == 0 then
					Frame = Frame + 1
					if Frame == 5 then
						Frame = 1
					end
				end
				if Player.absy <= Aux + 28 and Player.absy >= Aux - 4 and Player.absx >= Ventilator.absx - 32 and Player.absx <= Ventilator.absx + 32 and jump < 0 then
					Hurt = 0
					Pound = nil
					Fall = nil
					Frame = 1
					Hits = Hits + 1
					Audio.PlaySound("hitBowsy")
					Audio.PlaySound("wow")
					if Arrow then
						Arrow.Remove()
						Arrow = nil
					end
					if Input.Up > 0 then
						jump = 40
					else
						jump = 25
					end
					if Hits == 3 then
						local YHelikoopa = Helikoopa.absy
						local YBowsy = HeliBowsy.absy
						local XVentilator = Ventilator.absx
						local YVentilator = Ventilator.absy
						Helikoopa.Remove()
						HeliBowsy.Remove()
						Ventilator.Remove()
						HeliBowsy = CreateSprite("Bowsy Attacks Sprites/Bowsy/Car/Hurt/1","Top")
						Helikoopa = CreateSprite("Bowsy Attacks Sprites/Helikoopa/Front/Sad","Top")
						Ventilator = CreateSprite("Bowsy Attacks Sprites/Helikoopa/1","Top")
						Shocks = CreateSprite("Bowsy Attacks Sprites/Helikoopa/Shocks/1","Top")
						HeliBowsy.SetAnimation({"Bowsy Attacks Sprites/Bowsy/Car/Hurt/1","Bowsy Attacks Sprites/Bowsy/Car/Hurt/2","Bowsy Attacks Sprites/Bowsy/Car/Hurt/3","Bowsy Attacks Sprites/Bowsy/Car/Hurt/2"}, 0.02)
						Shocks.SetAnimation({"Bowsy Attacks Sprites/Helikoopa/Shocks/1","Bowsy Attacks Sprites/Helikoopa/Shocks/2","Bowsy Attacks Sprites/Helikoopa/Shocks/3","Bowsy Attacks Sprites/Helikoopa/Shocks/4"}, 0.04)
						HeliBowsy.Scale(1.8,1.8)
						Helikoopa.Scale(2,2)
						Ventilator.Scale(2,2)
						Shocks.Scale(2,2)
						Ventilator.MoveTo(XVentilator, YVentilator)
						if CYFversion <= "0.5.3" then
							HeliBowsy.MoveTo(XVentilator, YVentilator + YHelikoopa + YBowsy)
							Helikoopa.MoveTo(XVentilator, YVentilator + YHelikoopa)
							Shocks.MoveTo(XVentilator, YVentilator + YHelikoopa)
						else
							HeliBowsy.MoveTo(XVentilator, YBowsy)
							Helikoopa.MoveTo(XVentilator, YHelikoopa)
							Shocks.MoveTo(XVentilator, YHelikoopa)
						end
						HeliBowsy.SetParent(Helikoopa)
						Ventilator.SetParent(Helikoopa)
						Shocks.SetParent(Helikoopa)
						NewAudio.Stop("Bowsy Jr")
						NewAudio.DestroyChannel("Bowsy Jr")
					else
						HeliBowsy.sprite.SetAnimation({"Bowsy Attacks Sprites/Bowsy/Car/Hurt/1","Bowsy Attacks Sprites/Bowsy/Car/Hurt/2","Bowsy Attacks Sprites/Bowsy/Car/Hurt/3","Bowsy Attacks Sprites/Bowsy/Car/Hurt/2"}, 0.02)
						HeliBowsy.sprite.loopmode = "LOOP"
						Helikoopa.sprite.Set("Bowsy Attacks Sprites/Helikoopa/Front/Sad")
					end
					for i=1,#Shells do
						local koopa = Shells[i - tableaux]
						if koopa then
							Dust = CreateSprite("Bowsy Attacks Sprites/Smoke/1","Top")
							Dust.MoveTo(koopa.absx, koopa.absy)
							Dust.Scale(2,2)
							Dust.SetVar("frame", 1)
							Dust.SetVar("velX", 0)
							Dust.SetVar("timer", 20)
							table.insert(Smoke, Dust)
							koopa.Remove()
							koopa = nil
							table.remove(Shells, i - tableaux)
							tableaux = tableaux + 1
						end
					end
					tableaux = 0
					for i=1,#Flames do
						if Flames[i] then
							Flames[i].SetVar("repeat", false)
						end
					end
				end
			else
				if Arrow then
					Arrow.Remove()
					Arrow = nil
				end
				Ventilator.SetVar("dead", nil)
				Helikoopa.SetVar("dead", nil)
				HeliBowsy.SetVar("dead", nil)
				HeliBowsy.sprite.Set("Bowsy Attacks Sprites/Bowsy/Car/Shooting Front/1")
				Helikoopa.sprite.Set("Bowsy Attacks Sprites/Helikoopa/Front/"..status)
			end
		end
	end
	if ventanim then
		ventanim = ventanim + 1
		if ventanim%framevel == 0 then
			framevent = framevent + 1
		end
		if framevent == 5 then
			framevent = 1
		end
	end
	if framevent and Hits < 3 then
		Ventilator.sprite.Set("Bowsy Attacks Sprites/Helikoopa/"..framevent)
	elseif framevent then
		Ventilator.Set("Bowsy Attacks Sprites/Helikoopa/"..framevent)
	end
	if MovementFloating then
		MovementFloating = MovementFloating + 1
		Ventilator.Move(0, math.cos(MovementFloating/10)/4)
	end
	if Volumen > 0 and not bowsymusic then
		Volumen = Volumen - 0.01
		Audio.volume(Volumen)
	elseif bowsymusic then
		NewAudio.CreateChannel("Bowsy Jr")
		NewAudio.PlaySound("Bowsy Jr", "Bowsy Music Intro", false, 1)
		bowsymusic = nil
		musicintro = true
	end
	if musicintro then
		if NewAudio.isStopped("Bowsy Jr") then
			NewAudio.PlaySound("Bowsy Jr", "Bowsy Music Loop", true, 1)
			musicintro = nil
		end
	end
	if state == 1 then -- Down
		newpX = newpX
		newpY = newpY
		if Input.Right > 0 then
			newpX = Player.x + 2.5
		end
		if Input.Left > 0 then
			newpX = Player.x - 2.5
		end
		if Player.y < bottomedge + 2 then
			if Input.Up > 0 then
				jump = maxjump
			else
				newpY = bottomedge
				jump = 0
			end
		elseif jump < 3 and jump > -3 then
			jump = jump - 0.5
		elseif jump < -3 and jump > -10 then
			jump = -10
		elseif jump < -3 then
			jump = jump - 1.5
		else
			jump = (jump/1.001) - 1
		end
		if Input.Up < 0 and jump > 5 then
			jump = 4
		end
		newpY = newpY + (jump/10)
		Player.MoveTo(newpX, newpY, false)
    end
	for i=1,#Smoke do
		local humo = Smoke[i - tableaux]
		if humo then
			humo.MoveTo(humo.x + humo.GetVar("velX"), humo.y)
			humo.SetVar("timer", humo.GetVar("timer") + 1)
			if humo.GetVar("timer")%10 == 0 and humo.GetVar("timer") >= 40 then
				humo.SetVar("frame", humo.GetVar("frame") + 1)
			end
			humo.Set("Bowsy Attacks Sprites/Smoke/"..humo.GetVar("frame"))
			if humo.GetVar("frame") == 4 then
				humo.Remove()
				humo = nil
				table.remove(Smoke, i - tableaux)
				tableaux = tableaux + 1
			end
		end
	end
	tableaux = 0
	for i=1,#FireBalls do
		local fuego = FireBalls[i - tableaux]
		if fuego then
			if not fuego.GetVar("target") then
				local angl = math.atan2(Player.absx - fuego.absx, Player.absy - fuego.absy)/math.pi * 180 * - 1 + 180
				while angl >= 360 do
					angl = angl - 360
				end
				while angl < 0 do
					angl = angl + 360
				end
				fuego.SetVar("rot", angl)
				fuego.SetVar("target", true)
				fuego.sprite.rotation = angl
			end
			fuego.Move(3*math.sin(math.rad(fuego.GetVar("rot"))), -3*math.cos(math.rad(fuego.GetVar("rot"))))
			if fuego.absy < Arena.y + 10 + 8*math.cos(math.rad(fuego.GetVar("rot"))) then
				for j=1,5 do
					Flame = CreateProjectileAbs("Bowsy Attacks Sprites/Flames/InFloor/5", fuego.absx + fuego.GetVar("diff"), Arena.y + 5 + 9)
					Flame.SetVar("timer", 0)
					Flame.SetVar("frame", 1)
					if j%2 == 0 then
						Flame.sprite.Scale(3,3)
						Flame.Move(0, 5)
					elseif j == 3 then
						Flame.sprite.Scale(2.5,2.5)
						Flame.Move(0, 3)
						Flame.sprite.layer = "Top"
					else
						Flame.sprite.Scale(2,2)
						Flame.sprite.layer = "BelowBullet"
					end
					table.insert(Flames, Flame)
					fuego.SetVar("diff", fuego.GetVar("diff") + 10)
				end
				explotion = CreateProjectileAbs("Bowsy Attacks Sprites/Flames/Explotion/1", fuego.absx, fuego.absy)
				explotion.sprite.color = {1,150/255,0}
				explotion.sprite.SetAnimation({"Bowsy Attacks Sprites/Flames/Explotion/1","Bowsy Attacks Sprites/Flames/Explotion/2","Bowsy Attacks Sprites/Flames/Explotion/3","Bowsy Attacks Sprites/Flames/Explotion/4"},0.08)
				explotion.sprite.loopmode = "ONESHOT"
				table.insert(FireExplotions, explotion)
				fuego.Remove()
				fuego = nil
				table.remove(FireBalls, i - tableaux)
				tableaux = tableaux + 1
			end
		end
	end
	tableaux = 0
	for i=1,#Flames do
		local flama = Flames[i - tableaux]
		if flama then
			flama.SetVar("timer", flama.GetVar("timer") + 1)
			if flama.GetVar("timer") == 1 then
				flama.SetVar("repeat", true)
			elseif flama.GetVar("timer") == 400 then
				flama.SetVar("repeat", false)
			end
			if flama.GetVar("timer")%5 == 0 then
				if flama.GetVar("frame") == 5 and flama.GetVar("repeat") == true then
					flama.SetVar("frame", 1)
				elseif flama.GetVar("frame") == 9 then
					flama.Remove()
					flama = nil
					table.remove(Flames, i - tableaux)
					tableaux = tableaux + 1
				end
				if flama then
					flama.sprite.Set("Bowsy Attacks Sprites/Flames/InFloor/"..flama.GetVar("frame"))
					flama.SetVar("frame", flama.GetVar("frame") + 1)
				end
			end
		end
	end
	tableaux = 0
	for i=1,#FireExplotions do
		local explosion = FireExplotions[i - tableaux]
		if explosion then
			if not explosion.GetVar("timer") then
				explosion.SetVar("timer", 0)
			else
				explosion.SetVar("timer", explosion.GetVar("timer") + 1)
			end
			if explosion.GetVar("timer") == 30 then
				explosion.Remove()
				explosion = nil
				table.remove(FireExplotions, i - tableaux)
				tableaux = tableaux + 1
			end
		end
	end
	tableaux = 0
	for i=1,#Shells do
		local koopa = Shells[i - tableaux]
		if koopa then
			koopa.Move(koopa.GetVar("velX"), koopa.GetVar("velY"))
			if not koopa.GetVar("dead") then
				koopa.SetVar("timer", koopa.GetVar("timer") + 1)
				if koopa.absy > Arena.y + 5 + koopa.sprite.height then
					koopa.SetVar("velY", koopa.GetVar("velY") - 0.2)
				end
				if koopa.absy < Arena.y + 5 + koopa.sprite.height then
					koopa.MoveToAbs(koopa.absx, Arena.y + 5 + koopa.sprite.height)
					koopa.SetVar("velY", 0)
				end
				if koopa.sprite.xscale < 2 then
					koopa.sprite.Scale(koopa.sprite.xscale + 0.1, koopa.sprite.yscale + 0.1)
				end
				if koopa.absx < Arena.x - Arena.width/2 + koopa.sprite.width then
					koopa.SetVar("velX", -koopa.GetVar("velX"))
					if koopa.GetVar("velX") ~= 0 then
						koopa.SetVar("fase", 1)
					end
					koopa.MoveToAbs(Arena.x - Arena.width/2 + koopa.sprite.width, koopa.absy)
				elseif koopa.absx > Arena.x + Arena.width/2 - koopa.sprite.width then
					koopa.SetVar("velX", -koopa.GetVar("velX"))
					if koopa.GetVar("velX") ~= 0 then
						koopa.SetVar("fase", 2)
					end
					koopa.MoveToAbs(Arena.x + Arena.width/2 - koopa.sprite.width, koopa.absy)
				end
				if koopa.GetVar("velX") == 0 then
					if Player.absx < koopa.absx + koopa.sprite.width + 10 and Player.absx > koopa.absx and Player.absy <= Arena.y + 8 + koopa.sprite.height and koopa.absy <= Arena.y + 5 + koopa.sprite.height then
						koopa.SetVar("velX", -3)
						koopa.SetVar("fase", 2)
						Audio.PlaySound("hitshells")
					elseif Player.absx > koopa.absx - koopa.sprite.width - 10 and Player.absx < koopa.absx and Player.absy <= Arena.y + 8 + koopa.sprite.height and koopa.absy <= Arena.y + 5 + koopa.sprite.height then
						koopa.SetVar("velX", 3)
						koopa.SetVar("fase", 1)
						Audio.PlaySound("hitshells")
					end
				end
				koopa.sprite.Set("Bowsy Attacks Sprites/Shell/"..koopa.GetVar("frame"))
				if koopa.GetVar("timer")%5 == 0 then
					if koopa.GetVar("fase") == 1 then
						koopa.SetVar("frame", koopa.GetVar("frame") + 1)
						if koopa.GetVar("frame") == 5 then
							koopa.SetVar("frame", 1)
						end
					elseif koopa.GetVar("fase") == 2 then
						koopa.SetVar("frame", koopa.GetVar("frame") - 1)
						if koopa.GetVar("frame") == 0 then
							koopa.SetVar("frame", 4)
						end
					end
				end
				for j=1,#Shells do
					local koopa2 = Shells[j]
					if koopa2 then
						if i - tableaux ~= j and not koopa.GetVar("dead") and not koopa2.GetVar("dead") and koopa.absy <= Arena.y + 5 + koopa.sprite.height and koopa2.absy <= Arena.y + 5 + koopa.sprite.height then
							if koopa.absx > koopa2.absx - koopa2.sprite.width*2 and koopa.absx < koopa2.absx + koopa2.sprite.width*2 then
								if koopa.absx > koopa2.absx then
									koopa.SetVar("rot", math.random(3,5))
									koopa2.SetVar("rot", -math.random(3,5))
									koopa.SetVar("velX", 1)
									koopa2.SetVar("velX", -1)
								elseif koopa.absx <= koopa2.absx then
									koopa.SetVar("rot", -math.random(3,5))
									koopa2.SetVar("rot", math.random(3,5))
									koopa.SetVar("velX", -1)
									koopa2.SetVar("velX", 1)
								end
								koopa.sprite.StopAnimation()
								koopa2.sprite.StopAnimation()
								koopa.SetVar("velY", 2)
								koopa2.SetVar("velY", 2)
								koopa.SetVar("dead", true)
								koopa2.SetVar("dead", true)
								Audio.PlaySound("hitshells")
							end
						end
					end
				end
			else
				koopa.Move(koopa.GetVar("velX"), koopa.GetVar("velY"))
				koopa.SetVar("velY", koopa.GetVar("velY") - 0.1)
				koopa.sprite.rotation = koopa.sprite.rotation + koopa.GetVar("rot")
				if koopa.absy < -60 then
					koopa.Remove()
					koopa = nil
					table.remove(Shells, i - tableaux)
					tableaux = tableaux + 1
				end
			end
		end
	end
	tableaux = 0
	for i=1,#Mines do
		local bomba = Mines[i - tableaux]
		if bomba then
			if bomba.sprite.xscale < bomba.GetVar("scale") then
				bomba.sprite.Scale(bomba.sprite.xscale + 0.1, bomba.sprite.yscale + 0.1)
				bomba.GetVar("Spikes").sprite.Scale(bomba.GetVar("Spikes").sprite.xscale + 0.1, bomba.GetVar("Spikes").sprite.yscale + 0.1)
			end
			if bomba.GetVar("InFloor") or bomba.GetVar("InLoop") then
				bomba.SetVar("timer", bomba.GetVar("timer") + 1)
			end
			if not bomba.GetVar("InFloor") then
				bomba.Move(0, bomba.GetVar("Y"))
				bomba.SetVar("Y", bomba.GetVar("Y") - 0.2)
				if bomba.absy < Arena.y + 5 + bomba.sprite.height*0.5*bomba.GetVar("scale") then
					bomba.MoveToAbs(bomba.absx, Arena.y + 5 + bomba.sprite.height*0.5*bomba.GetVar("scale"))
					bomba.SetVar("InFloor", true)
					bomba.SetVar("X", 0)
					Audio.PlaySound(bomba.GetVar("sound"))
					if bomba.absx > Player.absx and not bomba.GetVar("InLoop") then
						bomba.SetVar("direction", "Izquierda")
					elseif not bomba.GetVar("InLoop") then
						bomba.SetVar("direction", "Derecha")
					end
					for i=1,2 do
						Dust = CreateSprite("Bowsy Attacks Sprites/Smoke/1","Top")
						Dust.MoveTo(bomba.absx, Arena.y + 5)
						Dust.Scale(2,2)
						Dust.SetVar("frame", 1)
						Dust.SetVar("velX", -3 + i*2)
						Dust.SetVar("timer", 0)
						table.insert(Smoke, Dust)
					end
				end
			else
				bomba.Move(bomba.GetVar("X"), 0)
				bomba.sprite.rotation = bomba.sprite.rotation + bomba.GetVar("velrot")
				if bomba.GetVar("direction") == "Izquierda" and bomba.GetVar("X") > -bomba.GetVar("maxvel") then
					bomba.SetVar("X", bomba.GetVar("X") - 0.1)
					bomba.SetVar("velrot", bomba.GetVar("velrot") + 0.2)
				elseif bomba.GetVar("direction") == "Derecha" and bomba.GetVar("X") < bomba.GetVar("maxvel") then
					bomba.SetVar("X", bomba.GetVar("X") + 0.1)
					bomba.SetVar("velrot", bomba.GetVar("velrot") - 0.2)
				end
				if bomba.absx < Arena.x - Arena.width/2 + bomba.sprite.width*0.75 then
					bomba.MoveToAbs(Arena.x - Arena.width/2 + bomba.sprite.width*0.75, bomba.absy)
					bomba.SetVar("Y", 3)
					bomba.SetVar("direction", "Derecha")
					bomba.SetVar("velrot", 0)
					bomba.SetVar("InLoop", true)
					bomba.SetVar("InFloor", nil)
					Audio.PlaySound(bomba.GetVar("sound"))
				elseif bomba.absx > Arena.x + Arena.width/2 - bomba.sprite.width*0.75 then
					bomba.MoveToAbs(Arena.x + Arena.width/2 - bomba.sprite.width*0.75, bomba.absy)
					bomba.SetVar("Y", 3)
					bomba.SetVar("direction", "Izquierda")
					bomba.SetVar("velrot", 0)
					bomba.SetVar("InLoop", true)
					bomba.SetVar("InFloor", nil)
					Audio.PlaySound(bomba.GetVar("sound"))
				end
				if bomba.GetVar("timer") >= 360 and not bomba.GetVar("warning") then
					bomba.SetVar("warning", 255)
					bomba.SetVar("color", 1)
					bomba.SetVar("velcolor", 3)
				elseif bomba.GetVar("timer") >= 480 and bomba.GetVar("velcolor") < 6 then
					bomba.SetVar("velcolor", 6)
				elseif bomba.GetVar("timer") >= 540 and bomba.GetVar("velcolor") < 9 then
					bomba.SetVar("velcolor", 9)
				elseif bomba.GetVar("timer") >= 600 and bomba.GetVar("velcolor") < 12 then
					bomba.SetVar("velcolor", 12)
				elseif bomba.GetVar("timer") >= 600 and bomba.GetVar("velcolor") < 12 then
					bomba.SetVar("velcolor", 12)
				elseif bomba.GetVar("timer") >= 660 and bomba.GetVar("velcolor") < 15 then
					bomba.SetVar("velcolor", 15)
				elseif bomba.GetVar("timer") >= 720 and bomba.GetVar("velcolor") < 18 then
					bomba.SetVar("velcolor", 18)
				elseif bomba.GetVar("timer") >= 780 and bomba.GetVar("velcolor") < 21 then
					bomba.SetVar("velcolor", 21)
				elseif bomba.GetVar("timer") >= 840 and bomba.GetVar("velcolor") < 24 then
					bomba.SetVar("velcolor", 51)
				elseif bomba.GetVar("timer") >= 900 then
					Audio.PlaySound("explode")
					explotion = CreateProjectileAbs("Bowsy Attacks Sprites/boom", bomba.absx, bomba.absy)
					explotion.sprite.Scale(1.3*bomba.GetVar("scale"),1.3*bomba.GetVar("scale"))
					table.insert(Explotions, explotion)
					bomba.GetVar("Spikes").Remove()
					bomba.Remove()
					bomba = nil
					table.remove(Mines, i - tableaux)
					tableaux = tableaux + 1
				end
			end
			if bomba then
				if bomba.GetVar("warning") then
					if bomba.GetVar("color") == 1 then
						bomba.SetVar("warning", bomba.GetVar("warning") - bomba.GetVar("velcolor"))
						if bomba.GetVar("warning") <= 0 then
							bomba.SetVar("warning", 0)
							bomba.SetVar("color", 2)
						end
					elseif bomba.GetVar("color") == 2 then
						bomba.SetVar("warning", bomba.GetVar("warning") + bomba.GetVar("velcolor"))
						if bomba.GetVar("warning") >= 255 then
							bomba.SetVar("warning", 255)
							bomba.SetVar("color", 1)
						end
					end
					bomba.sprite.color = {255, bomba.GetVar("warning")/255, bomba.GetVar("warning")/255}
				end
			end
		end
	end
	tableaux = 0
	for i=1,#Explotions do
		local kabum = Explotions[i - tableaux]
		if kabum then
			kabum.sprite.Scale(kabum.sprite.xscale + 4/46, kabum.sprite.yscale + 4/46)
			kabum.sprite.alpha = kabum.sprite.alpha - 0.02
			if kabum.sprite.alpha <= 0 then
				kabum.Remove()
				kabum = nil
				table.remove(Explotions, i - tableaux)
				tableaux = tableaux + 1
			end
		end
	end
	tableaux = 0
	for i=1,#Hammers do
		local metal = Hammers[i - tableaux]
		if metal then
			metal.Move(metal.GetVar("velX"), metal.GetVar("velY"))
			metal.SetVar("timer", metal.GetVar("timer") + 1)
			if metal.absy > Arena.y + 5 + metal.sprite.height then
				metal.SetVar("velY", metal.GetVar("velY") - 0.2)
			end
			if metal.absy < Arena.y + 5 + metal.sprite.height and metal.absx < Arena.x + Arena.width/2 + 5 and metal.absx > Arena.x - Arena.width/2 - 5 then
				metal.MoveToAbs(metal.absx, Arena.y + 5 + metal.sprite.height)
				metal.SetVar("velY", 4.9 + 0.1*math.random(11))
			elseif metal.absy < -30 then
				metal.Remove()
				metal = nil
				table.remove(Hammers, i - tableaux)
				tableaux = tableaux + 1
			end
			if metal then
				if metal.sprite.xscale < 2 then
					metal.sprite.Scale(metal.sprite.xscale + 0.1, metal.sprite.yscale + 0.1)
				end
				if metal.absx < Arena.x - Arena.width/2 + metal.sprite.width and metal.GetVar("timer") < 700 then
					metal.SetVar("velX", -metal.GetVar("velX"))
					metal.SetVar("fase", 1)
					metal.MoveToAbs(Arena.x - Arena.width/2 + metal.sprite.width, metal.absy)
				elseif metal.absx > Arena.x + Arena.width/2 - metal.sprite.width and metal.GetVar("timer") < 700 then
					metal.SetVar("velX", -metal.GetVar("velX"))
					metal.SetVar("fase", 2)
					metal.MoveToAbs(Arena.x + Arena.width/2 - metal.sprite.width, metal.absy)
				end
				if metal.GetVar("fase") == 1 then
					metal.sprite.rotation = metal.sprite.rotation - 18
				elseif metal.GetVar("fase") == 2 then
					metal.sprite.rotation = metal.sprite.rotation + 18
				end
			end
		end
	end
	tableaux = 0
	if wait2 then
		wait2 = wait2 + 1
		if wait2 == 120 then
			Black.Remove()
			for i=1,#Smoke do
				Smoke[i].Remove()
			end
			Player.sprite.color = {1,0,0}
			Encounter["nextwaves"] = {"Menu"}
			SetRealGlobal("Extras", 6)
			State("ACTIONSELECT")
			State("DEFENDING")
		end
	end
end

function GenerateFire()
	if CYFversion <= "0.5.3" then
		Aux = Ventilator.absy + Helikoopa.absy + HeliBowsy.absy
	else
		Aux = HeliBowsy.absy
	end
	if direction == "Right" then
		Fire = CreateProjectileAbs("Bowsy Attacks Sprites/Flames/1", Ventilator.absx + 8, Aux - 11, "Top")
	elseif direction == "Front" then
		Fire = CreateProjectileAbs("Bowsy Attacks Sprites/Flames/1", Ventilator.absx, Aux - 11, "Top")
	elseif direction == "Left" then
		Fire = CreateProjectileAbs("Bowsy Attacks Sprites/Flames/1", Ventilator.absx - 8, Aux - 11, "Top")
	end
	Fire.sprite.SetAnimation({"Bowsy Attacks Sprites/Flames/1","Bowsy Attacks Sprites/Flames/2","Bowsy Attacks Sprites/Flames/3","Bowsy Attacks Sprites/Flames/4","Bowsy Attacks Sprites/Flames/5"}, 0.08)
	Fire.sprite.Scale(2, 2)
	Fire.SetVar("diff", -20)
	table.insert(FireBalls, Fire)
end

function GenerateMine(type)
	if CYFversion <= "0.5.3" then
		Aux = Ventilator.absy + Helikoopa.absy
	else
		Aux = Helikoopa.absy
	end
	if type == 1 then
		Mine = CreateProjectileAbs("Bowsy Attacks Sprites/Ball", Ventilator.absx, Aux - 19, "BelowBullet")
		Mine.SetVar("maxvel", 2)
		Mine.SetVar("sound", "poundbomb")
	elseif type == 2 then
		Mine = CreateProjectileAbs("Bowsy Attacks Sprites/Ball", Ventilator.absx, Aux - 22, "BelowBullet")
		Mine.SetVar("maxvel", 1)
		Mine.SetVar("sound", "poundbigbomb")
	end
	Mine.SetVar("velrot", 0)
	Mine.SetVar("timer", 0)
	Mine.SetVar("Y", -1)
	Mine.SetVar("scale", 1.2 + 0.3*type)
	Mine.sprite.Scale(0.5*type,0.5*type)
	Mine.SetVar("Spikes", CreateProjectileAbs("Bowsy Attacks Sprites/Spike", Mine.absx, Mine.absy))
	Mine.GetVar("Spikes").sprite.SetParent(Mine.sprite)
	Mine.GetVar("Spikes").sprite.Scale(0.5*type,0.5*type)
	table.insert(Mines, Mine)
	Audio.PlaySound("fallingbomb")
end

function Generate(type, amount)
	if CYFversion <= "0.5.3" then
		Aux = Ventilator.absy + Helikoopa.absy + HeliBowsy.absy
	else
		Aux = HeliBowsy.absy
	end
	if type == "Shells" then
		ActualShells = {}
		for i=1,amount do
			local choice = math.random(2)
			Caparazon = CreateProjectileAbs("Bowsy Attacks Sprites/Shell/1", Ventilator.absx, Aux)
			Caparazon.sprite.Scale(0.5,0.5)
			Caparazon.SetVar("velY", 3)
			Caparazon.SetVar("frame", 1)
			Caparazon.SetVar("timer", 0)
			if i == 1 then
				if choice == 1 then
					Caparazon.SetVar("velX", math.random(2,3))
					Caparazon.SetVar("fase", 1)
				elseif choice == 2 then
					Caparazon.SetVar("velX", -math.random(2,3))
					Caparazon.SetVar("fase", 2)
				end
			elseif i == 2 then
				Caparazon.SetVar("velX", -ActualShells[1].GetVar("velX"))
				if ActualShells[1].GetVar("fase") == 1 then
					Caparazon.SetVar("fase", 2)
				elseif ActualShells[1].GetVar("fase") == 2 then
					Caparazon.SetVar("fase", 1)
				end
			elseif i == 3 then
				Caparazon.SetVar("velX", 0)
				Caparazon.SetVar("fase", 0)
			end
			table.insert(Shells, Caparazon)
			table.insert(ActualShells, Caparazon)
		end
	elseif type == "Hammers" then
		ActualHammers = {}
		for i=1,amount do
			Martillo = CreateProjectileAbs("Bowsy Attacks Sprites/Hammer", Ventilator.absx, Aux)
			Martillo.sprite.Scale(0.5,0.5)
			Martillo.SetVar("velY", 3)
			Martillo.SetVar("frame", 1)
			Martillo.SetVar("timer", 0)
			if i == 1 then
				Martillo.SetVar("velX", 1.5*math.random(2))
				Martillo.SetVar("fase", 1)
			elseif i == 2 then
				Martillo.SetVar("velX", -ActualHammers[1].GetVar("velX"))
				Martillo.SetVar("fase", 2)
			elseif i == 3 then
				if ActualHammers[1].GetVar("velX") == 1.5 then
					Martillo.SetVar("velX", 3)
				else
					Martillo.SetVar("velX", 1.5)
				end
				Martillo.SetVar("fase", 1)
			elseif i == 4 then
				Martillo.SetVar("velX", -ActualHammers[3].GetVar("velX"))
				Martillo.SetVar("fase", 2)
			end
			table.insert(Hammers, Martillo)
			table.insert(ActualHammers, Martillo)
		end
	end
end

function OnHit(bullet)
	if not bullet.GetVar("dead") and bullet.sprite.alpha >= 0.4 then
		if Player.hp > 3 then
			Player.Hurt(3)
		elseif not Player.isHurting then
			Black.Remove()
			for i=1,#Smoke do
				Smoke[i].Remove()
			end
			if Arrow then
				Arrow.Remove()
			end
			NewAudio.Stop("Bowsy Jr")
			NewAudio.DestroyChannel("Bowsy Jr")
			Encounter["nextwaves"] = {"Undertale Game Over B"}
			State("ACTIONSELECT")
			State("DEFENDING")
		end
	end
end