program ASCIICaverns;
//----------------------------------------------------------------------------------------------------------------------
// Alex 'Shirson' Nevskiy 2012-08
//----------------------------------------------------------------------------------------------------------------------

uses
  OpenGL,
  eXgine,
  Windows,
  Classes,
  SysUtils,
  _scd,
  _load,
  _render,
  _var in '_var.pas',
  MainMenu in 'MainMenu.pas',
  GameSys in 'GameSys.pas',
  LevelSys in 'LevelSys.pas',
  HelpScreen in 'HelpScreen.pas',
  _math in '_math.pas',
  InfoScreen in 'InfoScreen.pas';

//----------------------------------------------------------------------------------------------------------------------

procedure Update; //
begin
  GetMouseState;
  GetKeysState;

  FillChar(GUIMatrix, SizeOf(GUIMatrix),0);

  //inp.MDelta.
//  GameInput.Keys.Up:=(GetAsyncKeyState(keyUp) and $8000)=$8000;
//  GameInput.Keys.Right:=(GetAsyncKeyState(keyRight) and $8000)=$8000;
//  GameInput.Keys.Down:=(GetAsyncKeyState(keyDown) and $8000)=$8000;
//  GameInput.Keys.Left:=(GetAsyncKeyState(keyLEFT) and $8000)=$8000;
//  input.B1:=(GetAsyncKeyState(VK_Space) and $8000)=$8000;
//  input.B2:=(GetAsyncKeyState(VK_SHIFT) and $8000)=$8000;
//  input.PAUSE:=(GetAsyncKeyState(VK_PAUSE) and $8000)=$8000;
//  input.Ent:=(GetAsyncKeyState(VK_RETURN) and $8000)=$8000;
//  GameInput.ESC:=(GetAsyncKeyState(VK_ESCAPE) and $8000)=$8000;
//
  case GameState of
    gsMenu: DrawMainMenu;
    gsHelp: DrawHelpScreen;
    gsGame: DrawGame;
    gsInfo: DrawInfoScreen;
  end;

  //if GameInput.Mouse.ShowCursor then
  if GameState = gsGame then
  GUIMatrix[GameInput.Mouse.X, GameInput.Mouse.Y].BG:= ColorFilter(colWhite, CFilter);// not GUIMatrix[GameInput.Mouse.X, GameInput.Mouse.Y].BG;
  //wnd.Caption(pchar('ASCII Caverns ['+inttostr(ogl.fps)+']'));
  //if IsControl(VK_UP) then wnd.Caption(pchar('UP')) else
  //wnd.Caption(pchar('ASCII Caverns ['+inttostr(ogl.fps)+']'));
  //wnd.Caption(pchar('ASCII Caverns ['+inttostr(HideMouseDelay)+']'));
  //wnd.Caption(pchar('ASCII Caverns ['+booltostr(isControl(keyLMB))+']'));
end;

//----------------------------------------------------------------------------------------------------------------------

procedure Render;
//var a,b,c:byte;
begin
  glColor3ub(0,0,0);
  ogl.Clear(True, True);
  tex.Disable;
  RenderGUI;
end;

//----------------------------------------------------------------------------------------------------------------------

begin
  //randomize;
  ogl.VSync(true);
  wnd.Create('ASCII Caverns',50,250);
  //snd.Freq(22050);
  GameInput.Mouse.RawX:= TotalW /2;
  GameInput.Mouse.RawY:= TotalH /2;

  eX.SetProc(PROC_UPDATE, @Update);
  eX.SetProc(PROC_RENDER, @Render);

  wnd.Mode(false, 810, 360, 32, 85);
  inp.MCapture(true);
  LoadData;

  ogl.Set2D(0, 0, 810, 360);
  glTranslatef(5, 5, 0);
  eX.MainLoop(60);

end.

//----------------------------------------------------------------------------------------------------------------------

