unit ugmpao;

{$mode delphi}

interface

uses
  uGMPObject;

type

  { TPortal }

  { TActObj }

  TActObj = class(TGMPObject)
    Color2 : Integer;
    procedure UpdateAct; virtual;
    function Act : Boolean; virtual;
    constructor Create(X, Y : Single); virtual;
    procedure Draw; override;
  end;

  TPortal = class(TActObj)
    Key : array[1..4] of Boolean;
    procedure Draw; override;
    function Act : Boolean; override;
    constructor Create(X, Y : Single); override;
  end;

  { TPortalKey }

  TPortalKey = class(TActObj)
    Key : Byte;
    function Act : Boolean; override;
    constructor Create(X, Y : Single; K : Byte);
  end;

  { TDoor }

  TDoor = class(TActObj)
    Key, Open  : Boolean;
    Obj : TGMPObject;
    ColorN : Integer;
    Vert : Boolean;
    procedure Draw; override;
    procedure UpdateAct; override;
    function Act : Boolean; override;
    constructor Create(X, Y, W, H : Single; pColorN : Integer);
  end;

  { TDoorKey }

  TDoorKey = class(TActObj)
    Door : TDoor;
    ColorN : Integer;
    function Act : Boolean; override;
    constructor Create(X, Y : Single; pColorN : Integer);
  end;

  { TBonus }

  TBonus = class(TActObj)
    BonType : Integer;
    Text : String;
    function Act : Boolean; override;
    constructor Create(X, Y : Single; pBonType : Integer);
    procedure Draw; override;
  end;

implementation
uses
  zglHeader, uGMP, uGlobal, uGMPBul;
const
  cPortalKeyColor : array[1..4] of Integer = ($F02222, $02F022, $F0F022, $0202F0);
  cDoorColor : array[1..4] of Integer = ($964b00, $002f95, $8ac8ff, $800080);
  cBonusColor : array[0..5] of Integer = ($FFA0A0, $4070CD, $ca3a27, $1b877e, $004d00, $f754e1);
  cBonusColor2 : array[0..5] of Integer = ($EF9090, $3060BD, $ba2a17, $0b776e, $003d00, $e744d1);
  cBonusText : array[0..5] of string = ('+','P','F','S','A','^');
{ TBonus }

function TBonus.Act: Boolean;
begin
  case BonType of
    0 : begin
           Map.GH.Live := Map.GH.Live + 35;
           if Map.GH.Live > 200 then
             Map.GH.Live := 200;
        end;
    1,2,3,4 : Map.GH.GunMag[BonType].Count2 := Map.GH.GunMag[BonType].Count2 + Guns[BonType].MaxCount1 * 2;
    5 : Map.GH.SetPower;
  end;
  Result := true;
end;

constructor TBonus.Create(X, Y: Single; pBonType: Integer);
begin
  BonType := pBonType;
  if (pBonType = 5) or (pBonType = 0) then
    Size.SetValue(12, 8)
  else
    Size.SetValue(15, 7);
  Text := cBonusText[BonType];
  Color := cBonusColor[BonType];
  Color2 := cBonusColor2[BonType];
  inherited Create(X, Y);
end;

procedure TBonus.Draw;
begin
  inherited Draw;
  text_DrawEx(mFont, Pos.X, Pos.Y, 1, 0, Text, $FF, $FFFFFF, TEXT_ALIGN_CENTER);
end;

{ TDoorKey }

function TDoorKey.Act: Boolean;
begin
  if Door <> nil then
  begin
    Door.Key := true;
    Result := true;
  end
  else
   Result := false;
end;

constructor TDoorKey.Create(X, Y: Single; pColorN: Integer);
begin
  ColorN := pColorN;
  Size.SetValue(c_door_key, c_door_key*1.5);
  Color := cDoorColor[pColorN];
  Color2 := cDoorColor[pColorN];
  inherited Create(X, Y);
end;

{ TDoor }

procedure TDoor.Draw;
begin
  if Key then
  pr2d_Rect(DrawPos.X, DrawPos.Y, DrawSize.X, DrawSize.Y, Color, $41, PR2D_FILL)
  else
  pr2d_Rect(DrawPos.X, DrawPos.Y, DrawSize.X, DrawSize.Y, Color, $10, PR2D_FILL);
end;

procedure TDoor.UpdateAct;
begin

  if Open and Enabled then
  begin
    if Vert then
    begin
      if Obj.Size.y > Obj.Size.x then
      begin
        Obj.Size.y := Obj.Size.y - 0.5;
        Obj.Pos.y := Obj.Pos.y - 0.25;
      end
      else
        Enabled:=false;
    end
    else
    begin
      if Obj.Size.x > Obj.Size.y then
      begin
        Obj.Size.x := Obj.Size.x - 0.5;
        Obj.Pos.x := Obj.Pos.x - 0.25;
      end
      else
        Enabled:=false;
    end;
    Obj.Update;
  end;
  inherited UpdateAct;
end;

function TDoor.Act: Boolean;
begin
  if Key then
    Open := Key;
  Result := false;
end;

constructor TDoor.Create(X, Y, W, H: Single; pColorN: Integer);
begin
  Enabled := true;
  Obj := TGMPObject.Create;
  Obj.Color := cDoorColor[pColorN];
  Obj.Size.SetValue(W, H);
  Obj.Pos.SetValue(X, Y);
  Obj.Update;
  Key := false;
  Open := false;
  ColorN := pColorN;
  Color := Obj.Color;
  Pos := Obj.Pos;
  Size := Obj.Size;
  Vert := H >= W;
  if Vert then
    Size.x := Size.x + chsize*1.7
  else
    Size.y := Size.y + chsize*1.7;
  Update;

end;

{ TPortalKey }

function TPortalKey.Act: Boolean;
begin
  if Map.Portal <> nil then
  begin
    Map.Portal.Key[Key] := true;
    Result := true;
  end
  else
   Result := false;
end;

constructor TPortalKey.Create(X, Y: Single; K: Byte);
begin
  Key := K;
  Size.SetValue(c_portal_key, c_portal_key);
  Color := cPortalKeyColor[Key];
  Color2 := Color;
  inherited Create(X, Y);
end;

{ TPortal }

procedure TPortal.Draw;
begin
  pr2d_Rect(DrawPos.X, DrawPos.Y, DrawSize.X, DrawSize.Y, $7F5FF0, $77, PR2D_FILL);
  if Key[1] then pr2d_Rect(DrawPos.X, DrawPos.Y, DrawSize.X div 2, DrawSize.Y div 2, cPortalKeyColor[1], $F0, PR2D_FILL);
  if Key[2] then pr2d_Rect(DrawPos.X, Pos.Y, DrawSize.X div 2, DrawSize.Y div 2, cPortalKeyColor[2], $F0, PR2D_FILL);
  if Key[3] then pr2d_Rect(Pos.X, DrawPos.Y, DrawSize.X div 2, DrawSize.Y div 2, cPortalKeyColor[3], $F0, PR2D_FILL);
  if Key[4] then pr2d_Rect(Pos.X, Pos.Y, DrawSize.X div 2, DrawSize.Y div 2, cPortalKeyColor[4], $F0, PR2D_FILL);
end;

function TPortal.Act : Boolean;
begin
  if Key[1] and Key[2] and Key[3] and Key[4] then
  begin
    Result := true;
    GMP.Win;
  end
  else
    Result := false;
end;

constructor TPortal.Create(X, Y: Single);
begin
  Enabled:=true;
  Size.SetValue(cportal_w, cportal_h);
  Key[1] := false;
  Key[2] := false;
  Key[3] := false;
  Key[4] := false;
  inherited Create(X, Y);
end;

{ TActObj }

procedure TActObj.UpdateAct;
begin
  if {Enabled and} Map.GH.RectColission(Rect) and Act then
  begin
    ListAct.Delete(ListAct.IndexOf(Self));
    Free;
  end;
end;

function TActObj.Act : Boolean;
begin

end;

constructor TActObj.Create(X, Y: Single);
begin
  Pos.SetValue(X, Y);
  Update;
end;

procedure TActObj.Draw;
begin
  pr2d_Rect(DrawPos.X, DrawPos.Y, DrawSize.X, DrawSize.Y, Color2, $D0, PR2D_FILL);
  pr2d_Rect(DrawPos.X + 2, DrawPos.Y + 2, DrawSize.X -4, DrawSize.Y-4, Color, $FF, PR2D_FILL);
end;

end.

