unit uBoom;

interface
uses
  zglHeader, uMaterials, uList, LexUtils,
  uBomb, uZepelin;

type
  TBoomList = class(TList)
    Bombs : TBombList;
    Zepelins : TZepelinList;
    constructor Create(const pBombs : TBombList; pZepelins : TZepelinList);  overload;
    function  Add(E : TBoomList) : TList; overload;
  end;

  TBoom = class(TBoomList)
    W, H : Integer;
    pX, pY, cX, cY, sW, sH, dW, dH : Single;
    Alpha, dAlpha : byte;
    constructor Create(const X, Y : Integer); overload;
    procedure Init; override;
    procedure Draw; override;
    procedure Update; override;
  end;

implementation
uses
  uConst;
{ TBoomList }

function TBoomList.Add(E: TBoomList): TList;
begin
  E.Bombs := (Root as TBoomList).Bombs;
  E.Zepelins := (Root as TBoomList).Zepelins;
  Result := inherited Add(E);
end;

constructor TBoomList.Create(const pBombs: TBombList; pZepelins : TZepelinList);
begin
  inherited Create;
  Bombs := pBombs;
  Zepelins := pZepelins;
end;

{ TBoom }

constructor TBoom.Create(const X, Y: Integer);
begin
  W := 128;
  H := 128;
  cX := X;
  cY := Y;
  sW := 16;
  sH := 16;
  dW := 2;
  dH := 2;
  Alpha := 15;
  dAlpha := 5;

  pX := cX - dW / 2;
  pY := cY - dH / 2;
end;

procedure TBoom.Init;
begin
end;

procedure TBoom.Draw;
begin
  ssprite2d_Draw(m_bam, pX, pY, sW, sH, 0, Alpha);
  Next.Draw;
end;

procedure TBoom.Update;
begin
  Next.Update;

  if (Alpha < 5) then
    Del
  else
  begin
    Alpha := Alpha + dAlpha;
    if Alpha > 225 then
      dAlpha := -dAlpha;

    sW := sW + dW;
    sH := sH + dH;

    pX := cX - sW / 2;
    pY := cY - sH / 2;

    (Bombs.Next as TBombList).InBoom(cX, cY, sW * 0.6, pX, pY, pX + sW, pY + sH);
    (Zepelins.Next as TZepelinList).InBoom(cX, cY, pX, pY, pX + sW, pY + sH);
  end;
end;


end.
