program Scroller;

//{$APPTYPE CONSOLE}

uses
  SysUtils,
  uGame in 'uGame.pas',
  u_SceneM in 'MainCode\u_SceneM.pas',
  zglHeader in 'zglHeader.pas',
  uConst in 'uConst.pas',
  uMaterials in 'uMaterials.pas',
  Setup in 'MainCode\Setup.pas',
  LexUtils in 'MainCode\LexUtils.pas',
  uHero in 'GameSrc\uHero.pas',
  uBonus in 'GameSrc\uBonus.pas',
  uEnemy in 'GameSrc\uEnemy.pas',
  uEmiter in 'uEmiter.pas',
  uQuest in 'uQuest.pas',
  u_Menu in 'MainCode\u_Menu.pas',
  u_Button in 'MainCode\u_Button.pas',
  GSound in 'MainCode\GSound.pas',
  u_Menu_I in 'MainCode\u_Menu_I.pas',
  u_Menu_Level in 'MainCode\u_Menu_Level.pas',
  u_Menu_Name in 'MainCode\u_Menu_Name.pas',
  u_Player in 'MainCode\u_Player.pas',
  u_Records in 'MainCode\u_Records.pas',
  SD_menu in 'MainCode\SD_menu.pas',
  u_Win in 'MainCode\u_Win.pas',
  Bass in 'MainCode\Bass.pas',
  Intro in 'MainCode\Intro.pas';

procedure Init;
begin
  LoadMaterials;
  Rec  := t_Recs.Create;
  Main := TMain.Create;
  Menu := T_Menu.Create;
  uGame.Init;
  snd_Init();
  InitGS;
end;

procedure Update;
begin

  if Main.MSWork then
  case Main.Scene of
    tg_intro  : Intro.Work;
    tg_menu   : Menu.Work;
    tg_game   : uGame.Update;
    //tg_quit  = 0;
  end;

  //DJ;
  //uGame.Update;
//  wnd_SetCaption( '???? (c) cdmlex 20.10.12  FPS: ' + Int2S(zgl_Get( RENDER_FPS )));

  key_ClearState();
  mouse_ClearState();
  joy_ClearState();
end;

procedure Draw;
begin
  case Main.Scene of
    tg_intro  : Intro.Draw;
    tg_menu   : Menu.Draw;
    tg_game   : uGame.Draw;
    //tg_quit  = 0;
  end;

  Main.Draw;

//  batch2d_Begin();
 // zgl_Disable( COLOR_BUFFER_CLEAR );
//  uGame.Draw;
//  batch2d_End();
end;

procedure Quit;
begin
  pengine2d_Set( @particles );
  pengine2d_ClearAll();
end;

procedure UpdateDt( dt : Double );
begin
  pengine2d_Proc( dt );
end;

begin
  Randomize;


  Setup.LoadSetupFile;
// ????????? ?????
  StartScene := //tg_game;
//    tg_menu;
  tg_intro;

  Player_Load('Player');

  zglLoad( libZenGL );
  zgl_Reg( SYS_LOAD, @Init );
  zgl_Reg( SYS_DRAW, @Draw );
  zgl_Reg( SYS_EXIT, @Quit );
  zgl_Reg( SYS_UPDATE, @UpdateDt );

  timer_Add( @Update, 17);
//  wnd_SetCaption( 'Royale Dog' );
  SetWinSize(Setup.WinW, Setup.WinH);
  scr_SetOptions( WinW, WinH, REFRESH_MAXIMUM, FullWin, VSync );
  wnd_ShowCursor( True );
  zgl_Init;
end.


end.
