unit ObjectSwitch;

interface

uses
  CustomObject, Vec2f, IniFiles;

type
  TObjectSwitch = class(TCustomObject)
  private
    FDelay: Boolean;
    FRadius: Single;
    function IsActive: Boolean; override;
  published
    procedure Load(Aini: TIniFile); override;
    procedure Draw; override;
  end;

implementation

uses
  Resources, Level.Map;

procedure TObjectSwitch.Load(Aini: TIniFile);
begin
  inherited;
  FDelay := False;
  FRadius := TLevelMap.FieldSize;
end;

function TObjectSwitch.IsActive: Boolean;
var
  i: Integer;
  Pos: TVec2f;
  PointA, PointB: TVec2f;
begin
  if FDelay then
    Exit(True);

  PointB := TVec2f.Create(FRadius, FRadius);
  PointA := Position - PointB / 2;
  PointB := PointA + PointB;

  for i := 0 to TGlobals.LevelHeroes.Count - 1 do
  begin
    Pos := TGlobals.LevelHeroes[i].Position;
    if (Pos.X > PointA.X) and (Pos.Y > PointA.Y) and (Pos.Y < PointB.Y) and (Pos.Y < PointB.Y) then
      if Pos.Distance(Position) < FRadius then
      begin
        FDelay := True;
        Exit(True);
      end;
  end;
  Result := False;
end;

procedure TObjectSwitch.Draw;
begin
 { if Action then
    TGlobals.QuadRender.DrawCircle(Position, FRadius, FRadius - 3, $FF00FF00)
  else
    TGlobals.QuadRender.DrawCircle(Position, FRadius, FRadius - 3);   }
end;

end.
