unit uGame;

interface
uses
  zglHeader, uScene, uPage;


type
  TGame = class(TScene)
    Level  : Integer;
    procedure   SetParam(Param : Integer); override;
    //procedure   Start;
    procedure   Draw;   override;
    procedure   Update; override;
    constructor Create(const SceneMng : tSceneMng); override;
    destructor  Free;   override;
  end;

  var
  Btn : TPageButton;

implementation
uses
  uMyApp, uMaterials, uConst, uWorld, uHero;

{ TGame }

constructor TGame.Create;
begin
  inherited Create(SceneMng);
  WorldCreate;
end;

procedure TGame.Draw;
begin
  uWorld.Draw;
  pr2d_Rect(5, 5, 170, 32, $202020, $FF, PR2D_FILL);
  text_Draw(mFont_1, 10, 10, 'Бомбы ' + u_IntToStr( Bomb.Count));
  if LevelEnd.Final then
    ssprite2d_Draw(mWin, (WinW - 512) div 2, (WinH - 128) div 2, 512, 128, 0)
  else
  if Hero.Fail then
    ssprite2d_Draw(mFail, (WinW - 512) div 2, (WinH - 128) div 2, 512, 128, 0)
end;

destructor TGame.Free;
begin

end;

procedure TGame.SetParam(Param : Integer);    //Start;
begin
  Btn.Enabled:=true;
  //uWorld.WorldInit;
  Level := Param;
  case Param of
    1: uWorld.Level_1;
    2: uWorld.WorldInit;
  end;
  //with (PSceneMng as TMyApp) do
  //  NowScene := Self;
end;

procedure TGame.Update;
begin


  if LevelEnd.Final then
  begin
    if key_Press(K_ENTER) then
    with (PSceneMng as TMyApp) do
      ChangeScenePar(2, 0);
  end
  else
  if Hero.Fail then
  begin
    if key_Press(K_ENTER) then
    with (PSceneMng as TMyApp) do
      ChangeScenePar(Level, 0);
  end
  else
    uWorld.Update;

  if key_Press(K_ESCAPE) then
  with (PSceneMng as TMyApp) do
    ChangeScene(MainMenu, 0);
    //zgl_Exit;
end;

end.
