Level = { enemiesKilled = 0}

function Level.Area11()
	
	ChangeAnimation(GetPlayerAlert(),"Attack")
	AddBeat("Attack")
end


function Level.Area1()
	RemoveArea(0)
	ChangeAnimation(GetPlayerAlert(),"Stand")
end

function Level.Area12()
	ChangeAnimation(GetPlayerAlert(),"Combo1")
end

function Level.Area3()
	ChangeAnimation(GetPlayerAlert(),"Stand")
end

function Level.Area15()
	ChangeAnimation(GetPlayerAlert(),"Combo2")
end

function Level.Area21()
	ChangeAnimation(GetPlayerAlert(),"JumpAttack")
end

function Level.Area20()
	ChangeAnimation(GetPlayerAlert(),"Combo3")
end

function Level.Area7()
	ChangeAnimation(GetPlayerAlert(),"Stand")
end

function Level.Area19()
	ChangeAnimation(GetPlayerAlert(),"Combo1")
end

function Level.Area9()
	ChangeAnimation(GetPlayerAlert(),"Stand")
end

function Level.Area9()

	AddBeat("Attack")
	spawn = LoadObject("MobGunner","Enemies","")
	
	UseGravity(spawn, true)
	x,y = GetPosition(GetPlayer())
	SetPosition(spawn,x + 600,1750)
	SetDirection(spawn,-1)
	RemoveArea(9)
end

function Level.Area10()
	spawn = LoadObject("MobGunner","Enemies","")
	
	UseGravity(spawn, true)
	--SetPosition(spawn,1125,1040)
	x,y = GetPosition(GetPlayer())
	SetPosition(spawn,x + 600,1750)
	SetDirection(spawn,-1)
	--SetPosition(spawn,348,1040)
	
	SubscribeTo(GetEngine(),spawn,"Death","Testy")
end

function Level.Testy(me, you)
	spawn = LoadObject("MobGunner","Enemies","")
	UseGravity(spawn, true)
	x,y = GetPosition(GetPlayer())
	SetPosition(spawn,x - 600,1750)
	SubscribeTo(GetEngine(),spawn,"Death","Testy2")
end

function Level.Testy2(me, you)
	spawn = LoadObject("MobGunner","Enemies","")
	spawn2 = LoadObject("MobGunner","Enemies","")
	UseGravity(spawn, true)
	UseGravity(spawn2, true)
	x,y = GetPosition(GetPlayer())
	SetPosition(spawn,x - 600,1750)
	SetPosition(spawn2,x + 600,1750)
	SetDirection(spawn2,-1)
	--SubscribeTo(GetEngine(),spawn,"Death","Testy2")
	RemoveArea(10)
end

function Level.DestroyArea13()
	

	DestroyLevelBlockAt(64*68,64*25)
	DestroyLevelBlockAt(64*68,64*26)
	DestroyLevelBlockAt(64*68,64*27)

	CreateEmitter("Explosion", 64*69,64*24.5)
	CreateEmitter("Explosion", 64*69,64*25.5)
	CreateEmitter("Explosion", 64*69,64*26.5)
end

function Level.Area13()
	PersistArea()
	if TimeInArea() == 0
	then
		ExtendArea(13,0,0,0,1024)
		spawn = LoadObject("AttackBot","Enemies","")
	
		UseGravity(spawn, true)
		x,y = GetPosition(GetPlayer())
		SetPosition(spawn,x + 600,1750)
		SetDirection(spawn,-1)
		SubscribeTo(GetEngine(),spawn,"Death","DestroyArea13")
		AddBeat("Attack",20)
		AddBeat("Attack")
	--elseif TimeInArea() == 5
	--then
		--AddBeat("Attack")
	elseif TimeInArea() == 10
	then
		AddBeat("Attack")

	elseif TimeInArea() == 40
	then
		
		
		spawn = LoadObject("MobGunner","Enemies","")
		UseGravity(spawn, true)
		x,y = GetPosition(GetPlayer())
		SetPosition(spawn,x - 600,1750)
	elseif TimeInArea() == 38
	then
		AddBeat("Jump")
	elseif TimeInArea() == 66
	then
		AddBeat("Jump")


	elseif TimeInArea() == 80
	then
		
		spawn = LoadObject("MobGunner","Enemies","")
		UseGravity(spawn, true)
		x,y = GetPosition(GetPlayer())
		SetPosition(spawn,x - 600,1750)
	elseif TimeInArea() == 90
	then
		AddBeat("Jump")
	elseif TimeInArea() == 110
	then
		spawn = LoadObject("MobGunner","Enemies","")
		UseGravity(spawn, true)
		x,y = GetPosition(GetPlayer())
		SetPosition(spawn,x - 600,1750)
		
	elseif TimeInArea() == 115
	then
		AddBeat("Attack")
		RemoveArea(13)
	end

end

function Level.Area14()
	PersistArea()
	--ChangeAnimation(GetPlayerAlert(),"Jump")
	if(TimeInArea() % 100 == 0)
	then
		spawn = LoadObject("MobGunner","Enemies","")
		UseGravity(spawn, true)
		x,y = GetPosition(GetPlayer())
		SetPosition(spawn,x - 600,1750)
		SubscribeTo(GetEngine(),spawn,"CollideWall","DestroyArea14")	
		
	
	elseif ( (TimeInArea() - 15) % 100 == 0 )
	then
		AddBeat("Jump")	
	end
end

function Level.DestroyArea14(me, you)
	RemoveArea(14)
	ChangeAnimation(GetPlayerAlert(),"Stand")

	DestroyLevelBlockAt(64*78,64*25)
	DestroyLevelBlockAt(64*78,64*26)
	DestroyLevelBlockAt(64*78,64*27)

	CreateEmitter("Explosion", 64*79,64*24.5)
	CreateEmitter("Explosion", 64*79,64*25.5)
	CreateEmitter("Explosion", 64*79,64*26.5)
end

function Level.Area16()
	PersistArea()
	if(TimeInArea() == 0)
	then
		spawn = LoadObject("AttackBot","Enemies","")
		UseGravity(spawn, true)
		x,y = GetPosition(GetPlayer())
		SetPosition(spawn,x - 600,1550)
		SubscribeTo(GetEngine(),spawn,"Death","DestroyArea16a")		
	elseif TimeInArea() == 70
	then
		spawn = LoadObject("AttackBot","Enemies","")
		UseGravity(spawn, true)
		x,y = GetPosition(GetPlayer())
		SetPosition(spawn,x + 600,1550)
		SetDirection(spawn,-1)
		SubscribeTo(GetEngine(),spawn,"Death","DestroyArea16b")	
		RemoveArea(16)
	end
end

function Level.DestroyArea16a()
	DestroyLevelBlockAt(64*117,64*23)

	CreateEmitter("Explosion", 64*118,64*22.5)	
end

function Level.DestroyArea16b()
	DestroyLevelBlockAt(64*117,64*22)
	DestroyLevelBlockAt(64*117,64*24)

	CreateEmitter("Explosion", 64*118,64*21.5)
	CreateEmitter("Explosion", 64*118,64*23.5)	
end

function Level.Area17()
	spawn = LoadObject("MegaMobGunner","Enemies","")
	
	UseGravity(spawn, true)
	x,y = GetPosition(GetPlayer())
	SetPosition(spawn,x + 600,1850)
	SetDirection(spawn,-1)
	RemoveArea(17)
end

function Level.Area18()
	spawn = LoadObject("MegaMobGunner","Enemies","")
	
	UseGravity(spawn, true)
	x,y = GetPosition(GetPlayer())
	SetPosition(spawn,x + 600,1850)
	SetDirection(spawn,-1)
	RemoveArea(18)
	SubscribeTo(GetEngine(),spawn,"Death","DestroyWalls18")
end

function Level.DestroyWalls18(me, you)

	DestroyLevelBlockAt(64*146,64*25)
	DestroyLevelBlockAt(64*146,64*26)
	DestroyLevelBlockAt(64*146,64*27)
	DestroyLevelBlockAt(64*146,64*28)

	CreateEmitter("Explosion", 64*147,64*24.5)
	CreateEmitter("Explosion", 64*147,64*25.5)
	CreateEmitter("Explosion", 64*147,64*26.5)
	CreateEmitter("Explosion", 64*147,64*27.5)
end

function Level.Area20()
	
	PersistArea()
	if TimeInArea() == 0
	then
		enemiesKilled = 0
		ExtendArea(20,0,0,0,2048)
		spawn = LoadObject("MobGunner","Enemies","")
	
		UseGravity(spawn, true)
		x,y = GetPosition(GetPlayer())
		SetPosition(spawn,x + 600,1800)
		SetDirection(spawn,-1)
		SubscribeTo(GetEngine(),spawn,"Death","AddDeathCounter20")

	elseif TimeInArea() == 10
	then
		spawn = LoadObject("MobGunner","Enemies","")
		UseGravity(spawn, true)
		x,y = GetPosition(GetPlayer())
		SetPosition(spawn,x - 600,1800)
		SubscribeTo(GetEngine(),spawn,"Death","AddDeathCounter20")
	elseif TimeInArea() == 15
	then
		spawn = LoadObject("MobGunner","Enemies","")
		UseGravity(spawn, true)
		x,y = GetPosition(GetPlayer())
		SetPosition(spawn,x + 600,1800)
		SetDirection(spawn,-1)
		SubscribeTo(GetEngine(),spawn,"Death","AddDeathCounter20")
	elseif TimeInArea() == 20
	then
		spawn = LoadObject("MobGunner","Enemies","")
		UseGravity(spawn, true)
		x,y = GetPosition(GetPlayer())
		SetPosition(spawn,x - 600,1800)
		SubscribeTo(GetEngine(),spawn,"Death","AddDeathCounter20")
	elseif TimeInArea() == 30
	then
		spawn = LoadObject("MobGunner","Enemies","")
		UseGravity(spawn, true)
		x,y = GetPosition(GetPlayer())
		SetPosition(spawn,x - 600,1800)
		SubscribeTo(GetEngine(),spawn,"Death","AddDeathCounter20")
	elseif TimeInArea() == 25
	then
		spawn = LoadObject("MobGunner","Enemies","")
		UseGravity(spawn, true)
		x,y = GetPosition(GetPlayer())
		SetPosition(spawn,x + 600,1800)		
		SetDirection(spawn,-1)
		SubscribeTo(GetEngine(),spawn,"Death","AddDeathCounter20")
	elseif TimeInArea() == 60
	then
		spawn = LoadObject("AttackBot","Enemies","")
		UseGravity(spawn, true)
		x,y = GetPosition(GetPlayer())
		SetPosition(spawn,x + 600,1800)
		SetDirection(spawn,-1)
		SubscribeTo(GetEngine(),spawn,"Death","AddDeathCounter20")
	elseif TimeInArea() == 110
	then
		spawn = LoadObject("MegaMobGunner","Enemies","")
		UseGravity(spawn, true)
		x,y = GetPosition(GetPlayer())
		SetPosition(spawn,x - 600,1800)
		SubscribeTo(GetEngine(),spawn,"Death","AddDeathCounter20")
	elseif TimeInArea() == 175
	then
		spawn = LoadObject("MegaMobGunner","Enemies","")
		UseGravity(spawn, true)
		x,y = GetPosition(GetPlayer())
		SetPosition(spawn,x - 600,1800)
		SubscribeTo(GetEngine(),spawn,"Death","AddDeathCounter20")
	elseif TimeInArea() == 220
	then
		spawn = LoadObject("MegaMobGunner","Enemies","")
		UseGravity(spawn, true)
		x,y = GetPosition(GetPlayer())
		SetPosition(spawn,x + 600,1800)
		SetDirection(spawn,-1)
		SubscribeTo(GetEngine(),spawn,"Death","AddDeathCounter20")
		RemoveArea(20)


	end
	
	
end

function Level.AddDeathCounter20()
	enemiesKilled = enemiesKilled + 1
	if enemiesKilled == 10
	then
		KillPlayer()
	end
end


