unit uGame;

interface
uses
  zglHeader, uScene, uMap,
  LexUtils, uList, uParticle,
  uGun, uBullet, uZepelin,
  uBomb, uBoom, uWinPage, uGamePage;

const
  BonusCount = 70;

type
  TGame = class(TScene)
    Map  : TMap;
    Gun1 : TGun;
    Guns : TGunList;
    Bullets : TBulletList;
    Bombs : TBombList;
    Zepelins : TZepelinList;
    Booms : TBoomList;

    LosePage,
    WinPage : TGamePage;
    Particles : TParticles;

    procedure   Start;
    procedure   Draw; override;
    procedure   Update; override;
    constructor Create(const SceneMng : tSceneMng); override;
    constructor Free;
    procedure   SetParam(Param: Integer); override;
  end;

implementation
uses
  uMaterials, uConst, uMyApp;
{ TGame }

constructor TGame.Create;
begin
  inherited;
  Map := TMap.Create(WinW, WinH);
  Bombs := TBombList.Create(Map);
  Zepelins := TZepelinList.Create(Map, Bombs);

  Booms := TBoomList.Create(Bombs, Zepelins);
  Bullets := TBulletList.Create(Map, Booms);
  Guns := TGunList.Create(Map, Bullets);

  Gun1 := Guns.Add(TGun.Create()) as TGun;



  WinPage  := TWinPage.Create(nil);
  LosePage := TLosePage.Create(nil);

  Particles := TParticles.Create;
  Map.PParticles := Particles;
end;

procedure TGame.Draw;
begin
  Map.Draw;
  Bombs.Next.Draw;

  Bullets.Next.Draw;
  Guns.Next.Draw;

  Zepelins.Next.Draw;

  Booms.Next.Draw;

  LosePage.Draw;
  WinPage.Draw;

  pr2d_Rect(400 - 200, 20 - 5, 400, 30, $0, $A0, PR2D_FILL);
  pr2d_Rect(400 - 200, 20 - 5, 400, 30, $FFFFFF, $AF);
  text_Draw( mFont_1, 400, 20,
  '   FPS = ' + INt2S(zgl_Get(RENDER_FPS)) +
  '   Count = ' + INt2S(Zepelins.Count)
  , TEXT_HALIGN_CENTER );
end;

constructor TGame.Free;
begin

end;

procedure TGame.SetParam(Param: Integer);
begin
  Start;
end;

procedure TGame.Start;
var
  I : Integer;
begin
  Map.Start;
  Bombs.Clear;
  Zepelins.Clear;

  Booms.Clear;
  Bullets.Clear;

  for I := 1 to 10 do
    Zepelins.Add(TZepelin.Create);
end;

procedure TGame.Update;
var
  I : Integer;
  X, Y : Integer;
begin
  Guns.Next.Update;
  Bullets.Next.Update;
  Zepelins.Next.Update;
  Bombs.Next.Update;
  Booms.Next.Update;

  if WinPage.NoActive then
  if LosePage.NoActive then
  begin
    if Zepelins.Count <= 0 then
      WinPage.Show;

    if Map.BunkerNoLive then
      LosePage.Show;

    if mouse_Click(M_BLEFT) then
    begin
      Gun1.MouseWork(mouse_X, mouse_Y);
    end;
  end;

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

end.
