unit ObjectTimer;

interface

uses
  CustomObject, Vec2f, System.SysUtils, IniFiles;

type
  TObjectTimer = class(TCustomObject)
  private
    FTime: Double;
    FTimeDelay: Single;
    function IsActive: Boolean; override;
  public

  published
    procedure Load(Aini: TIniFile); override;
    procedure Process(const Delta: Double); override;
  end;

implementation

uses
  Resources, Level.Map;

procedure TObjectTimer.Load(Aini: TIniFile);
var
  Str: String;
begin
  inherited;
  Str := 'Obj_' + IntToStr(ID);
  FTimeDelay := Aini.ReadFloat(Str, 'Time', 1);
  FTime := 0;
end;

function TObjectTimer.IsActive: Boolean;
begin
  Result := FTime >= FTimeDelay;
end;

procedure TObjectTimer.Process(const Delta: Double);
begin
  inherited;
  if ParentAction then
    FTime := FTime + Delta
  else
    FTime := 0;
end;

end.
