;---------------------------------------
; Set Up Intro Screen
;---------------------------------------
Global intro = LoadSprite("title.jpg",1,cam)
aspect# = 0.75
ScaleSprite intro, 0.1, 0.1*aspect#
PositionEntity intro, 0, 0, 0.1
SpriteViewMode intro,2
EntityOrder intro,-3
TurnEntity intro,0,-10,0
HideEntity intro

ScaleSprite intro, 10, 10*aspect
PositionEntity intro, 0, 0, 10
SpriteViewMode intro,2
EntityOrder intro,-3
TurnEntity intro,0,-10,0
HideEntity intro

;---------------------------------------
; Set Up Info Screens
;---------------------------------------
Global m_plot = LoadSprite("plot.tga",3,cam)
ScaleSprite m_plot, 10, 10*aspect#
PositionEntity m_plot, 0, 0.0, 10
SpriteViewMode m_plot,2
EntityOrder m_plot,-5

Global m_hints = LoadSprite("hints.tga",3,cam)
ScaleSprite m_hints, 10, 10*aspect#
PositionEntity m_hints, 0, 0.0, 10
SpriteViewMode m_hints,2
EntityOrder m_hints,-5

Global m_credits = LoadSprite("credits.tga",3,cam)
ScaleSprite m_credits, 10, 10*aspect#
PositionEntity m_credits, 0, 0.0, 10
SpriteViewMode m_credits,2
EntityOrder m_credits,-5

;---------------------------------------
; Set Up Buttons
;---------------------------------------
Global b_help = LoadSprite("help.tga",3,cam)
ScaleSprite b_help, 0.1, aspect#/10
PositionEntity b_help, 		-0.5, -0.6, 1
SpriteViewMode b_help,2
EntityOrder b_help,-5

Global b_end = LoadSprite("end.tga",3,cam)
ScaleSprite b_end, 0.1, aspect#/10
PositionEntity b_end,		0.5, -0.6, 1
SpriteViewMode b_end,2
EntityOrder b_end,-5

Global b_ok = LoadSprite("ok.tga",3,cam)
ScaleSprite b_ok, 0.1, aspect#/10
PositionEntity b_ok, 		0, -0.6, 1
SpriteViewMode b_ok,2
EntityOrder b_ok,-5

Global b_hl = LoadSprite("high.tga",3,cam)
ScaleSprite b_hl, 0.1, aspect#/10
PositionEntity b_hl, 		0, -0.6, 1
SpriteViewMode b_hl,2
EntityOrder b_hl,-5

MenuUpdate()

; ==============================================================================
; Load "Skybox"

Global starbox = CreateSphere(16) : starboxtex = LoadTexture("stars3.tga")
ScaleEntity starbox,2000,2000,2000	;pluto\distance# * 1.1,pluto\distance# * 1.1,pluto\distance# * 1.1
EntityTexture starbox,starboxtex
EntityOrder starbox,100
FlipMesh starbox
EntityFX starbox, 1

Function IntroText(message$)
	RenderWorld
	Text GraphicsWidth() / 4,						GraphicsHeight()/2, message
	Text GraphicsWidth() - (GraphicsWidth() / 4),	GraphicsHeight()/2, message
	Flip
End Function

Function LoadGame()

	PositionEntity g_slCameraL,0,0,0
	PositionEntity g_slCameraR,0,0,0

	DebugLog "LoadGame()"

	ShowEntity intro

	IntroText "Loading character..."
	LoadPlayer()
	IntroText "Loading planets..."
	LoadPlanets()
	IntroText "Loading sounds..."
	LoadSounds()
	
	; set up aliases for convenience
	sol.Planet		= FindPlanet("sol")
	mercury.Planet	= FindPlanet("mercury")
	venus.Planet	= FindPlanet("venus")
	earth.Planet	= FindPlanet("earth")
	mars.Planet		= FindPlanet("mars")
	jupiter.Planet	= FindPlanet("jupiter")
	saturn.Planet	= FindPlanet("saturn")
	uranus.Planet	= FindPlanet("uranus")
	neptune.Planet	= FindPlanet("neptune")
	pluto.planet	= FindPlanet("pluto")

	; miscellaneous special case elements
	IntroText "Setting up environment..."
	
	FlipMesh sol\model : sol\flipped = True
	;EntityFX sol\model, 16 ; disable backface culling (problem: hides sun's light source)

	sunglow = LoadSprite("starGlow.tga", 3, sol\model)
	EntityAlpha sunglow,1
	SpriteViewMode sunglow,1
	ScaleSprite sunglow,sol\radius*3,sol\radius*3
	EntityOrder sunglow,2

	venussky2 = CreateSphere(20, venus\sky)
	PositionEntity venussky2,0,0,0
	ScaleEntity venussky2,0.9,0.9,0.9
	EntityColor venussky2, .5, .3, .1
	
	;jupiterfog = RingSystem("jupiterFog.tga", jupiter\radius, jupiter\radius * 1.1, 0, 360, 80, True)
	;EntityParent jupiterfog, jupiter\ringpivot
	;MoveToEntity(jupiterfog, jupiter\ringpivot)

	RotateEntity saturn\ringpivot,20,0,0	
	RotateEntity uranus\ringpivot,80,0,0
	
	ShowPlanet(sol)
	
	HideEntity intro
	
End Function

Global palette=0, palette_id#=1

Function PlanetPicker.Planet()
	id# = palette_id
	
	If palette = 0 Then
		palette = CreatePivot(cam)
	
		For p.Planet = Each Planet
			If p\sprite <> 0 Then
				icon = CopyEntity(p\sprite, palette)
				EntityOrder icon,-25
				ScaleSprite icon, 1, 1
				PositionEntity icon, 1.3*p\id - 8, p\id/2.0 - 7, 10
			EndIf
		Next
		
		ShowEntity g_planhigh
		EntityOrder g_planhigh,-26
		ScaleEntity g_planhigh, 1,1,1
	EndIf
		
	MoveMouse GraphicsWidth()/2,GraphicsHeight()/2	; lock mouse at center of screen
		
	If mxspd <> 0 Then
		total = CountChildren(palette)
		If total = 0 Then DebugLog "no planets to pick" : End
		If mxspd > 0 And id < total Then
			id# = id# + 0.2
		ElseIf mxspd < 0 And id > 1 Then
			id# = id# - 0.2
		EndIf
		
		EntityParent g_planhigh, GetChild(palette, Int(id))
		PositionEntity g_planhigh, 0,0,0
	EndIf
	
	If MouseHit(1) Then
		EntityOrder g_planhigh,  0
		EntityParent g_planhigh, 0
		HideEntity g_planhigh
		
		For i = 1 To total
			FreeEntity GetChild(palette, 1)
		Next
		FreeEntity palette
		palette = 0
	
		FlushMouse : FlushKeys
		Return LookupPlanet(Int(id)+1)	; because sol is 1
	EndIf
	
	palette_id = id
	Return Null
End Function