unit Radar;

interface

uses
  _Geometry,
  Frost.Engine,
  Frost.GL,
  BaseBuild,
  _PNG;

type
TRadar = class(TBuild)
  private
    class var FMesh: TMesh;          
    class var FRadarMesh: TMesh;
    class var FMaterial: TMaterial; 
  private                       
    FTower: TGameObject;
    FTowerRenderer: TMeshRenderer;      
    FAngle: Single;
  public
    procedure OnStart; override;
    procedure OnUpdate(const Delta: Double); override;
    procedure OnDestroy; override;
  end;

implementation

{$REGION 'Factory'}
procedure TRadar.OnStart;
begin
  if FMesh = nil then
  begin
    FMesh := Resources.LoadMMSMesh('data/models/radar.mms', 0.2);
    FRadarMesh := Resources.LoadMMSMesh('data/models/radar_tower.mms', 0.2);
    FMaterial := TTexturedMaterial.Create(LoadPNGTexture('data/textures/radar.png'));
  end;
  CreateMesh(FMesh, FMaterial, Vector3(1.2,1.2,1.6 ), 15);
  FTower := TGameObject.Create(GameObject);
  FTowerRenderer := TMeshRenderer.CreateMeshRenderer(FRadarMesh, FMaterial);
  FTower.AddComponent(FTowerRenderer);        
end;
         
procedure TRadar.OnUpdate(const Delta: Double);
begin
  if (GameObject.Enabled <> FActive) then
  begin
    if (FLife > 0) then
    begin
      FTowerRenderer.Enable := GameObject.Enabled;
    end;
  end;  
  CheckBoundCollision();
  if (FActive) and (FLife > 0) then
  begin
    FAngle := GetRound(FAngle + 5 * Delta);
    FTower.LocalRotation := Rotate(FAngle, VECTOR3_FORWARD);
  end;
  Animate(Delta);
end;

procedure TRadar.OnDestroy;
begin

end;
{$ENDREGION}

end.

end.
