unit Forest;

interface   

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

type
TForest = class(TBuild)
  private
    class var FMesh: TMesh;
    class var FMaterial: TMaterial;    
    class var FGroundMesh: TMesh;
    class var FGroundMaterial: TMaterial;
  public
    procedure OnStart; override;
    procedure OnUpdate(const Delta: Double); override;
    procedure OnDestroy; override;
  end;

implementation

{$REGION 'Forest'}
procedure TForest.OnStart;
begin
  if FMesh = nil then
  begin
    FMesh := Resources.LoadMMSMesh('data/models/palm.mms', 0.2);
    FMaterial := TTexturedMaterial.Create(LoadPNGTexture('data/textures/palm.png'));    
    FGroundMesh := Resources.LoadMMSMesh('data/models/palm_ground.mms', 0.2);
    FGroundMaterial := TTexturedMaterial.Create(LoadPNGTexture('data/textures/palm_ground.png'));
  end;
  CreateMesh(FMesh, FMaterial, Vector3(1.6,1.2,1), 1);
  GameObject.AddComponent(TMeshRenderer.CreateMeshRenderer(FGroundMesh, FGroundMaterial));
end;
         
procedure TForest.OnUpdate(const Delta: Double);
begin
  if (GameObject.Enabled <> FActive) then
  begin
    FActive := GameObject.Enabled;
    if (FLife > 0) then
    begin
      FRenderer.Enable := FActive;
    end;
  end;
end;

procedure TForest.OnDestroy;
begin

end;
{$ENDREGION}

end.
