;==================================================================
;Project Title: CRYSTALIUM
;Author:        Vladislav Borzunov aka ObelardO
;Email:         Obelardos@gmail.com 
;Version:       0.9 Alpha
;Date:          04.03.13
;Notes:         main code-file
;==================================================================

Include "code\xors3d.bb"
Include "code\Loader.bb"
Include "code\Player.bb"
Include "code\Console.bb"
Include "code\Objects.bb"
Include "code\Menu.bb"

Const VERSION$ = "0.9a"
Const AUTHOR$ = "ObelardO"

Global WINDOW_TITLE$    = "Game Window"
Global WINDOW_HEIGHT    = 768
Global WINDOW_WIDTH     = 1024
Global WINDOW_DEPTH     = 32
Global RENDER_VSYNC     = 1
Global WINDOW_MODE      = 0
Global WINDOW_LOADED    = 0
Global WINDOW_BORDER    = 1
Global RENDER_ANTIALIAS = 1
Global DEBUG_MODE       = 0
Global LOGGING_MODE	= 0
Global LOGGING_STEAM    = 0
Global LOGGING_FILE$    = "Debug.log"
Global GAME_PAUSED      = 0
Global GAME_LANGUAGE$   = "ru"

CheckCommandLine()
ConsoleExecute("config "+ StrQuote("Config.cfg"))
ConsoleExecute("start")

DataLoad()
CreatePlayer()
CreateBackGround()
UpdateGame()
MapLoad(MAP_NAME)

While Not (xWinMessage("WM_CLOSE"))
	xUpdateWorld()
	xRenderWorld()
 	UpdateGame()
	xFlip
Wend

ConsoleExecute("stop")

Function UpdateGame()
	If Not GAME_PAUSED
		UpdatePlayers()
		UpdateCrystals()
		UpdateDynamites()
		UpdateBackGround()
		UpdateExplosions()
		UpdateStones()
		UpdateTriggers()
		UpdateTunnels()
		UpdateFireBalls()
		If xKeyHit(KEY_ESCAPE) CreateMenu("pause")
	Else
		If xKeyHit(KEY_ESCAPE) deletemenu("pause")
		UpdateMenus()
	End If
	xSetEffectVector MAP_ENTITY,	   "PosLight",       PLAYER_ACTIVE_X + Rnd(-0.1,0.1), PLAYER_ACTIVE_Y, PLAYER_ACTIVE_Z+Rnd(-0.05,0.05)
	xSetEffectFloat  MAP_ENTITY,     "DotLight",       Sin(MilliSecs()*.2)*.2+1.5
	xSetEffectFloat  MAP_ENTITY,     "RngLight",       PLAYER_CAMERA_ZOOM * LIGHT_POWER
	xSetEffectVector CRYSTAL_ENTITY, "cameraPosition", PLAYER_ACTIVE_X, PLAYER_ACTIVE_Y, PLAYER_ACTIVE_Z
End Function