unit Units.Custom;

interface

uses
  QuadEngine, Vec2f, QuadEngine.Color, GlobalTypes;

type
  TCustomUnit = class
  private
    FIsNeedToKill: Boolean;
    FPosition: TVec2f;
    FViewVector: TVec2f;
    FColor: TQuadColor;
    procedure SetViewVector(AVector: TVec2f);
  protected
    FRadius: Single;
    FSpeed: array[TAnimationType] of Single;
    FHP: Single;
    FMaxHP: Integer;
    FFrame: Single;
    FScale: Single;
    FAngle: Single;
    FFrameSpeed: array[TAnimationType] of Single;
    FAnimation: TAnimationType;
    FDefaultAnimation: TAnimationType;
    function GetSpeed: Single;
    function GetHP: Integer;
  public
    constructor Create(const APosition: TVec2f); virtual;
    procedure Process(const Delta: Double); virtual;
    procedure Draw; virtual;
  published
    procedure Move(AVector: TVec2f);
    procedure Kill;
    procedure Hit; virtual;
    procedure Death(); virtual;
    procedure Damage(AGamage: Single); virtual;
    procedure SetAnimation(AAnimation: TAnimationType);
    property Position: TVec2f read FPosition write FPosition;
    property ViewVector: TVec2f read FViewVector write SetViewVector;
    property Angle: Single read FAngle;
    property Speed: Single read GetSpeed;
    property Color: TQuadColor read FColor write FColor;
    property Radius: Single read FRadius;
    property IsNeedToKill: Boolean read FIsNeedToKill;
    property HP: Integer read GetHP;
    property MaxHP: Integer read FMaxHP;
  end;

implementation

uses
  Resources, Math;

function TCustomUnit.GetHP: Integer;
begin
  Result := Ceil(FHP);
end;

function TCustomUnit.GetSpeed: Single;
begin
  Result := FSpeed[FAnimation];
end;

constructor TCustomUnit.Create(const APosition: TVec2f);
var
  AnimationType: TAnimationType;
begin
  FIsNeedToKill := False;
  FPosition := APosition;
  FAnimation := baStep;
  FDefaultAnimation := baStep;
  for AnimationType := Low(AnimationType) to High(AnimationType) do
  begin
    FFrameSpeed[AnimationType] := 30;
    FSpeed[AnimationType] := 150;
  end;
  FScale := 1;
end;

procedure TCustomUnit.SetAnimation(AAnimation: TAnimationType);
begin
  FAnimation := AAnimation;
  FFrame := 0;
end;

procedure TCustomUnit.Process(const Delta: Double);
begin

end;

procedure TCustomUnit.Damage(AGamage: Single);
begin
  FHP := FHP - AGamage;
  if FHP <= 0 then
  begin
    Death;
    Kill;
  end
  else
    Hit;
end;

procedure TCustomUnit.Draw;
begin
  TGlobals.QuadRender.SetBlendMode(qbmSrcAlpha);
  TGlobals.QuadRender.DrawCircle(Position, Radius, 0, Color);
  TGlobals.QuadRender.DrawQuadLine(Position, Position + ViewVector.Normalize * Radius, 1, 1, $FFFF0000, $FFFF0000);
end;

procedure TCustomUnit.Move(AVector: TVec2f);
begin
  FPosition := FPosition + AVector;
end;

procedure TCustomUnit.Kill;
begin
  FIsNeedToKill := True;
end;

procedure TCustomUnit.SetViewVector(AVector: TVec2f);
begin
  FViewVector := AVector;
  FAngle := FViewVector.Angle;
end;

procedure TCustomUnit.Hit;
begin

end;

procedure TCustomUnit.Death();
begin

end;

end.
