unit ugmppart;

{$mode delphi}

interface

uses
  Classes, uGMPLib, zglHeader;

type

  { TParLine }

  TParLine = class
    x1, x2, y1, y2 : single;
    Alpha : Single;
    DAlpha : Byte;
    constructor Create(A, B : ZPos);
    procedure Update;
    procedure Draw;
  end;

  { TParRect }

  TParRect = class
    Live  : Integer;
    Color : Integer;
    DPos, Size : ZPos;

    AddSz : Single;
    AddAlpha : Single;
    Alpha : Single;
    DAlpha : Byte;
    procedure Update; virtual;
    procedure Draw;
  end;

  { TParFire }

  TParFire = class(TParRect)
    Pos, SizeD2 : ZPos;
    procedure Init;
    constructor Create(P : ZPos);
    procedure Update; override;
  end;

  { TParBlood }

  TParBlood = class(TParFire)
    Move : ZPos;
    constructor Create(P, Dir : ZPos);
    procedure Update; override;
  end;

var
  ListParLine : TList;
  ListParGr,
  ListPar : TList;

implementation
uses
  uGlobal;

{ TParFire }

procedure TParFire.Init;
begin
  Size.SetValue(chsize/2 + random(5), chsize/2 + random(5));

  Live := 1000;
  ListPar.Add(Self);
end;

constructor TParFire.Create(P: ZPos);
begin
  Alpha := 220 + random(11);
  AddAlpha := -10;
  Pos.SetValue(random(10)-5, random(10)-5);
  Pos.AddBy(P);
  Color := cFireColor[random(Length(cFireColor))];
  AddSz := 1.01;
  Init;
end;

procedure TParFire.Update;
begin
  Size.MultiplyBy(AddSz);
  SizeD2 := Size / 2;
  DPos := Pos - SizeD2;
  Alpha := Alpha + AddAlpha;
  if Alpha < 0 then
    Live := 0;
  DAlpha := trunc(Alpha);

  if Live <= 0 then
  begin
    ListPar.Delete(ListPar.IndexOf(Self));
    Self.Free;
  end;

end;

{ TParBlood }

constructor TParBlood.Create(P, Dir: ZPos);
begin
  Alpha := 150 + random(50);
  AddAlpha := -7;

  Pos.SetValue(random(6)-3, random(6)-3);
  Pos.AddBy(P);
  Color := cBloodColor[random(Length(cBloodColor))];
  Move := Dir*0.4;
  AddSz := 1.029;
  Init;
end;

procedure TParBlood.Update;
begin
  Pos.AddBy(Move);
  inherited Update;
  if Alpha < 70 then
  begin
    ListPar.Delete(ListPar.IndexOf(Self));
    ListParGr.Add(Self);
  end;
end;


{ TParRect }

procedure TParRect.Update;
begin

end;

procedure TParRect.Draw;
begin
  pr2d_Rect(DPos.X, DPos.Y, Size.X, Size.Y, Color, DAlpha, PR2D_FILL);
end;


{ TParLine }

constructor TParLine.Create(A, B: ZPos);
begin
  x1 := A.x;
  y1 := A.y;
  x2 := B.x;
  y2 := B.y;
  Alpha := 152;
  DAlpha := 50;

  ListParLine.Add(Self);
end;

procedure TParLine.Update;
begin
  Alpha := Alpha - 8;

  if Alpha < 0 then
  begin
    ListParLine.Delete(ListParLine.IndexOf(Self));
    Self.Free;
  end
  else
    DAlpha:= trunc(Alpha);
end;

procedure TParLine.Draw;
begin
  pr2d_Line(x1, y1, x2, y2, $FFFFFF, DAlpha, PR2D_SMOOTH);
end;

end.

