unit uGmBullet;

interface

uses
  zglHeader, uGmData;

type
  TBullet = class
    Pat   : PBulletPat;
    X, Y  : single;
    Ang   : single;
    Dist  : single;

    constructor Create( x1, y1, x2, y2 : single; bPat : PBulletPat );
    destructor Destroy; override;
    procedure Draw;
    procedure Update;
  end;

implementation

//==============================================================================
constructor TBullet.Create( x1, y1, x2, y2 : single; bPat : PBulletPat );
begin
  X     := x1;
  Y     := y1;
  Ang   := m_Angle( x2, y2, x1, y1 );
  Dist  := m_Distance( x1, y1, x2, y2 );
  Pat   := bPat;
end;

//==============================================================================
destructor TBullet.Destroy;
begin

  inherited;
end;

//==============================================================================
procedure TBullet.Draw;
var
  cx, cy, a : single;
begin
  cx := X - Pat.Tex.Width / 2;
  cy := Y - Pat.OffsetY - Pat.Tex.Height / 2;
  a := Ang;
  if Pat.NoRotate then a := 0;
  ssprite2d_Draw( Pat.Tex, cx, cy, Pat.Tex.Width, Pat.Tex.Height, a );
end;

//==============================================================================
procedure TBullet.Update;
begin
  if Dist > 0 then
  begin
    X := X + Cos( Ang * Deg2Rad ) * Pat.Speed;
    Y := Y + Sin( Ang * Deg2Rad ) * Pat.Speed;
    Dist := Dist - Pat.Speed * 1;
  end;
end;

end.
