--[[
Author: Will Graham (wgraham@digipen.edu)

Copyright 2008-2009 DigiPen (USA) Corp.
]]--

--print("PlatformTestLevel2_Init.lua")

if GameEngine.FirstRun == true then
	Sound:StopMusic();
	Sound:PlayMusic("IgneousCity");	
	Sound:PlayMusic("AmbientFire");
end

EventManager:AddEvent(false, 0.0, "PlayerData:LockPlayer(Vector3D(0.0, 0.0, 0.0))")
EventManager:AddEvent(false, 0.0, "PlayerData:SetEmissiveColor(Vector3D(100.0, 0.0, 0.0), true)")
EventManager:AddEvent(false, 0.0, "PlayerData:ToggleLight(true)")
EventManager:AddEvent(false, 0.0, "PlayerData:SetRimColor(Vector3D(0.0, 0.3, 1.5), 1.0)")
EventManager:AddEvent(false, 0.0, "PlayerData.JumpSpeed_ = 150.0");
EventManager:AddEvent(false, 0.0, "PlayerData.JumpDuration_ = 0.0");
EventManager:AddEvent(false, 0.0, "PlayerData.MoveSpeed_ = 1000.0");
EventManager:AddEvent(false, 0.0, "PlayerData.Acceleration_ = 7.0");

TikiGodInfo = LvlLoader:GetInfo("tikiGod01")
TikiGod = GlobalSpawnController:SpawnTikiGod(TikiGodInfo.Pos_, TikiGodInfo.Scale_, false, 200.0);
TikiGod:SetFireInterval(80);

if GameEngine.FirstRun == true then
	StartPos = LvlLoader:GetInfo("playerStart01").Pos_
	
	cameraStartPos01 = LvlLoader:GetInfo("cameraStartPos01").Pos_
	cameraStartDir01 = LvlLoader:GetInfo("cameraStartDir01").Pos_
	cameraStartPos03 = LvlLoader:GetInfo("cameraStartPos03").Pos_
	cameraStartDir03 = LvlLoader:GetInfo("cameraStartDir03").Pos_
	cameraStartPos04 = LvlLoader:GetInfo("cameraStartPos04").Pos_
	cameraStartDir04 = LvlLoader:GetInfo("cameraStartDir04").Pos_
	cameraStartPos05 = LvlLoader:GetInfo("cameraStartPos05").Pos_
	cameraStartDir05 = LvlLoader:GetInfo("cameraStartDir05").Pos_
	cameraStartPos06 = LvlLoader:GetInfo("cameraStartPos06").Pos_
	cameraStartDir06 = LvlLoader:GetInfo("cameraStartDir06").Pos_
	
	
	cameraStartPos = cameraStartPos04;
	startFirePos01 = LvlLoader:GetInfo("startFirePos01").Pos_
	startFireDir01 = LvlLoader:GetInfo("startFireDir01").Pos_
	
	EventManager:AddEvent(false, 0.0, "PlayerData:SetCameraPositionLookat(cameraStartPos03, cameraStartDir03, 1.0)")
	EventManager:AddEvent(false, 4.5, "PlayerData:SetCameraPositionLookat(cameraStartPos01, cameraStartDir01, 0.02)")
	
	EventManager:AddEvent(false, 5.5, "PlayerData:LockPlayer(Vector3D(0.0, 1.0, 0.0))")
	
	StartBridgesNumber = 1
	StartBridges = {}
	for i = 1, StartBridgesNumber do
		local PieceName = "level4StartBridge"
		if i < 10 then
			PieceName = PieceName .. 0 .. i
		else
			PieceName = PieceName .. i
		end
		local PieceInfo = LvlLoader:GetInfo(PieceName)
		StartBridges[i] = SpawnTowerInfo(PieceInfo, true, true)	
	end
	
	SpawnTriggerInfo(LvlLoader:GetInfo("startLaserTrigger01"), false, false, 
	[[
		EventManager:AddEvent(false, 0.0, "TikiGod:FireMahLazer(startFirePos01, startFireDir01, false, 200.0, 1000.0, 70.0, 60, false, 5, 0)")
		EventManager:AddEvent(false, 1.5, "PlayerData:SetCameraPosition(DefaultCameraVec, DefaultCameraSpeed + 0.05, DefaultCameraRelative, DefaultCameraFixed)")
		EventManager:AddEvent(false, 3.5, "PlayerData:UnlockPlayer()")
		EventManager:AddEvent(false, 3.5, "TikiGod:ActivateAI(true)")
	]])
	
	SpawnPlatformInfo(LvlLoader:GetInfo("startPlatform01"))
	
else
	EventManager:AddEvent(false, 0.1, "PlayerData:LockPlayer(Vector3D(0.0, 1.0, 0.0))")
	StartPos = LvlLoader:GetInfo("playerStart02").Pos_
	cameraStartPos02 = LvlLoader:GetInfo("cameraStartPos02").Pos_
	cameraStartDir02 = LvlLoader:GetInfo("cameraStartDir02").Pos_
	cameraStartPos = cameraStartPos02;
	EventManager:AddEvent(false, 0.0, "PlayerData:SetCameraPositionLookat(cameraStartPos02, cameraStartDir02, 1.0)")
	EventManager:AddEvent(false, 2.0, "PlayerData:SetCameraPosition(DefaultCameraVec, DefaultCameraSpeed + 0.05, DefaultCameraRelative, DefaultCameraFixed)");
	EventManager:AddEvent(false, 3.5, "PlayerData:UnlockPlayer()")
	EventManager:AddEvent(false, 6.5, "TikiGod:ActivateAI(true)")
end

--EventManager:AddEvent(false, 10.0, "PlayerData:SetCameraPosition(Vector3D(0.0, -200.0, 50.0), 0.3, true, true)");
--EventManager:AddEvent(false, 0.5, "PlayerData:SetCameraPosition(DefaultCameraVec, DefaultCameraSpeed + 0.05, DefaultCameraRelative, DefaultCameraFixed)");
--EventManager:AddEvent(false, 10.0, "PlayerData:UnlockPlayer()")

--EventManager:AddEvent(false, 0.5, "PlayerData:SetCameraPosition(Vector3D(-200.0, 0.0, 100.0), 0.3, true, true)");


BigBridgesNumber = 18
BigBridges = {}
for i = 1, BigBridgesNumber do
	local PieceName = "level4BigBridge"
	if i < 10 then
		PieceName = PieceName .. 0 .. i
	else
		PieceName = PieceName .. i
	end
	local PieceInfo = LvlLoader:GetInfo(PieceName)
	BigBridges[i] = SpawnTowerPatternInfo(PieceInfo, false, true)	
end

NormalTowersNumber = 10
NormalTowers = {}
for i = 1, NormalTowersNumber do
	local PieceName = "level4NormalTower"
	if i < 10 then
		PieceName = PieceName .. 0 .. i
	else
		PieceName = PieceName .. i
	end
	local PieceInfo = LvlLoader:GetInfo(PieceName)
	NormalTowers[i] = SpawnTowerInfo(PieceInfo, false, false, true)	
end

SideTowersNumber = 88
SideTowers = {}
for i = 1, SideTowersNumber do
	local PieceName = "level4SideTower"
	if i < 10 then
		PieceName = PieceName .. 0 .. i
	else
		PieceName = PieceName .. i
	end
	local PieceInfo = LvlLoader:GetInfo(PieceName)
	SideTowers[i] = SpawnTowerInfo(PieceInfo, false, false, true)	
end

EndTowersNumber = 210
EndTowers = {}
for i = 1, EndTowersNumber do
	local PieceName = "level4EndTower"
	if i < 10 then
		PieceName = PieceName .. 0 .. i
	else
		PieceName = PieceName .. i
	end
	local PieceInfo = LvlLoader:GetInfo(PieceName)
	EndTowers[i] = SpawnPillarInfo(PieceInfo, false, false, false)	
end

FinalTowersNumber = 4
FinalTowers = {}
for i = 1, FinalTowersNumber do
	local PieceName = "level4FinalTower"
	if i < 10 then
		PieceName = PieceName .. 0 .. i
	else
		PieceName = PieceName .. i
	end
	local PieceInfo = LvlLoader:GetInfo(PieceName)
	FinalTowers[i] = SpawnTowerInfo(PieceInfo, false, false, false)	
end

for i = 1, 9 do
	local DeathBoundaryName = "deathBoundary"
	if i < 10 then
		DeathBoundaryName = DeathBoundaryName .. 0 .. i
	else
		DeathBoundaryName = DeathBoundaryName .. i
	end
	SpawnDeathBoundaryInfo(LvlLoader:GetInfo(DeathBoundaryName));
end
--71
for i = 1, 69 do
	local PieceName = "compositeObjects/snakeHeadComposite"
	
	if i < 10 then
		PieceName = PieceName .. 0 .. i
	else
		PieceName = PieceName .. i
	end
	local PieceInfo = LvlLoader:GetInfo(PieceName)
	GlobalSpawnController:SpawnIgobj(PieceInfo.Pos_, PieceInfo.Scale_, PieceInfo.Rot_, "levelLoader\\snakeHead.igobj", PieceName, 0.0, true, 3, false);
end


if GameEngine.FirstRun == true then
	GameEngine.FirstRun = false
end

dofile("Scripts/HillLevel/HillLevel2_TowerTriggers.lua")

MinZ = -10000.0
KillsNeeded = 0