unit uLevelEnd;



interface

uses
  Classes, uObj, uBox, zglHeader;

type

{ TLevelEnd }

TLevelEnd = class(TObj)
  constructor Create; overload;
  function  Final : boolean;
  procedure Draw; override;
end;

{ TFish }

TFish = class(TBox)
  constructor Create(const X, Y :  Single);
  procedure Draw; override;
  procedure Activate(B : Boolean); virtual;
end;

implementation
uses
  uHero, uConst, uWorld, uMaterials;

{ TFish }

constructor TFish.Create(const X, Y :  Single);
begin
  Init(X, Y, cFishSize, cFishSize, $77AAFF);
  OldX :=zCircle.cX;
  OldY :=zCircle.cY;
  A := c_maxA + 1;
  Active := false;
  OnHero := false;

  Objs.Add(Self);
  Fishs.Add(Self);
  DynamicObjs.Add(Self);
end;

procedure TFish.Draw;
begin
  if not OnHero then
  with DrawRect do
    ssprite2d_Draw(mFish, X - 4, Y - 4, 32, 32, 0);
end;

procedure TFish.Activate(B: Boolean);
begin
  if not OnHero and B then
  begin
    Active := true;
    A := 0;
    OnHero:= false;
    OldX := zCircle.cX - Hero.zCircle.cX;
    OldY := zCircle.cY - Hero.zCircle.cY;
    zRect.W := 0;
    zRect.H := 0;
    DynamicObjs.Remove(Self);
  end
end;

{ TLevelEnd }

constructor TLevelEnd.Create;
begin

end;

function TLevelEnd.Final : boolean;
var
  I : Integer;
begin
  result := false;
  if col2d_CircleInRect(Hero.zCircle, zRect) then
  begin
    for I := 0 to Fishs.Count - 1 do
    if not TFish(Fishs[I]).OnHero then
      Exit;
    result := true;
  end
end;

procedure TLevelEnd.Draw;
begin
  inherited Draw;
end;

end.

