unit uGMP;

{$mode delphi}

interface

uses
  Classes, uScene, zglHeader, uGMPH, ugmppart, uGMPM, uherogui;

type
{ TGMP }

TGMP = class(tScene)
  gh  : TGMPH;
  HeroGUI : THeroGUI;
  Level : Integer;
  WinForm : TWinForm;
  LoseForm : TLoseForm;
  constructor Create(const PSceneMng : tSceneMng); override;
  procedure SetParam(Param : Integer); override;
  procedure Draw; override;
  procedure Update; override;
  procedure Win;
  procedure Lose;
end;

var
  ListBul : TList;
  ListMapObj : TList;
  ListLObj : TList;
  //List4Del : TList;
  ListAct : TList;
  Map : TMap;

implementation
uses
  uGlobal, uGMPBul, uGMPL, ugmpao, ugmpobject, ulevels;

{ TGMP }

constructor TGMP.Create(const PSceneMng: tSceneMng);
begin
  inherited Create(PSceneMng);
  gh := TGMPH.Create;
  Map := TMap.Create;
  Map.GH := gh;

  ListBul := TList.Create;

  ListMapObj    := TList.Create;
  ListParLine   := TList.Create;
  ListParGr     := TList.Create;
  ListPar  := TList.Create;
  ListLObj := TList.Create;
  //List4Del := TList.Create;

  ListAct := TList.Create;

  HeroGUI := THeroGUI.Create(0,32,255,Self);

  WinForm := TWinForm.Create(WinW div 2, WinH div 2 - 100, 255, Self);
  LoseForm := TLoseForm.Create(WinW div 2, WinH div 2 - 100, 255, Self);


end;

procedure TGMP.SetParam(Param: Integer);
var
  I : Integer;
begin
  Level := Param;
  LoadLevel(Param);
  WinForm.Visible:=false;
  WinForm.Alpha:=0;
  LoseForm.Visible:=false;
  LoseForm.Alpha:=0;
  GH.Live := 200;
  GH.PowerTime:=0;
  GH.TempC:=0;
  GH.Regun:=false;
  GH.Fire:=false;
  GH.Timer:=0;
  for I := 1 to 4 do
  begin
    GH.GunMag[I].Count1:= Guns[I].MaxCount1;
    GH.GunMag[I].Count2:= Guns[I].MaxCount2;
  end;
end;

procedure TGMP.Draw;
var
  I, J : Integer;
begin
  //pr2d_Rect(0, 0, WinW, WinH, $FFFFFF, $FF, PR2D_FILL);

{  for I := 0 to WallCountX do
  for J := 0 to WallCountY do
  if Map.Wall[I, J] then
    pr2d_Rect(I * cwallsize, J * cwallsize, cwallsize, cwallsize, $FF, $A0);
}
  for I := 0 to ListParGr.Count - 1 do
    TParRect(ListParGr.Items[I]).Draw;

  for I := 0 to ListAct.Count - 1 do
    TActObj(ListAct.Items[I]).Draw;

  gh.Draw;
  for I := 0 to ListBul.Count - 1 do
    TGMPBul(ListBul.Items[I]).Draw;

  for I := 0 to ListMapObj.Count - 1 do
    TGMPObject(ListMapObj.Items[I]).Draw;

  for I := 0 to ListParLine.Count - 1 do
    TParLine(ListParLine.Items[I]).Draw;

  for I := 0 to ListPar.Count - 1 do
    TParRect(ListPar.Items[I]).Draw;

  HeroGUI.Draw;
  if GH.PowerTime > 0 then
    Map.DrawMusicBox;

  if WinForm.Visible then
    WinForm.Draw
  else
  if LoseForm.Visible then
    LoseForm.Draw;
end;

procedure TGMP.Update;
var
  I : Integer;
begin
  inherited Update;
  if WinForm.IsActive then
    WinForm.Update(mouse_X, mouse_Y)
  else
  if LoseForm.IsActive then
      LoseForm.Update(mouse_X, mouse_Y)
  else
  begin
    gh.Update;
    HeroGUI.Update(mouse_X, mouse_Y);

    for I := ListAct.Count - 1 downto 0 do
      TActObj(ListAct.Items[I]).UpdateAct;

    for I := ListLObj.Count - 1 downto 0 do
      TGMPObject(ListLObj.Items[I]).Update;

   { for I := 0 to ListMapObj.Count - 1 do
      TGMPObject(ListMapObj.Items[I]).Color:= false;
   }
    for I := ListBul.Count - 1 downto 0 do
      TGMPBul(ListBul.Items[I]).Update;

    for I := ListParLine.Count - 1 downto 0 do
      TParLine(ListParLine.Items[I]).Update;

    for I := ListPar.Count - 1 downto 0 do
      TParRect(ListPar.Items[I]).Update;

    if key_Down(K_ESCAPE) then
    begin
      MainMenu.ButtonGame.Visible:=true;
      SceneManager.ChangeScene(MainMenu, 0);
    end;
  end;
end;

procedure TGMP.Win;
begin
  if Level < Length(Levels) then
    SceneManager.ChangeSceneAndPar(Self, Level + 1, 0)
  else
    WinForm.Visible:=true;
end;

procedure TGMP.Lose;
begin
  LoseForm.Visible:=true;
end;

end.

