------ All content © 2008 DigiPen (USA) Corporation, all rights reserved. ------
-- Author: Hamza M. Hutchinson
-- Created: 10/25/2008
-- Modified: 10/31/2008 Matt Anderson added set of presentation slides

dofile( "../../Assets/Scripts/key_name_mappings.lua" )
dofile( "../../Assets/Scripts/util_math.lua" )

Global:PlayMusic2D( "../../Assets/Sounds/wind.mp3" )

local myData = Entity:Data()
local viewVecs = {}
local posVecs = {}

local function CheckPosition( currentSlide )
  if( currentSlide == 4 ) or 
    ( currentSlide == 6 ) or
    ( currentSlide == 8 ) or
    ( currentSlide == 10 )
  then
    local cPos = Global:gCameraPosition()
    cPos = vec3.subtract( cPos, vec3.negate( viewVecs[ currentSlide ] ) )
    
    if( Approx( cPos.x, posVecs[ currentSlide ].x, 3 ) ) and
      ( Approx( cPos.y, posVecs[ currentSlide ].y, 3 ) ) and
      ( Approx( cPos.z, posVecs[ currentSlide ].z, 7 ) ) then
      return true
      
    else
      return false
      
    end
    
  end
  
end

myData[ "Slide1" ] = Global:CreateEntity( "../../Assets/Xml/entities/e_Slide03.xml" )
myData.Slide1:SHR_sPosition(94.17, 257.18, 1704.31)
posVecs[1] = {}
posVecs[1].x = 96.0
posVecs[1].y = 257.18
posVecs[1].z = 1704.31
viewVecs[1] = {}
viewVecs[1].x = -7.73
viewVecs[1].y = 0.18
viewVecs[1].z = -19.0
Global:SetCameraTargetPositionVector( posVecs[ 1 ].x, posVecs[ 1 ].y, posVecs[ 1 ].z )
Global:SetCameraViewVector( viewVecs[ 1 ].x, viewVecs[ 1 ].y, viewVecs[ 1 ].z )

myData[ "Slide2" ] = Global:CreateEntity( "../../Assets/Xml/Slide02.xml" )
myData.Slide2:SHR_sPosition(28.91, 22.2, 47.82)
posVecs[2] = {}
posVecs[2].x = 28.91
posVecs[2].y = 22.2
posVecs[2].z = 52.82
viewVecs[2] = {}
viewVecs[2].x = -12.3
viewVecs[2].y = 7.7
viewVecs[2].z = -15.68
myData[ "DeadSpaceAster" ] = Global:CreateEntity( "../../Assets/Xml/entities/e_DeadSpaceAster.xml" )
myData.DeadSpaceAster:SHR_sPosition(30.91, 14.7, 61.0) 
--( 30.00, 20.0, 46.00 )

myData[ "Slide3" ] = Global:CreateEntity( "../../Assets/Xml/entities/e_Slide01.xml" )
myData.Slide3:SHR_sPosition(-18.77, 55.31, 75.47)
posVecs[3] = {}
posVecs[3].x = -18.77
posVecs[3].y = 60.51
posVecs[3].z = 75.47
viewVecs[3] = {}
viewVecs[3].x = 7
viewVecs[3].y = 7.4
viewVecs[3].z = -21

-- on way to core
posVecs[4] = {}
posVecs[4].x = 308.56
posVecs[4].y = -20.2
posVecs[4].z = -189.36
viewVecs[4] = {}
viewVecs[4].x = -100.37
viewVecs[4].y = 0.85
viewVecs[4].z = 2.77

--Core Engine
myData[ "Slide4" ] = Global:CreateEntity( "../../Assets/Xml/entities/e_Slide04.xml" )
myData.Slide4:SHR_sPosition(8.56, -20.2, -189.36)
posVecs[5] = {}
posVecs[5].x = 8.56
posVecs[5].y = -20.2
posVecs[5].z = -189.36
viewVecs[5] = {}
viewVecs[5].x = -1.37
viewVecs[5].y = -0.85
viewVecs[5].z = 2.77

-- above graphics
posVecs[6] = {}
posVecs[6].x = -90.53
posVecs[6].y = 170.31
posVecs[6].z = -179.31
viewVecs[6] = {}
viewVecs[6].x = 0.0
viewVecs[6].y = -20.2
viewVecs[6].z = 2.0

--Graphics
myData[ "Slide5" ] = Global:CreateEntity( "../../Assets/Xml/entities/e_Slide05.xml" )
myData.Slide5:SHR_sPosition(-90.53, 22.6, -82.31)
posVecs[7] = {}
--posVecs[7].x = -90.53
--posVecs[7].y = 22.31
--posVecs[7].z = -82.31
posVecs[7].x = -83.53
posVecs[7].y = 25.31
posVecs[7].z = -80.31
viewVecs[7] = {}
viewVecs[7].x = -1.2
viewVecs[7].y = -0.2
viewVecs[7].z = -.8

-- above graphics (again)
posVecs[8] = {}
posVecs[8].x = -90.53
posVecs[8].y = 100.31
posVecs[8].z = -82.31
viewVecs[8] = {}
viewVecs[8].x = 0.0
viewVecs[8].y = -20.2
viewVecs[8].z = 2.0

--Physics
myData[ "Slide6" ] = Global:CreateEntity( "../../Assets/Xml/entities/e_Slide06.xml" )
myData.Slide6:SHR_sPosition(-31.33, 43.52, 62.81)
posVecs[9] = {}
posVecs[9].x = -31.33
posVecs[9].y = 43.52
posVecs[9].z = 62.81
viewVecs[9] = {}
viewVecs[9].x = -0.1
viewVecs[9].y = 1.1
viewVecs[9].z = 1.64

-- above Physics
posVecs[10] = {}
posVecs[10].x = 0.33
posVecs[10].y = 50.52
posVecs[10].z = 10.00
viewVecs[10] = {}
viewVecs[10].x = 26.0
viewVecs[10].y = -10.0
viewVecs[10].z = -10.0

--AI/Gameplay
myData[ "Slide7" ] = Global:CreateEntity( "../../Assets/Xml/entities/e_Slide07.xml" )
myData.Slide7:SHR_sPosition(27.52, 42.05, 29.14)
posVecs[11] = {}
posVecs[11].x = 27.52
posVecs[11].y = 40.35
posVecs[11].z = 29.14
viewVecs[11] = {}
viewVecs[11].x = 19
viewVecs[11].y = -5
viewVecs[11].z = 16.5

--Obstacles
myData[ "Slide8" ] = Global:CreateEntity( "../../Assets/Xml/entities/e_Slide08.xml" )
myData.Slide8:SHR_sPosition(-12.61, 33.2, -45.98)
posVecs[12] = {}
posVecs[12].x = -12.61
posVecs[12].y = 33.2
posVecs[12].z = -45.18
viewVecs[12] = {}
viewVecs[12].x = -22.4
viewVecs[12].y = 1.2
viewVecs[12].z = -23.2

local max = 12
local min = 1
local currentSlide = 1
local slideName

while( 1 ) 
do
  coroutine.yield()

  if( currentSlide ~= (max + 1) ) then
	  if( Global:IsTriggered( key_names_to_values( "Spacebar" ) ) ) or ( CheckPosition( currentSlide ) )
	  then
	    if( currentSlide < max ) 
	    then
		    currentSlide = currentSlide + 1
		    slideName = "Slide"..currentSlide
		    --Global:SetCameraTargetObject( myData[ slideName ]:GetMyPointer() )
		    Global:SetCameraTargetPositionVector( posVecs[ currentSlide ].x, posVecs[ currentSlide ].y, posVecs[ currentSlide ].z )
		    Global:SetCameraViewVector( viewVecs[ currentSlide ].x, viewVecs[ currentSlide ].y, viewVecs[ currentSlide ].z )
		    
		    if( currentSlide == 3 ) then
		      Global:PlayMusic2D( "../../Assets/Sounds/chimes_and_choir.mp3" )
		    
		    end
  		
	    else
		    currentSlide = max + 1
		    local aster = Player:gAster()
		    --Global:SetCameraTargetObject( aster:GetMyPointer() )
		    Global:SetCameraViewVector( -57, 3.1, -59.6 )

		    Global:DeleteEntityByPtr( myData.Slide1:GetMyPointer() )
		    Global:DeleteEntityByPtr( myData.Slide2:GetMyPointer() )
		    Global:DeleteEntityByPtr( myData.Slide3:GetMyPointer() )
		    Global:DeleteEntityByPtr( Entity:GetMyPointer() )
		    
		    local spawner
		    spawner = Global:CreateEntity( "../../Assets/Xml/entities/e_FireflySwarm.xml" )
		    spawner:SHR_sPosition( 0, 30, 0 )
		    
		    spawner = Global:CreateEntity( "../../Assets/Xml/entities/e_FireflySwarm.xml" )
		    spawner:SHR_sPosition( -19, 34, -47 )
		    
		    spawner = Global:CreateEntity( "../../Assets/Xml/entities/e_FireflySwarm.xml" )
		    spawner:SHR_sPosition( 36, 46, -35 )
		    
		    spawner = Global:CreateEntity( "../../Assets/Xml/entities/e_FireflySwarm.xml" )
		    spawner:SHR_sPosition( 26, 52, 27 )
		    
		    spawner = Global:CreateEntity( "../../Assets/Xml/entities/e_FireflySwarm.xml" )
		    spawner:SHR_sPosition( 22, 25,-19 )

	    end
  	  
	  end

	  if( Global:IsTriggered( key_names_to_values( "Backspace" ) ) ) 
	  then
	    if( currentSlide > min ) 
	    then
		    currentSlide = currentSlide - 1
		    slideName = "Slide"..currentSlide
		    Global:SetCameraTargetPositionVector( posVecs[ currentSlide ].x, posVecs[ currentSlide ].y, posVecs[ currentSlide ].z )
		    Global:SetCameraViewVector( viewVecs[ currentSlide ].x, viewVecs[ currentSlide ].y, viewVecs[ currentSlide ].z )
	    end
  	  
	  end
  	
  end

end
