unit iz_effects;

interface
uses
  windows, OpenGL, iz_types, iz_gfx;

const
  MAX_POINT_COUNT = 2000;

type
  iStar = record
    x,y : float;
    Life : int;
    ThisTickCount,
    LastTickCount : DWORD;
end;

var
  Star: Array [0..MAX_POINT_COUNT - 1] of iStar;
  motion: Array [0..MAX_POINT_COUNT - 1] of iStar;
  Voolkan : bool = false;
  NumStars : int;
  VoolkanX,VoolkanY : float;

procedure CreateVulkanPoints(X,Y,POINT_COUNT : int; delay : byte);
procedure UpdateVulkanPOINT(i : Word; x, y : int; delay : byte; move : bool);
procedure DrawVulkan(x,y : int; POINT_COUNT : int; delay : byte; move : bool);

implementation

procedure CreateVulkanPoints(X,Y,POINT_COUNT : int; delay : byte);
var
  i : int;
begin
  i := 0;
  NumStars := 0;
  while i < POINT_COUNT - 1 do begin
    Star[i].x := X;
    Star[i].y := Y;
    motion[i].x := -random(8)+random(8);
    motion[i].y := -random(7)+random(7);
    Star[i].Life := Random(delay);
    inc(NumStars,Star[i].Life);
    inc(i);
  end;
  Voolkan := true;
end;

procedure UpdateVulkanPOINT(i : Word; x,y : int; delay : byte; move : bool);
begin
  Star[i].ThisTickCount := GetTickCount;

  if Star[i].ThisTickCount - Star[i].LastTickCount > 20 then
  begin
  if move then begin
  Star[i].x := Star[i].x + motion[i].x;
  Star[i].y := Star[i].y + motion[i].y;
  end;
  If (Star[i].Life <= 0) then begin
    Star[i].x := X;
    Star[i].y := Y;
    motion[i].x := 0;
    motion[i].y := 0;
    Star[i].Life := 0;
    Star[i].LastTickCount := GetTickCount;
    end
    else
    begin
    if move then begin
      motion[i].x := motion[i].x+(random(5)/10-random(5)/10);
      motion[i].y := motion[i].y+(random(5)/10-random(5)/10);
      dec(Star[i].Life);
      dec(NumStars);
      if NumStars < 1 then Voolkan := false;
      Star[i].LastTickCount := GetTickCount;
    end;
    end;
  end;
end;

procedure DrawVulkan(x,y : int; POINT_COUNT : int; delay : byte; move : bool);
var
  i : int;
begin
  glBegin(GL_POINTS);
    For i := 0 to POINT_COUNT - 1 do begin
    glColor3f(1-random,1-random,1-random);
      UpdateVulkanPOINT(i,x,y,delay,move);
      glVertex3fv(@Star[i]);
    end;
  glEnd;
end;

end.
