// File: splash.agc
// Created: 20-04-26

type tStone
	id		as integer
	scale	as float
endtype

function	Splash(env ref as tEnvironment)
	id 		as integer
	scale 	as float
	v		as tVehicle
	p		as tPoint2D
	i		as integer
	f		as tPoint
	t		as tPoint
	stones 	as tStone[]
	title	as tObject
	rumble 	as integer
	bg		as integer
	icons	as integer[]
	plinth	as tObject
	trees	as tObject
	hills	as tObject
	button	as integer
	
	SetTextVisible(env.place, 0)
	SetTextVisible(env.lap, 0)
	SetSpriteVisible(env.pickups, 0)

	bg = CreateSprite(LoadImage("texture/title.png"))
	SetSpriteDepth(bg, 5)
	
	Transition(env)	
	
	ClearScreen()		
	LowRez(env)

	FlushEscapeKey()
	
	SetMusicVolumeOGG(env.theme, 30)
	
	do		
		button = AnyJoystickButton(TRUE)

		if GetRawKeyState(KEY_ESCAPE) or button = JOYSTICK_BACK  
			gGameState = GAMESTATE_EXIT
			exit
		elseif GetRawKeyState(asc("S")) or button = JOYSTICK_X
			gGameState = GAMESTATE_SETTINGS
			exit			
		elseif GetRawKeyState(asc("F"))
			gGameState = GAMESTATE_FINISH
			exit
		elseif GetPointerPressed() or GetRawKeyPressed(KEY_UP) or button = JOYSTICK_START or button = JOYSTICK_A or button = JOYSTICK_B or button = JOYSTICK_Y or GetRawKeyPressed(KEY_ENTER)  or GetRawKeyPressed(KEY_SPACE) 
			gGameState = GAMESTATE_SELECT
			exit
		endif
		
		sync()	
	loop
	
	PlaySound(env.coin.sound)
	
	ClearScreen()
	
	sync()

	DestroySprite(bg)
	SetSpriteVisible(env.canvas, 0)			
	SetTextVisible(env.place, 1)
	SetTextVisible(env.lap, 1)
endfunction 

	