unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ExtCtrls, Math, StdCtrls, MPlayer;

type
  TForm1 = class(TForm)
    PaintBox1: TPaintBox;
    Timer1: TTimer;
    Label1: TLabel;
    Edit1: TEdit;
    MediaPlayer1: TMediaPlayer;
    procedure PaintBox1MouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
    procedure PaintBox1DblClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure Timer1Timer(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

  TVec = record
    X, Y: double;
  end;

  TBall = record
    X, Y, vX, vY: double;
    color, r: integer;
  end;

  TIntArr = array of integer;
  T2DIntArr = array of TIntArr;

  TCharArr = array of char;
  T2DCharArr = array of TCharArr;

  TAimFunction = function(p: TPoint; minspeed, maxspeed, dev: double): TVec;

var
  Form1: TForm1;
  Player: TPoint;
  level, step, maxlevel: Integer;
  Balls: array of TBall;
  lost, nomusicyet: boolean;

implementation

{$R *.dfm}

function vec(X, Y: double): TVec; overload;
begin
  result.X:= X;
  result.Y:= Y;
end;

function vec(X: TPoint): TVec; overload;
begin
  result:= vec(X.X, X.Y);
end;

function Arr(a: array of integer): TIntArr;
var i: integer;
begin
  setlength(result, length(a));
  for i:= 0 to high(a) do begin
    result[i]:= a[i];
  end;
end;

function CArr(a: array of char): TCharArr;
var i: integer;
begin
  setlength(result, length(a));
  for i:= 0 to high(a) do begin
    result[i]:= a[i];
  end;
end;

procedure PlayMusic(fileName: string);
var f: string;
begin
  f:= ExtractFilePath(Application.ExeName) + 'music\' + fileName;
  nomusicyet:= false;
  with Form1.MediaPlayer1 do begin
    FileName:= f;
    Open;
    Play;
  end;
end;

function Gray(c: integer): integer;
begin
  result:= RGB(c, c, c);
end;

function toPolar(X: TVec): TVec;
begin
  result.X:= sqrt(sqr(X.X)+sqr(X.Y));
  if x.x>0 then result.Y:= arctan(x.y/x.x)
  else if x.x<0 then result.Y:= Pi+arctan(x.y/x.x)
  else if x.y>0 then result.Y:= Pi/2
  else result.Y:= -Pi/2;
end;

function toKarthesic(x: TVec): TVec;
begin
  result:= vec(X.X*cos(x.Y), X.X*sin(x.Y));
end;

function GetEdge(a: integer): TPoint;
begin
  with Form1.PaintBox1 do begin
    if a<Width * 2 then begin
      if a<Width then begin
        result:= Point(a, 0);
      end else begin
        result:= Point(a - Width, Height);
      end;
    end else begin
      if a<Height + 2 * Width then begin
        result:= Point(0, a - 2*Width);
      end else begin
        result:= Point(Width, a - 2*Width - Height);
      end;
    end;
  end;
end;

function GetNormalVel(a: TPoint; minSpeed, MaxSpeed, dev: double): TVec;
var speed: double;
begin
  speed:= random*(MaxSpeed - minSpeed) + minspeed;
  if (a.Y = 0) then begin
    result:= vec(random*(2 * dev) - dev, speed);
  end else if a.Y = Form1.PaintBox1.Height then begin
    result:= vec(random*(2 * dev) - dev, -speed);
  end else if (a.X = 0) then begin
    result:= vec(speed, random*(2 * dev) - dev);
  end else if a.X = Form1.PaintBox1.Width then begin
    result:= vec(-speed, random*(2 * dev) - dev);
  end;
end;

function AimAtPlayer(p: TPoint; minSpeed, MaxSpeed, dev: double): TVec;
var speed, x, y, a: double;
begin
  speed:= random*(MaxSpeed - minSpeed) + minspeed;
  x:= Player.X-P.X;
  y:= Player.Y-p.Y;
  if x>0 then a:= arctan(y/x)
  else if x<0 then a:= Pi+arctan(y/x)
  else if y>0 then a:= Pi/2
  else a:= -Pi/2;
  a:= a + random*(2 * dev) - dev;
  x:= speed*cos(a);
  y:= speed*sin(a);
  Result:= vec(x, y);
end;

function DirectionalAim(p: TPoint; x, y, dummy: double): TVec;
begin
  result:= vec(x, y);
end;

function Converge(p: TPoint; x, y, time: double): TVec;
begin
  result:= vec(p);
  result.X:= (x - result.X)/time;
  result.Y:= (y - result.Y)/time;

end;

procedure SpawnBall(pos, vel: TVec; acolor, rad: integer);
begin
  setlength(Balls, length(Balls) + 1);
  with Balls[high(Balls)] do begin
    X:= pos.X;
    Y:= pos.Y;
    vx:= vel.x;
    vy:= vel.y;
    color:= acolor;
    r:= rad;
  end;
end;

procedure SpawnCircle(pos: TVec; speed: double; acolor, rad, count: integer; rotation: double = 0);
var i: integer;
    a: double;
    v: TVec;
begin
  for i:= 0 to count-1 do begin
    a:= i*2*Pi/count + rotation;
    v:= vec(cos(a) * speed, sin(a) * speed);
    SpawnBall(pos, v, acolor, rad);
  end;
end;

procedure SpawnLine(p1, p2: TPoint; acolor, rad, count: integer; aim: TAimFunction; minspeed, maxspeed, dev: double);
var i: integer;
    p: TPoint;
    v: Tvec;
begin
  for i:= 0 to count - 1 do begin
    p:= Point(round((i*p2.x + (count-1-i)*p1.x)/(count-1)),round((i*p2.y + (count-1-i)*p1.y)/(count-1)));
    v:= aim(p, minspeed, maxspeed, dev);
    SpawnBall(vec(p), v, acolor, rad);
  end;
end;

procedure SpawnGrayLine(p1, p2: TPoint; baseColor, colors, rad, count: integer; aim:TAimFunction; minspeed, maxspeed, dev: double);
var i, c: integer;
    p: TPoint;
    v: TVec;
begin
  for i:= 0 to count - 1 do begin
    p:= Point(round((i*p2.x + (count-1-i)*p1.x)/(count-1)),round((i*p2.y + (count-1-i)*p1.y)/(count-1)));
    v:= aim(p, minspeed, maxspeed, dev);
    c:= baseColor + floor(i / count * colors) mod 16;
    c:= c+c*256+c*sqr(256);
    SpawnBall(vec(p), v, c, rad);
  end;
end;

procedure SpawnOpenCircle(m: TVec; dist, start, stop: double; acolor, rad, count: integer;
                          aim: TAimFunction; minspeed, maxspeed, dev: double);
var i: integer;
    a: double;
    v, p: TVec;
begin
  for i:= 0 to count - 1 do begin
    a:= (i/count)*(stop-start) + start;
    p:= vec(m.X + cos(a)*dist, m.Y + sin(a)*dist);
    v:= aim(Point(round(P.X), round(P.Y)), minspeed, maxspeed, dev);
    SpawnBall(p, v, acolor, rad);
  end;
end;

procedure SpawnTurning(p: TVec; count: integer; minRad, maxRad, minPhi, maxPhi, minSp, maxSp, r: integer;
                       aim: TAimFunction; minspeed, maxspeed, dev: double);
var i: integer;
    rad, phi, sp: integer;
    v: TVec;
begin
  for i:= 0 to count - 1 do begin
    rad:= round(minRad*(i/count) + maxRad*((count-i)/count)) mod 255;
    phi:= round(minPhi*(i/count) + maxPhi*((count-i)/count)) mod 255;
    sp:= round(minSp*(i/count) + maxSp*((count-i)/count)) mod 255;
    v:= aim(Point(round(P.X), round(P.Y)), minspeed, maxspeed, dev);
    SpawnBall(p, v, rad+phi*256+sp*sqr(256), r);
  end;
end;

procedure UpperCircleBarrier1(m, vel: TVec; size, space: double);
begin
  SpawnOpenCircle(m, size, Pi, 2*Pi, clred, 3, round(size / 5), DirectionalAim, vel.X, vel.Y, 0);
  SpawnOpenCircle(m, size-space, 0, 2*Pi, clred, 3, round((size-space)/2.5), DirectionalAim, vel.X, vel.Y, 0);
  SpawnLine(Point(round(m.X), round(m.Y + size-space)), Point(round(m.X), 600), clred, 3, 15, DirectionalAim, vel.X, vel.Y, 0);
end;

procedure LowerCircleBarrier1(m, vel: TVec; size, space: double);
begin
  SpawnOpenCircle(m, size, 0, Pi, clred, 3, round(size / 5), DirectionalAim, vel.X, vel.Y, 0);
  SpawnOpenCircle(m, size-space, 0, 2*Pi, clred, 3, round((size-space)/2.5), DirectionalAim, vel.X, vel.Y, 0);
  SpawnLine(Point(round(m.X), round(m.Y - size + space)), Point(round(m.X), 0), clred, 3, 15, DirectionalAim, vel.X, vel.Y, 0);
end;

procedure UpperBoxBarrier(m, vel: TPoint; size, space: integer);
begin
  SpawnLine(Point(m.X-size, m.Y), Point(m.X-size, m.Y-size), clred, 3, size div 10, DirectionalAim, vel.X, vel.Y, 0);
  SpawnLine(Point(m.X+size, m.Y-size), Point(m.X-size, m.Y-size), clred, 3, size div 5, DirectionalAim, vel.X, vel.Y, 0);
  SpawnLine(Point(m.X+size, m.Y), Point(m.X+size, m.Y-size), clred, 3, size div 10, DirectionalAim, vel.X, vel.Y, 0);

  SpawnLine(Point(m.X-size+space, m.Y+size-space), Point(m.X-size+space, m.Y-size+space), clred, 3, (size-space) div 5, DirectionalAim, vel.X, vel.Y, 0);
  SpawnLine(Point(m.X+size-space, m.Y-size+space), Point(m.X-size+space, m.Y-size+space), clred, 3, (size-space) div 5, DirectionalAim, vel.X, vel.Y, 0);
  SpawnLine(Point(m.X+size-space, m.Y+size-space), Point(m.X+size-space, m.Y-size+space), clred, 3, (size-space) div 5, DirectionalAim, vel.X, vel.Y, 0);
  SpawnLine(Point(m.X+size-space, m.Y+size-space), Point(m.X-size+space, m.Y+size-space), clred, 3, (size-space) div 5, DirectionalAim, vel.X, vel.Y, 0);

  SpawnLine(Point(round(m.X), round(m.Y + size-space)), Point(round(m.X), 600), clred, 3, 15, DirectionalAim, vel.X, vel.Y, 0);
end;

procedure LowerBoxBarrier(m, vel: TPoint; size, space: integer);
begin
  SpawnLine(Point(m.X-size, m.Y), Point(m.X-size, m.Y+size), clred, 3, size div 10, DirectionalAim, vel.X, vel.Y, 0);
  SpawnLine(Point(m.X+size, m.Y+size), Point(m.X-size, m.Y+size), clred, 3, size div 5, DirectionalAim, vel.X, vel.Y, 0);
  SpawnLine(Point(m.X+size, m.Y), Point(m.X+size, m.Y+size), clred, 3, size div 10, DirectionalAim, vel.X, vel.Y, 0);

  SpawnLine(Point(m.X-size+space, m.Y+size-space), Point(m.X-size+space, m.Y-size+space), clred, 3, (size-space) div 5, DirectionalAim, vel.X, vel.Y, 0);
  SpawnLine(Point(m.X+size-space, m.Y-size+space), Point(m.X-size+space, m.Y-size+space), clred, 3, (size-space) div 5, DirectionalAim, vel.X, vel.Y, 0);
  SpawnLine(Point(m.X+size-space, m.Y+size-space), Point(m.X+size-space, m.Y-size+space), clred, 3, (size-space) div 5, DirectionalAim, vel.X, vel.Y, 0);
  SpawnLine(Point(m.X+size-space, m.Y+size-space), Point(m.X-size+space, m.Y+size-space), clred, 3, (size-space) div 5, DirectionalAim, vel.X, vel.Y, 0);

  SpawnLine(Point(round(m.X), round(m.Y - size+space)), Point(round(m.X), 0), clred, 3, 15, DirectionalAim, vel.X, vel.Y, 0);
end;

procedure SpawnGrid(maze: T2DIntArr; Vel: TVec);
var i, j, s: integer;
    p: TPoint;
begin
  for i:= 0 to high(maze) do
    for j:= 0 to high(maze[i]) do begin
      s:= Form1.PaintBox1.Height div length(maze);
      p:= Point(round(j*s + Form1.PaintBox1.Width), round(i*s));
      if maze[i, j] and 1 > 0 then SpawnLine(p, Point(p.X + s, p.Y), clred, 3, s div 10, DirectionalAim, Vel.X, Vel.Y, 0);
      if maze[i, j] and 2 > 0 then SpawnLine(p, Point(p.X, p.Y + s), clred, 3, s div 10, DirectionalAim, Vel.X, Vel.Y, 0);
    end;
end;

procedure SpawnBlockMaze(maze: T2DIntArr; Vel: TVec);
var i, j, s: integer;
    p: TPoint;
begin
  for i:= 0 to high(maze) do
    for j:= 0 to high(maze[i]) do begin
      s:= Form1.PaintBox1.Height div length(maze);
      p:= Point(round(j*s + Form1.PaintBox1.Width), round(i*s));
      if maze[i, j] > 0 then begin
        SpawnLine(p, Point(p.X + s, p.Y), clred, 3, s div 10, DirectionalAim, Vel.X, Vel.Y, 0);
        SpawnLine(p, Point(p.X, p.Y + s), clred, 3, s div 10, DirectionalAim, Vel.X, Vel.Y, 0);
        SpawnLine(Point(p.X + s, p.Y), Point(p.X + s, p.Y + s), clred, 3, s div 10, DirectionalAim, Vel.X, Vel.Y, 0);
        SpawnLine(Point(p.X, p.Y + s), Point(p.X + s, p.Y + s), clred, 3, s div 10, DirectionalAim, Vel.X, Vel.Y, 0);
      end;
    end;
end;

procedure SpawnCharMaze(maze: T2DCharArr; Vel: TVec);
var i, j, s: integer;
    p: TPoint;
begin
  for i:= 0 to high(maze) do
    for j:= 0 to high(maze[i]) do begin
      s:= Form1.PaintBox1.Height div length(maze);
      if Vel.X < 0 then p:= Point(round(j*s + Form1.PaintBox1.Width), round(i*s))
      else p:= Point(round(j*s - s*length(maze[0])), round(i*s));
      case Maze[i, j] of
        '/': begin
          SpawnLine(Point(p.X + s, p.Y), Point(p.X, p.Y + s), clred, 3, s div 10, DirectionalAim, Vel.X, Vel.Y, 0);
        end;
        '\': begin
          SpawnLine(p, Point(p.X + s, p.Y + s), clred, 3, s div 10, DirectionalAim, Vel.X, Vel.Y, 0);
        end;
        '_': begin
          SpawnLine(Point(p.X, p.Y+s), Point(p.X+s, p.Y+s), clred, 3, s div 10, DirectionalAim, Vel.X, Vel.Y, 0);
        end;
        '^': begin
          SpawnLine(p, Point(p.X + s, p.Y), clred, 3, s div 10, DirectionalAim, Vel.X, Vel.Y, 0);
        end;
        '|': begin
          SpawnLine(p, Point(p.X, p.Y + s), clred, 3, s div 10, DirectionalAim, Vel.X, Vel.Y, 0);
          SpawnLine(Point(p.X + s, p.Y), Point(p.X+s, p.Y+s), clred, 3, s div 10, DirectionalAim, Vel.X, Vel.Y, 0);
        end;
      end;
    end;
end;

procedure SpawnStrMaze(maze: array of string; Vel: TVec);
var i, j, s: integer;
    p: TPoint;
begin
  for i:= 0 to high(maze) do
    for j:= 1 to length(maze[i]) do begin
      s:= Form1.PaintBox1.Height div length(maze);
      if Vel.X < 0 then p:= Point(round((j-1)*s + Form1.PaintBox1.Width), round(i*s))
      else p:= Point(round((j-1)*s - s*length(maze[0])), round(i*s));
      case Maze[i, j] of
        '/': begin
          SpawnLine(Point(p.X + s, p.Y), Point(p.X, p.Y + s), clred, 3, s div 10, DirectionalAim, Vel.X, Vel.Y, 0);
        end;
        '\': begin
          SpawnLine(p, Point(p.X + s, p.Y + s), clred, 3, s div 10, DirectionalAim, Vel.X, Vel.Y, 0);
        end;
        '_': begin
          SpawnLine(Point(p.X, p.Y+s), Point(p.X+s, p.Y+s), clred, 3, s div 10, DirectionalAim, Vel.X, Vel.Y, 0);
        end;
        '^': begin
          SpawnLine(p, Point(p.X + s, p.Y), clred, 3, s div 10, DirectionalAim, Vel.X, Vel.Y, 0);
        end;
        '|': begin
          SpawnLine(p, Point(p.X, p.Y + s), clred, 3, s div 10, DirectionalAim, Vel.X, Vel.Y, 0);
          SpawnLine(Point(p.X + s, p.Y), Point(p.X+s, p.Y+s), clred, 3, s div 10, DirectionalAim, Vel.X, Vel.Y, 0);
        end;
        '=': begin
          SpawnLine(Point(p.X, p.Y+s), Point(p.X+s, p.Y+s), clred, 3, s div 10, DirectionalAim, Vel.X, Vel.Y, 0);
          SpawnLine(p, Point(p.X + s, p.Y), clred, 3, s div 10, DirectionalAim, Vel.X, Vel.Y, 0);
        end;
        'D': begin
          SpawnLine(p, Point(p.X, p.Y + s), clred, 3, s div 10, DirectionalAim, Vel.X, Vel.Y, 0);
        end;
        'a': begin
          SpawnLine(Point(p.X + s, p.Y), Point(p.X+s, p.Y+s), clred, 3, s div 10, DirectionalAim, Vel.X, Vel.Y, 0);
        end;
      end;
    end;
end;

procedure killBall(index: integer);
var i: integer;
begin
  for i:= index to high(Balls) - 1 do begin
    Balls[i]:= Balls[i+1];
  end;
  setLength(Balls, length(Balls) - 1);
end;

procedure update;
var i, j: integer;
    v, d: TVec;
    a, speed, rad: double;
begin
  for i:= 0 to high(Balls) do begin
    with Balls[i] do begin
      X:= X + vX;
      Y:= Y + vY;
      if color = clblue then begin
        v:= ToPolar(vec(vx, vy));
        d:= ToPolar(vec(Player.X-X, Player.Y-Y));
        a:= d.Y-v.Y;
        if a>Pi then a:= a-2*Pi;
        if a<-Pi then a:= a+2*Pi;
        if a>0 then v.Y:= v.Y+0.005*(r-2)
        else if a<0 then v.Y:= v.Y-0.005*(r-2);
        v:= ToKarthesic(v);
        vx:= v.X;
        vy:= v.Y;
      end;
      if color = $ff00ff then begin
        v:= ToPolar(vec(vx, vy));
        d:= ToPolar(vec(Player.X-X, Player.Y-Y));
        a:= d.Y-v.Y;
        if a>Pi then a:= a-2*Pi;
        if a<-Pi then a:= a+2*Pi;
        d:= ToKarthesic(d);
        vx:= vx+0.0025*abs(a)*(r-2)*d.X;
        vy:= vy+0.0025*abs(a)*(r-2)*d.Y;
      end;
      if (color mod 256 = (color div 256) mod 256) and (color mod 256 = (color div sqr(256)) mod 256) then begin
        a:= (color mod 16)/8*pi;
        if (color mod 256) div 16 = 15 then begin
          Y:= Y + sin(step/10 + a) * (r-2)*3;
        end else if (color mod 256) div 16 = 14 then begin
          X:= X + sin(step/10 + a) * (r-2)*3;
        end else if (color mod 256) div 16 = 13 then begin
          Y:= Y + sin(step/3 + a) * (r-2)*3;
        end else if (color mod 256) div 16 = 12 then begin
          X:= X + sin(step/3 + a) * (r-2)*3;
        end else if (color mod 256) div 16 = 11 then begin
          Y:= Y + sin(step/10 + a) * (r-2)*3;
          X:= X + sin(step/10 + a + Pi/2) * (r-2)*3;
        end else if (color mod 256) div 16 = 10 then begin
          Y:= Y + sin(step/10 + a) * (r-2)*3;
          X:= X - sin(step/10 + a + Pi/2) * (r-2)*3;
        end else if (color mod 256) div 16 = 9 then begin
          if color mod 16 = 15 then begin
            X:= X + sin(step/10 + Pi/2) * 20;
          end else if color mod 16 = 14 then begin
            X:= X + sin(step/10 + Pi/2) * 20;
            if step/10>Pi/2 then Y:= Y - sin(step/10) * 20;
          end;
        end
      end;
    end;
  end;
  i:= 0;
  while i<= high(Balls) do begin
    with Balls[i] do begin
      if (X<0) and (vX<0) or (X>Form1.PaintBox1.Width) and (vX>0) or (Y<0) and (vY<0) or (Y>Form1.PaintBox1.Height) and (vY>0) then begin
        speed:= sqrt(sqr(vx)+sqr(vy));
        if (color = clred) or (color = clblue) or (color = $fe00fe) then begin
          KillBall(i);
          continue;
        end;
        if color = cllime then if r>3 then begin
          if (X<0) or (X>Form1.PaintBox1.Width) then vX:= -vX;
          if (Y<0) or (Y>Form1.PaintBox1.Height) then vY:= -vY;
          dec(r);
          inc(i);
          continue;
        end else KillBall(i);
        if color = claqua then if r>3 then begin
          v:= AimAtPlayer(Point(round(x), round(y)), speed, speed, 0);
          vx:= v.X;
          vy:= v.Y;
          dec(r);
          inc(i);
          continue;
        end else KillBall(i);
        if color = clyellow then begin
          SpawnCircle(vec(x, y), speed, clred, 3, 5*r);
          KillBall(i);
          continue;
        end;
        if color = $008080 then begin
          for j:= 0 to 10*(r-2) do SpawnBall(vec(x, y), AimAtPlayer(Point(round(x), round(y)), speed, 1.5*speed, Pi/2), clred, 3);
          KillBall(i);
          continue;
        end;
        if color = $ff00ff then begin
          KillBall(i);
          continue;
        end;
        if (color mod 256 = (color div 256) mod 256) and (color mod 256 = (color div sqr(256)) mod 256) then begin
          KillBall(i);
          continue;
        end;
        {else}
        rad:= (255 - (color mod 256)) * 10;
        if (X<-rad) or (X > Form1.PaintBox1.Width + rad) or (Y < -rad) or (Y > Form1.PaintBox1.Height + rad) then begin
          KillBall(i);
          continue;
        end else inc(i);
      end else inc(i);
    end;
  end;
end;

procedure checkCollision;
var i: integer;
    rad, phi, sp: double;

    procedure Lose;
    begin
      lost:= true;
      PlayMusic('Oppressive Gloom.mp3');
      nomusicyet:= true;
      maxlevel:= max(level, maxlevel);
      Form1.Edit1.Text:= IntToStr(level);
    end;
begin
  for i:= 0 to high(Balls) do
    with Balls[i] do begin
      if (color mod 256 < 255) and ((color div 256) mod 256 <255) and ((color div sqr(256)) mod 256 < 255)
         and ( (color mod 256 <> (color div 256) mod 256) or (color mod 256 <> (color div sqr(256)) mod 256) ) then begin
        rad:= (255 - (color mod 256)) * 10;
        phi:= ((color div 256) mod 256) / 64 * Pi;
        sp:= ((256-64) - ((color div sqr(256)) mod 256)) / 640;
        if (sqr(X+rad*cos(phi+step*sp) - Player.X) + sqr(Y+rad*sin(phi+step*sp) - Player.Y)  < sqr(r+10)) and (r>0) then begin
          lose;
        end;
      end;
      if (sqr(X - Player.X) + sqr(Y - Player.Y) < sqr(r + 10)) and (r>0) then begin
        lose;
        exit;
      end;
    end;
end;

procedure Draw;
var bmp: TBitMap;
    i: integer;
    rad, phi, sp: double;
begin
  bmp:= TBitMap.Create;
  with bmp do
  begin
    width:= Form1.PaintBox1.width;
    height:= Form1.PaintBox1.height;
    with canvas do
    begin
      pen.Color:= clblack;
      brush.Color:= clblack;
      rectangle(0,0,width, height);
      pen.Color:= clwhite;
      brush.Color:= clwhite;
      if lost then begin
        Font.Height:= 150;
        if level>0 then TextOut(250, 250, 'You Lose')
        else TextOut(50, 250, 'DblClick to start');
      end;
      if Step<0 then begin
        Font.Height:= 150;
        TextOut(50, 250, 'Level: ' + intToStr(level));
      end;
      pen.Color:= clgreen;
      brush.Color:= clgreen;
      ellipse(Player.X - 10, Player.Y - 10, Player.X + 10, Player.Y + 10);
      for i:= 0 to high(Balls) do With Balls[i] do begin
        if (X > -r) and (X < Width + r)
        and (Y > -r) and (Y < Height + r) then
        begin
          pen.Color:= Balls[i].color;
          brush.Color:= Balls[i].color;
          ellipse(round(X) - r, round(Y) - r, round(X) + r, round(Y) + r);
        end;
        if (color mod 256 < 255) and ((color div 256) mod 256 <255) and ((color div sqr(256)) mod 256 < 255)
           and ( (color mod 256 <> (color div 256) mod 256) or (color mod 256 <> (color div sqr(256)) mod 256) ) then begin
          rad:= (255 - (color mod 256)) * 10;
          phi:= ((color div 256) mod 256) / 64 * Pi;
          sp:= ((256-64) - ((color div sqr(256)) mod 256)) / 640;
          pen.Color:= Balls[i].color;
          brush.Color:= Balls[i].color;
          ellipse(round(X + rad*cos(phi+step*sp)) - r, round(Y + rad*sin(phi+step*sp)) - r,
                round(X + rad*cos(phi+step*sp)) + r, round(Y + rad*sin(phi+step*sp)) + r);
        end;
      end;
    end;
  end;
  Form1.PaintBox1.Canvas.Draw(0, 0, bmp);
  bmp.Free;
  if not lost then Form1.Caption:= IntToStr(Step);
end;

procedure CheckIntermediateCollision(X, Y: Integer);
var a, b: integer;
begin
  if sqr(X-Player.X) + sqr(Y-Player.Y) > 4 then begin
    a:= (X+Player.X) div 2;
    b:= (Y+Player.Y) div 2;
    CheckIntermediateCollision(a, b);
    CheckIntermediateCollision(X, Y);
  end else begin
    Player.X:= X;
    Player.Y:= Y;
    if not lost then CheckCollision;
  end;
end;

procedure TForm1.PaintBox1MouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
begin
  {Player.X:= X;
  Player.Y:= Y;
  //Draw;
  if not lost then CheckCollision;}
  CheckIntermediateCollision(X, Y);
end;

procedure TForm1.PaintBox1DblClick(Sender: TObject);
var a: integer;
begin
  if lost then begin
    if not TryStrToInt(edit1.Text, a) then begin
      ShowMessage('Es gibt nur Ganzzahlige Levels');
      exit;
    end;
    lost:= false;
    level:= a;
    step:= -30;
    setlength(balls, 0);
  end;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  level:= 0;
  step:= 0;
  lost:= true;
  nomusicyet:= true;
  maxlevel:= 1;
  randomize;
end;

procedure Script;
var w, h: integer;
    center, center2: TVec;

  procedure NextLevel;
  begin
    inc(level);
    step:= -30;
    setlength(balls, 0);
  end;

var i, cl: integer;
    p: TPoint;
    v: TVec;
    maze: T2DIntArr;
    cmaze: T2DCharArr;
begin
  w:= Form1.PaintBox1.Width;
  h:= Form1.PaintBox1.Height;
  center:= vec(500, 300);
  case level of
    1: begin
      if step = -25 then PlayMusic('Rising.mp3');
      if step>=0 then begin
        if step mod 25 = 0 then begin
          for i:= 0 to 5 + step div 500 do begin
            p:= GetEdge(random(2*(w + h)));
            v:= GetNormalVel(p, 2, 4, 2);
            SpawnBall(vec(p), v, clred, 3);
          end;
        end;
      end;
      if step = 1500 then NextLevel;
    end;
    2: begin
      case step of
        -25: PlayMusic('Take the Lead.mp3');
        0, 80, 200, 350, 370, 390, 550, 590: SpawnLine(Point(0, 0), Point(w, 0), clred, 3, 12, DirectionalAim, 0, 5, 0);
        50, 100, 360, 380, 400, 570, 600: SpawnLine(Point(-40, 0), Point(w+40, 0), clred, 3, 13, DirectionalAim, 0, 5, 0);
        150: SpawnLine(Point(0, 0), Point(w, 0), clred, 3, 25, DirectionalAim, 0, 5, 0);
        180: SpawnLine(Point(-20, 0), Point(w + 20, 0), clred, 3, 26, DirectionalAim, 0, 5, 0);
        250: SpawnLine(Point(w, 0), Point(w, h), clred, 3, 15, DirectionalAim, -5, 0, 0);
        280: SpawnLine(Point(w, -20), Point(w, h+20), clred, 3, 16, DirectionalAim, -5, 0, 0);
        450, 500: SpawnLine(Point(w, 0), Point(w, h), clred, 3, 7, DirectionalAim, -5, 0, 0);
        475, 520: SpawnLine(Point(w, -40), Point(w, h+40), clred, 3, 8, DirectionalAim, -5, 0, 0);
        700, 780, 850: SpawnLine(Point(0, 0), Point(w, 0), clred, 3, 50, GetNormalVel, 0, 4, 2);
      end;
      if step = 1200 then NextLevel;
    end;
    3: begin
      if step = -25 then PlayMusic('Rising.mp3');
      if step>=0 then begin
        if step mod 25 = 0 then begin
         for i:= 0 to 7 + step div 500 do begin
            p:= GetEdge(random(2*(w + h)));
            v:= AimAtPlayer(p, 1.5, 3, 0.1);
            SpawnBall(vec(p), v, clred, 3);
          end;
        end;
      end;
      if step = 1500 then NextLevel;
    end;
    4: begin
      case step of
        -25: begin
          SpawnLine(Point(0, 0), Point(w, 0), clred, 3, 100, DirectionalAim, 0, 0, 0);
          SpawnLine(Point(0, h), Point(w, h), clred, 3, 100, DirectionalAim, 0, 0, 0);
          PlayMusic('Mistake the Getaway.mp3');
        end;
        0, 220, 310, 940, 960: begin
          SpawnLine(Point(w, 0), Point(w, 250), clred, 3, 25, DirectionalAim, -5, 0, 0);
          SpawnLine(Point(w, h), Point(w, 350), clred, 3, 25, DirectionalAim, -5, 0, 0);
        end;
        50, 140, 280, 1000, 1020: begin
          SpawnLine(Point(w, 0), Point(w, h-100), clred, 3, 50, DirectionalAim, -5, 0, 0);
        end;
        100, 180, 250, 1060, 1080: begin
          SpawnLine(Point(w, 100), Point(w, h), clred, 3, 50, DirectionalAim, -5, 0, 0);
        end;
        350, 640, 1120, 1260: begin
          SpawnLine(Point(w, 100), Point(w, h), clred, 3, 50, DirectionalAim, -5, 0, 0);
          SpawnLine(Point(w, 100), Point(w + 500, h), clred, 3, 50, DirectionalAim, -5, 0, 0);
          SpawnLine(Point(w + 600, 0), Point(w + 600, h - 100), clred, 3, 50, DirectionalAim, -5, 0, 0);
          SpawnLine(Point(w + 100, 0), Point(w + 600, h - 100), clred, 3, 50, DirectionalAim, -5, 0, 0);
        end;
        500, 780, 1400: begin
          SpawnLine(Point(w, 200), Point(w, h), clred, 3, 40, DirectionalAim, -5, 0, 0);
          SpawnLine(Point(w, 200), Point(w + 300, 200), clred, 3, 30, DirectionalAim, -5, 0, 0);
          SpawnLine(Point(w + 500, 0), Point(w + 500, h - 200), clred, 3, 40, DirectionalAim, -5, 0, 0);
          SpawnLine(Point(w + 200, h - 200), Point(w + 500, h - 200), clred, 3, 30, DirectionalAim, -5, 0, 0);
        end;
      end;
      if step = 1600 then NextLevel;
    end;
    5: begin
      case Step of
        -25: PlayMusic('11-Titan.mp3');
        0: SpawnBall(vec(500, 700), vec(0, -4), clred, 50);
        100: Balls[0].vY:= 0;
        160..200, 250..300, 440..500, 630..700, 900..950: SpawnBall(center, AimAtPlayer(Point(500, 300), 6, 9, 0.1), clred, 3);
        840..899, 1450..1500: SpawnBall(center, AimAtPlayer(Point(500, 300), 6, 9, 0.5), clred, 3);
        350..400, 740..800, 970..1000, 1380..1440: SpawnCircle(center, 5, clred, 3, 6, step/50);
        550, 570, 590, 1330, 1350, 1370: SpawnCircle(center, 4, clred, 3, 30, step);
        1010, 1030, 1050, 1110, 1150, 1180, 1510, 1520, 1530: SpawnBall(center, vec(0, -6), clred, 10);
        1060, 1080, 1100: SpawnLine(Point(0, 0), Point(w, 0), clred, 3, 100, AimAtPlayer, 3, 3, 0);
        1160, 1200, 1230: SpawnLine(Point(0, 0), Point(w, 0), clred, 3, 80, GetNormalVel, 4, 8, 3);
        1560, 1570, 1580: SpawnLine(Point(0, 0), Point(w, 0), clred, 3, 50, GetNormalVel, 4, 8, 3);
        1701..1800: begin
          if step mod 2 = 0 then dec(Balls[0].r);
          SpawnBall(center, AimAtPlayer(Point(500, 300), 6, 9, Pi), clred, 3);
        end;
      end;
      if step = 1850 then NextLevel;
    end;
    6: begin
      if step = -25 then PlayMusic('Rising.mp3');
      if step>=0 then begin
        if step mod 30 = 0 then begin
         for i:= 0 to 3 + step div 500 do begin
            p:= GetEdge(random(2*(w + h)));
            v:= GetNormalVel(p, 2, 4, 2);
            SpawnBall(vec(p), v, cllime, 5);
          end;
        end;
      end;
      if step = 1500 then NextLevel;
    end;
    7: begin
      if (step = -25) and nomusicyet then PlayMusic('Rising.mp3');
      if step>=0 then begin
        if step mod 25 = 0 then begin
         for i:= 0 to 3 + step div 500 do begin
            p:= GetEdge(random(2*(w + h)));
            v:= AimAtPlayer(p, 3, 5, 0.1);
            SpawnBall(vec(p), v, cllime, 5);
          end;
        end;
      end;
      if step = 1500 then NextLevel;
    end;
    8: begin
      case step of
        -25: PlayMusic('Truth of the Legend.mp3');
        0, 25, 50, 75, 100, 125, 150, 175, 200, 800, 920, 1040, 1160, 1280:
          SpawnLine(Point(0, 0), Point(w, 0), clred, 3, 100, AimAtPlayer, 7, 7, 0);
        860, 980, 1100, 1220, 1340: SpawnLine(Point(0, h), Point(w, h), clred, 3, 100, AimAtPlayer, 7, 7, 0);
        300, 350, 400, 450, 500, 550, 600, 650, 830, 950, 1070, 1190, 1310:
          SpawnLine(Point(0, 0), Point(0, h), clred, 3, 60, AimAtPlayer, 5, 5, 0);
        325, 375, 425, 475, 525, 575, 625, 675, 890, 1010, 1130, 1250, 1370:
          SpawnLine(Point(w, 0), Point(w, h), clred, 3, 60, AimAtPlayer, 5, 5, 0);
      end;
      if step = 1500 then NextLevel;
    end;
    9: begin
      case step of
        -25: PlayMusic('Truth of the Legend.mp3');
        0, 50, 100, 150, 200, 1000, 1200, 1400, 1600: SpawnLine(Point(0, 0), Point(w, 0), cllime, 4, 40, AimAtPlayer, 7, 7, 0);
        1100, 1300, 1500, 1700: SpawnLine(Point(0, h), Point(w, h), cllime, 4, 40, AimAtPlayer, 7, 7, 0);
        400, 500, 600, 700, 1050, 1250, 1450, 1650:  SpawnLine(Point(0, 0), Point(0, h), cllime, 4, 25, AimAtPlayer, 5, 5, 0);
        450, 550, 650, 750, 1150, 1350, 1550, 1750:  SpawnLine(Point(w, 0), Point(w, h), cllime, 4, 25, AimAtPlayer, 5, 5, 0);
      end;
      if step = 1850 then NextLevel;
    end;
    10: begin
      case Step of
        -25: PlayMusic('11-Titan.mp3');
        0: SpawnBall(vec(500, 700), vec(0, -4), cllime, 50);
        100: Balls[0].vY:= 0;
        120..150, 600..650: SpawnBall(center, AimAtPlayer(Point(500, 300), 6, 9, 0.1), cllime, 5);
        220..300, 501..530, 1150..1200: SpawnBall(center, AimAtPlayer(Point(500, 300), 6, 9, 0.5), clred, 3);
        400..440, 700..780, 1220..1240, 1260..1280, 1300..1349: SpawnCircle(center, 5, clred, 3, 6, step/50);
        350, 370, 390, 1250, 1290: SpawnCircle(center, 4, clred, 3, 30, step);
        500, 900, 940, 1350, 1370, 1390: SpawnBall(center, vec(0, -6), clred, 10);
        550: SpawnLine(Point(0, 0), Point(w, 0), cllime, 4, 100, AimAtPlayer, 3, 3, 0);
        1400, 1440: SpawnLine(Point(0, 0), Point(w, 0), clred, 3, 80, GetNormalVel, 4, 8, 3);
        950, 990, 1420: SpawnLine(Point(0, 0), Point(w, 0), cllime, 4, 30, GetNormalVel, 4, 8, 3);
        1501..1600: begin
          if step mod 2 = 0 then dec(Balls[0].r);
          SpawnBall(center, AimAtPlayer(Point(500, 300), 6, 9, Pi), clred, 3);
        end;
      end;
      if step = 1650 then NextLevel;
    end;
    11: begin
      if step = -25 then PlayMusic('Rising.mp3');
      if step>=0 then begin
        if step mod 25 = 0 then begin
         for i:= 0 to 3 + step div 500 do begin
            p:= GetEdge(random(2*(w + h)));
            v:= GetNormalVel(p, 2, 4, 2);
            SpawnBall(vec(p), v, claqua, 5);
          end;
        end;
      end;
      if step = 1500 then NextLevel;
    end;
    12: begin
      case step of
        -25: PlayMusic('Truth of the Legend.mp3');
        0, 50, 100, 150, 200, 1000, 1200, 1400, 1600: SpawnLine(Point(0, 0), Point(w, 0), claqua, 4, 40, AimAtPlayer, 7, 7, 0);
        1100, 1300, 1500, 1700: SpawnLine(Point(0, h), Point(w, h), claqua, 4, 40, AimAtPlayer, 7, 7, 0);
        400, 500, 600, 700, 1050, 1250, 1450, 1650: SpawnLine(Point(0, 0), Point(0, h), claqua, 4, 25, AimAtPlayer, 5, 5, 0);
        450, 550, 650, 750, 1150, 1350, 1550, 1750: SpawnLine(Point(w, 0), Point(w, h), claqua, 4, 25, AimAtPlayer, 5, 5, 0);
      end;
      if step = 1850 then NextLevel;
    end;
    13: begin
      case step of
        -25: begin
          SpawnLine(Point(0, 0), Point(w, 0), clred, 3, 100, DirectionalAim, 0, 0, 0);
          SpawnLine(Point(0, h), Point(w, h), clred, 3, 100, DirectionalAim, 0, 0, 0);
          PlayMusic('Mistake the Getaway.mp3');
        end;
        0, 100, 180, 245, 295, 340, 380, 540: SpawnLine(Point(w, 50), Point(w, h), clred, 3, 50, DirectionalAim, -7, 0, 0);
        50, 140, 220, 270, 320, 360, 400, 560: SpawnLine(Point(w, 0), Point(w, h-50), clred, 3, 50, DirectionalAim, -7, 0, 0);
        500, 600: begin
          SpawnLine(Point(w, 0), Point(w, h div 2 - 25), clred, 3, 25, DirectionalAim, -7, 0, 0);
          SpawnLine(Point(w, h), Point(w, h div 2 + 25), clred, 3, 25, DirectionalAim, -7, 0, 0);
        end;
        700, 900, 1050, 1150, 1300, 1320, 1340, 1460, 1530, 1590: SpawnLine(Point(w, 50), Point(w, h), clred, 3, 50, DirectionalAim, -7, 0, 0);
        800, 1000, 1100, 1200, 1380, 1400, 1420, 1500, 1560: SpawnLine(Point(0, 0), Point(0, h-50), clred, 3, 50, DirectionalAim, 7, 0, 0);
      end;
      if step = 1700 then NextLevel;
    end;
    14: begin
      case step of
        -25: begin
          SpawnLine(Point(0, 0), Point(w, 0), clred, 3, 100, DirectionalAim, 0, 0, 0);
          SpawnLine(Point(0, h), Point(w, h), clred, 3, 100, DirectionalAim, 0, 0, 0);
          PlayMusic('Movement Proposition.mp3');
        end;
        0: begin
          SpawnLine(Point(-200, 0), Point(w, 0), clred, 3, 100, DirectionalAim, 5, 5, 0);
          SpawnLine(Point(-200, h), Point(w, h), clred, 3, 100, DirectionalAim, 5, -5, 0);
        end;
        60, 120, 180, 260: begin
          SpawnLine(Point(0, 60), Point(0, h-60), clred, 3, 60, DirectionalAim, 5, 0, 0);
          SpawnLine(Point(w, 60), Point(w, h-60), clred, 3, 60, DirectionalAim, -5, 0, 0);
        end;
        80, 140, 200, 280: begin
          SpawnLine(Point(0, 0), Point(0, h div 2 - 50), clred, 3, 25, DirectionalAim, 5, 0, 0);
          SpawnLine(Point(0, h), Point(0, h div 2 + 50), clred, 3, 25, DirectionalAim, 5, 0, 0);
          SpawnLine(Point(w, 0), Point(w, h div 2 - 50), clred, 3, 25, DirectionalAim, -5, 0, 0);
          SpawnLine(Point(w, h), Point(w, h div 2 + 50), clred, 3, 25, DirectionalAim, -5, 0, 0);
        end;
        400, 420, 440, 460: begin
          SpawnLine(Point(0, 60), Point(0, h-60), claqua, 4, 60, DirectionalAim, 5, 0, 0);
          SpawnLine(Point(w, 60), Point(w, h-60), claqua, 4, 60, DirectionalAim, -5, 0, 0);
        end;
        600, 620, 640: SpawnLine(Point(60, 0), Point(w - 60, 0), claqua, 4, 60, DirectionalAim, 0, 5, 0);
      end;
      if step = 800 then NextLevel;
    end;
    15: begin
      case Step of
        -25: PlayMusic('11-Titan.mp3');
        0: SpawnBall(vec(500, 700), vec(0, -4), claqua, 50);
        100: Balls[0].vY:= 0;
        110..150, 540..580: SpawnBall(center, AimAtPlayer(Point(500, 300), 6, 9, 0.1), claqua, 5);
        160..200, 700..780, 1200..1299: SpawnBall(center, AimAtPlayer(Point(500, 300), 6, 9, 0.5), clred, 3);
        240..300, 820..860, 880..920: SpawnCircle(center, 5, clred, 3, 6, -step/50);
        440..500: if step mod 2 = 0 then SpawnCircle(center, 6, claqua, 4, 6, step/50);
        330, 360, 380, 400, 810, 870: SpawnCircle(center, 4, clred, 3, 30, step);
        600, 790, 930: SpawnCircle(center, 4, claqua, 4, 30, step);
        1100, 1120, 1140, 1300, 1330, 1400, 1410, 1420, 1430: SpawnBall(center, vec(0, -6), clred, 10);
        1150, 1170, 1190: SpawnLine(Point(0, 0), Point(w, 0), claqua, 4, 100, AimAtPlayer, 3, 3, 0);
        1380: SpawnLine(Point(0, 0), Point(w, 0), clred, 3, 80, GetNormalVel, 4, 8, 3);
        1350: SpawnLine(Point(0, 0), Point(w, 0), claqua, 4, 30, GetNormalVel, 4, 8, 3);
        1450, 1460, 1470, 1480: SpawnLine(Point(60, 0), Point(w - 60, 0), claqua, 4, 90, DirectionalAim, 0, 5, 0);
        1601..1700: begin
          if step mod 2 = 0 then dec(Balls[0].r);
          for i:= 0 to 1 do SpawnBall(center, AimAtPlayer(Point(500, 300), 6, 9, Pi), clred, 3);
        end;
      end;
      if step = 1800 then NextLevel;
    end;
    16: begin
      if step = -25 then PlayMusic('Rising Game.mp3');
      if step>=0 then begin
        if step mod (28 - step div 100) = 0 then begin
          p:= GetEdge(random(2*(w + h)));
          v:= AimAtPlayer(p, 3, 6, 0.1);
          SpawnBall(vec(p), v, clyellow, 5);
        end;
      end;
      if step = 1500 then NextLevel;
    end;
    17: begin
      case step of
        -25: begin
          SpawnBall(vec(500, 700), vec(0, 0), clred, 50);
          SpawnLine(Point(0, 0), Point(w, 0), clred, 3, 100, DirectionalAim, 0, 0, 0);
          SpawnLine(Point(0, h), Point(w, h), clred, 3, 100, DirectionalAim, 0, 0, 0);
          PlayMusic('Mistake the Getaway.mp3');
        end;
        0, 100: begin
          SpawnLine(Point(w, 0), Point(w, h-100), clred, 3, 100, DirectionalAim, -8, 0, 0);
          SpawnLine(Point(w + 600, 0), Point(w, h-100), clred, 3, 100, DirectionalAim, -8, 0, 0);
          SpawnLine(Point(w + 600, 100), Point(w, h), clred, 3, 100, DirectionalAim, -8, 0, 0);
          SpawnLine(Point(w + 600, 100), Point(w + 600, h), clred, 3, 100, DirectionalAim, -8, 0, 0);
        end;
        200: begin
          SpawnLine(Point(w, 0), Point(w, h-100), clred, 3, 100, DirectionalAim, -8, 0, 0);
          SpawnLine(Point(w + 300, 200), Point(w, h-100), clred, 3, 50, DirectionalAim, -8, 0, 0);
          SpawnLine(Point(w + 300, 200), Point(w + 600, h-100), clred, 3, 50, DirectionalAim, -8, 0, 0);
          SpawnLine(Point(w + 300, 300), Point(w, h), clred, 3, 50, DirectionalAim, -8, 0, 0);
          SpawnLine(Point(w + 300, 300), Point(w + 600, h), clred, 3, 50, DirectionalAim, -8, 0, 0);
          SpawnLine(Point(w + 600, 0), Point(w + 600, h - 100), clred, 3, 100, DirectionalAim, -8, 0, 0);
        end;
        300: begin
          SpawnLine(Point(w, h), Point(w, 100), clred, 3, 100, DirectionalAim, -8, 0, 0);
          SpawnLine(Point(w + 300, h-200), Point(w, 100), clred, 3, 50, DirectionalAim, -8, 0, 0);
          SpawnLine(Point(w + 300, h-200), Point(w + 600, 100), clred, 3, 50, DirectionalAim, -8, 0, 0);
          SpawnLine(Point(w + 300, h-300), Point(w, 0), clred, 3, 50, DirectionalAim, -8, 0, 0);
          SpawnLine(Point(w + 300, h-300), Point(w + 600, 0), clred, 3, 50, DirectionalAim, -8, 0, 0);
          SpawnLine(Point(w + 600, h), Point(w + 600, 100), clred, 3, 100, DirectionalAim, -8, 0, 0);
        end;
        400: begin
          SpawnLine(Point(w, 0), Point(w, h-100), clred, 3, 100, DirectionalAim, -8, 0, 0);
          SpawnLine(Point(w, h-100), Point(w + 300, h-100), clred, 3, 50, DirectionalAim, -8, 0, 0);
          SpawnLine(Point(w + 300, h-100), Point(w + 300, 0), clred, 3, 100, DirectionalAim, -8, 0, 0);
          SpawnLine(Point(w + 400, h), Point(w + 400, 100), clred, 3, 100, DirectionalAim, -8, 0, 0);
          SpawnLine(Point(w + 400, 100), Point(w + 700, 100), clred, 3, 50, DirectionalAim, -8, 0, 0);
          SpawnLine(Point(w + 700, 100), Point(w + 700, h), clred, 3, 100, DirectionalAim, -8, 0, 0);
        end;
        500: begin
          Balls[0].vY:= -4;
          PlayMusic('11-Titan.mp3');
        end;
        600: Balls[0].vY:= 0;
        641..649, 681..689, 721..729: SpawnBall(center, AimAtPlayer(Point(500, 300), 6, 9, 0.5), clred, 3);
        610..640, 690..720: SpawnCircle(center, 5, clred, 3, 6, -step/50);
        650..680, 730..760, 940..979, 981..1000: SpawnCircle(center, 5, clred, 3, 6, step/50);
        800, 840, 870, 930: SpawnBall(center, vec(0, -6), clred, 10);
        850, 890, 920, 980: SpawnLine(Point(0, 0), Point(w, 0), clred, 3, 80, GetNormalVel, 4, 8, 3);
        1101..1200: begin
          if step mod 2 = 0 then dec(Balls[0].r);
          for i:= 0 to 1 do SpawnBall(center, AimAtPlayer(Point(500, 300), 6, 9, Pi), clred, 3);
        end;
      end;
      if step = 1300 then NextLevel;
    end;
    18: begin
      if step = -25 then PlayMusic('Rising Game.mp3');
      if step>=0 then begin
        if step mod (50 - step div 75) = 0 then begin
          p:= GetEdge(random(2*(w + h)));
          v:= AimAtPlayer(p, 3, 6, 0.1);
          SpawnBall(vec(p), v, clyellow, 5);
        end;
        if step mod 25 = 0 then begin
          p:= GetEdge(random(2*(w + h)));
          v:= AimAtPlayer(p, 3, 6, 0.1);
          SpawnBall(vec(p), v, cllime, 5);
          p:= GetEdge(random(2*(w + h)));
          v:= AimAtPlayer(p, 3, 6, 0.1);
          SpawnBall(vec(p), v, claqua, 5);
        end;
      end;
      if step = 1500 then NextLevel;
    end;
    19: begin
      case step of
        -25: begin
          SpawnLine(Point(0, 0), Point(w, 0), clred, 3, 100, DirectionalAim, 0, 0, 0);
          SpawnLine(Point(0, h), Point(w, h), clred, 3, 100, DirectionalAim, 0, 0, 0);
          PlayMusic('Mistake the Getaway.mp3');
        end;
        0, 350, 700: begin
          SpawnLine(Point(w, 0), Point(w, h-100), clred, 3, 100, DirectionalAim, -8, 0, 0);
          SpawnLine(Point(w + 600, 0), Point(w, h-100), clred, 3, 100, DirectionalAim, -8, 0, 0);
          SpawnLine(Point(w + 600, 100), Point(w, h), clred, 3, 100, DirectionalAim, -8, 0, 0);
          SpawnLine(Point(w + 600, 100), Point(w + 600, h), clred, 3, 100, DirectionalAim, -8, 0, 0);
        end;
        100, 225: begin
          SpawnLine(Point(w, 0), Point(w, h-100), clred, 3, 100, DirectionalAim, -8, 0, 0);
          SpawnLine(Point(w + 500, h-100), Point(w, h-100), clred, 3, 100, DirectionalAim, -8, 0, 0);
          SpawnLine(Point(w + 500, h-100), Point(w, 0), clred, 3, 100, DirectionalAim, -8, 0, 0);
          SpawnLine(Point(w + 750, h), Point(w + 750, 100), clred, 3, 100, DirectionalAim, -8, 0, 0);
          SpawnLine(Point(w + 250, 100), Point(w + 750, 100), clred, 3, 100, DirectionalAim, -8, 0, 0);
          SpawnLine(Point(w + 250, 100), Point(w + 750, h), clred, 3, 100, DirectionalAim, -8, 0, 0);
        end;
        450, 575: begin
          SpawnLine(Point(w, 0), Point(w, h-100), clred, 3, 100, DirectionalAim, -8, 0, 0);
          SpawnLine(Point(w + 500, h-100), Point(w, 0), clred, 3, 100, DirectionalAim, -8, 0, 0);
          SpawnLine(Point(w + 100, 250), Point(w + 100, h+150), clred, 3, 100, DirectionalAim, -8, 0, 0);
          SpawnLine(Point(w + 600, h+150), Point(w + 100, 250), clred, 3, 100, DirectionalAim, -8, 0, 0);
          SpawnLine(Point(w + 750, h), Point(w + 750, 100), clred, 3, 100, DirectionalAim, -8, 0, 0);
          SpawnLine(Point(w + 250, 100), Point(w + 750, h), clred, 3, 100, DirectionalAim, -8, 0, 0);
          SpawnLine(Point(w + 650, h - 250), Point(w + 650, -150), clred, 3, 100, DirectionalAim, -8, 0, 0);
          SpawnLine(Point(w + 150, -150), Point(w + 650, h-250), clred, 3, 100, DirectionalAim, -8, 0, 0);
        end;
      end;
      if step = 850 then NextLevel;
    end;
    20: begin
      case step of
        -25: PlayMusic('11-Titan.mp3');
        0: SpawnBall(vec(500, 700), vec(0, -4), clyellow, 50);
        100: Balls[0].vY:= 0;
        110..150, 360..390: if step mod 5 = 0 then SpawnBall(center, AimAtPlayer(Point(500, 300), 6, 9, 0.1), clyellow, 5);
        160..200: SpawnBall(center, AimAtPlayer(Point(500, 300), 6, 9, 0.5), clred, 3);
        220..280: SpawnCircle(center, 5, clred, 3, 6, step/50);
        300..350, 560..600: SpawnCircle(center, 6, clred, 6, 6, step/50);
        400..450, 660..700: SpawnOpenCircle(center, 600, (step-100)/50, (step-100)/50+2*Pi, clred, 3, 6, Converge, center.X, center.Y, 50);
        550: SpawnCircle(center, 6, clyellow, 6, 6, step/50);
        800, 830, 860: SpawnCircle(center, 6, clred, 6, 30, step);
        900, 930, 960: SpawnOpenCircle(center, 600, (step-100), (step-100)+2*Pi, clred, 3, 30, Converge, Player.X, Player.Y, 50);
        1000: SpawnCircle(center, 4, clyellow, 3, 8, step);
        1101..1200: begin
          if step mod 2 = 0 then dec(Balls[0].r);
          for i:= 0 to 1 do SpawnBall(center, AimAtPlayer(Point(500, 300), 6, 9, Pi), clred, 3);
        end;
      end;
      if step = 1350 then NextLevel;
    end;
    21: begin
      if step = -25 then PlayMusic('Ominous Intro.mp3');
      if step>=0 then begin
        if step mod 25 = 0 then begin
          for i:= 0 to 4 + step div 500 do begin
            p:= GetEdge(random(2*(w + h)));
            v:= GetNormalVel(p, 4, 7, 1);
            SpawnBall(vec(p), v, clblue, 3 + random(2+step div 500));
          end;
        end;
      end;
      if step = 1500 then NextLevel;
    end;
    22: begin
      case step of
        -25: begin
          SpawnLine(Point(0, 0), Point(w, 0), clred, 3, 100, DirectionalAim, 0, 0, 0);
          SpawnLine(Point(0, h), Point(w, h), clred, 3, 100, DirectionalAim, 0, 0, 0);
          PlayMusic('Mistake the Getaway.mp3');
        end;
        0, 500: begin
          SpawnLine(Point(w, 0), Point(w, h-60), clred, 3, 100, DirectionalAim, -8, 0, 0);
          SpawnLine(Point(w+540, 60), Point(w + 60, h), clred, 3, 100, DirectionalAim, -8, 0, 0);
          SpawnLine(Point(w + 600, 0), Point(w + 600, h-60), clred, 3, 100, DirectionalAim, -8, 0, 0);
          SpawnLine(Point(w+60, 60), Point(w + 540, h), clred, 3, 100, DirectionalAim, -8, 0, 0);
        end;
        100, 400: begin
          SpawnLine(Point(w, 0), Point(w, h-100), clred, 3, 100, DirectionalAim, -8, 0, 0);
          SpawnLine(Point(w, h-100), Point(w + 200, h-100), clred, 3, 25, DirectionalAim, -8, 0, 0);
          SpawnLine(Point(w + 200, h-100), Point(w+200, 200), clred, 3, 50, DirectionalAim, -8, 0, 0);
          SpawnLine(Point(w + 300, h), Point(w + 300, 100), clred, 3, 100, DirectionalAim, -8, 0, 0);
          SpawnLine(Point(w + 300, 100), Point(w + 100, 100), clred, 3, 25, DirectionalAim, -8, 0, 0);
          SpawnLine(Point(w + 100, 100), Point(w+100, h-200), clred, 3, 50, DirectionalAim, -8, 0, 0);
        end;
        200, 300: begin
          SpawnLine(Point(w, 0), Point(w, h-100), clred, 3, 100, DirectionalAim, -8, 0, 0);
          SpawnLine(Point(w, h-100), Point(w + 200, h-100), clred, 3, 25, DirectionalAim, -8, 0, 0);
          SpawnLine(Point(w, h-350), Point(w + 200, h-350), clred, 3, 25, DirectionalAim, -8, 0, 0);

          SpawnLine(Point(w + 300, 100), Point(w + 300, h), clred, 3, 100, DirectionalAim, -8, 0, 0);
          SpawnLine(Point(w + 100, 100), Point(w + 300, 100), clred, 3, 25, DirectionalAim, -8, 0, 0);
          SpawnLine(Point(w + 100, 350), Point(w + 300, 350), clred, 3, 25, DirectionalAim, -8, 0, 0);
        end;
      end;
      if step = 650 then NextLevel;
    end;
    23: begin
      if step = -25 then PlayMusic('Ominous Intro.mp3');
      if step>=0 then begin
        if step mod 27 = 0 then begin
          for i:= 0 to 4 {+ step div 500} do begin
            p:= GetEdge(random(2*(w + h)));
            v:= GetNormalVel(p, 2, 6, 1);
            SpawnBall(vec(p), v, clblue, 3 + random(4+step div 500));
          end;
        end;
      end;
      if step = 1500 then NextLevel;
    end;
    24: begin
      case step of
        -25: PlayMusic('Truth of the Legend.mp3');
        0, 25, 50, 75, 100, 125, 150, 175, 200, 800, 920, 1040, 1160, 1280:
          SpawnLine(Point(0, 0), Point(w, 0), clblue, 4, 100, AimAtPlayer, 7, 7, 0);
        860, 980, 1100, 1220, 1340: SpawnLine(Point(0, h), Point(w, h), clblue, 4, 100, AimAtPlayer, 7, 7, 0);
        300, 350, 400, 450, 500, 550, 600, 650, 830, 950, 1070, 1190, 1310:
          SpawnLine(Point(0, 0), Point(0, h), clblue, 4, 60, AimAtPlayer, 5, 5, 0);
        325, 375, 425, 475, 525, 575, 625, 675, 890, 1010, 1130, 1250, 1370:
          SpawnLine(Point(w, 0), Point(w, h), clblue, 4, 60, AimAtPlayer, 5, 5, 0);
      end;
      if step = 1500 then NextLevel;
    end;
    25: begin
      case step of
        -25: PlayMusic('11-Titan.mp3');
        0: SpawnBall(vec(500, 700), vec(0, -4), clblue, 50);
        1..99: begin
          Balls[0].vX:=0;
          Balls[0].vY:= -4;
        end;
        100: begin
          Balls[0].vX:= 0;
          Balls[0].vY:= 0;
        end;
        110..150: SpawnBall(center, AimAtPlayer(Point(500, 300), 6, 9, 0.1), clblue, 3);
        540..560, 630..650: SpawnBall(center, AimAtPlayer(Point(500, 300), 1, 5, 0.5), clblue, 5);
        900..920: SpawnBall(center, AimAtPlayer(Point(500, 300), 3, 3, 0.5), clblue, 10);
        450..500: SpawnCircle(center, 5, clred, 3, 6, step/50);
        250..330: SpawnCircle(center, 6, clred, 6, 6, step/50);
        350..430: SpawnOpenCircle(center, 600, (step-100)/50, (step-100)/50+2*Pi, clred, 3, 6, Converge, center.X, center.Y, 50);
        160..200, 1000..1050: SpawnCircle(center, 6, clblue, 6, 6, step/50);
        580, 620, 860, 1250, 1270, 1290: SpawnCircle(center, 6, clred, 6, 30, step);
        680, 720, 960, 1350, 1370, 1390: SpawnOpenCircle(center, 600, (step-100), (step-100)+2*Pi, clred, 3, 30, Converge, Player.X, Player.Y, 50);
        740, 760, 800, 1060, 1100, 1120: SpawnBall(center, vec(0, -6), clred, 10);
        790: SpawnLine(Point(0, 0), Point(w, 0), clblue, 4, 100, AimAtPlayer, 3, 3, 0);
        810, 1110, 1150, 1170: SpawnLine(Point(0, 0), Point(w, 0), clred, 3, 80, GetNormalVel, 4, 8, 3);
        850: SpawnLine(Point(0, 0), Point(w, 0), clblue, 4, 50, GetNormalVel, 4, 8, 3);
        1401..1500: begin
          if step mod 2 = 0 then dec(Balls[0].r);
          for i:= 0 to 1 do SpawnBall(center, AimAtPlayer(Point(500, 300), 6, 9, Pi), clred, 3);
        end;
      end;
      if step = 1600 then NextLevel;
    end;
    26: begin
      if step = -25 then PlayMusic('Ominous Intro.mp3');
      if step>=0 then begin
        if step mod 27 = 0 then begin
          for i:= 0 to 4 {+ step div 500} do begin
            p:= GetEdge(random(2*(w + h)));
            v:= GetNormalVel(p, 2, 6, 1);
            SpawnBall(vec(p), v, $ff00ff, 3);
          end;
        end;
      end;
      if step = 1000 then NextLevel;
    end;
    27: begin
      case step of
        -25: PlayMusic('Take the Lead.mp3');
        0, 40, 80, 400, 440, 480, 520, 560: SpawnLine(Point(0, 0), Point(w, 0), clred, 3, 12, DirectionalAim, 0, 5, 0);
        20, 60, 100, 420, 460, 500, 540, 580: SpawnLine(Point(-40, 0), Point(w+40, 0), clred, 3, 13, DirectionalAim, 0, 5, 0);
        300, 350, 700, 780, 860: SpawnLine(Point(0, 0), Point(w, 0), clred, 3, 25, DirectionalAim, 0, 5, 0);
        330, 360, 740, 820, 900: SpawnLine(Point(-20, 0), Point(w + 20, 0), clred, 3, 26, DirectionalAim, 0, 5, 0);
        720, 800, 880, 1000, 1020, 1040: SpawnLine(Point(w, 0), Point(w, h), clred, 3, 15, DirectionalAim, -5, 0, 0);
        760, 840, 920, 1010, 1030, 1050: SpawnLine(Point(w, -20), Point(w, h+20), clred, 3, 16, DirectionalAim, -5, 0, 0);
        120, 160, 200, 410, 450, 490, 530, 570: SpawnLine(Point(w, 0), Point(w, h), clred, 3, 7, DirectionalAim, -5, 0, 0);
        140, 180, 220, 430, 470, 510, 550: SpawnLine(Point(w, -40), Point(w, h+40), clred, 3, 8, DirectionalAim, -5, 0, 0);
        //: SpawnLine(Point(0, 0), Point(w, 0), clred, 3, 50, GetNormalVel, 0, 4, 2);
      end;
      if step = 1250 then NextLevel;
    end;
    28: begin
      case step of
        -25: PlayMusic('Rising Game.mp3');
        0, 50, 100, 500, 530, 560: SpawnOpenCircle(center, 600, 0, 2*Pi, clred, 3, 30, Converge, Player.X, Player.Y, 50);
        150, 300, 320, 340: SpawnOpenCircle(center, 600, 0, 2*Pi, clred, 3, 30, Converge, Player.X, Player.Y, 100);
      end;
      if step = 700 then NextLevel;
    end;
    29: begin
      case step of
        -25: begin
          SpawnLine(Point(0, 0), Point(w, 0), clred, 3, 100, DirectionalAim, 0, 0, 0);
          SpawnLine(Point(0, h), Point(w, h), clred, 3, 100, DirectionalAim, 0, 0, 0);
          PlayMusic('Mistake the Getaway.mp3');
        end;
        0, 360, 440, 680: begin
          SpawnLine(Point(w, 0), Point(w, h-80), clred, 3, 50, DirectionalAim, -8, 0, 0);
          SpawnOpenCircle(vec(w, 300), 220, 0, Pi/2, clred, 3, 22, DirectionalAim, -8, 0, 0);
          SpawnOpenCircle(vec(w, 300), 300, 0, Pi/2, clred, 3, 30, DirectionalAim, -8, 0, 0);
          SpawnOpenCircle(vec(w + 520, 300), 220, Pi, 3*Pi/2, clred, 3, 22, DirectionalAim, -8, 0, 0);
          SpawnOpenCircle(vec(w + 520, 300), 300, Pi, 3*Pi/2, clred, 3, 30, DirectionalAim, -8, 0, 0);
          SpawnLine(Point(w + 520, 80), Point(w + 520, h), clred, 3, 50, DirectionalAim, -8, 0, 0);
        end;
        80, 520: begin
          SpawnLine(Point(w, 0), Point(w, h-80), clred, 3, 50, DirectionalAim, -8, 0, 0);
          SpawnOpenCircle(vec(w, 300), 220, 0, Pi/2, clred, 3, 22, DirectionalAim, -8, 0, 0);
          SpawnOpenCircle(vec(w, 300), 300, 0, Pi/2, clred, 3, 30, DirectionalAim, -8, 0, 0);
          SpawnOpenCircle(vec(w + 520, 300), 220, Pi, 2*Pi, clred, 3, 44, DirectionalAim, -8, 0, 0);
          SpawnOpenCircle(vec(w + 520, 300), 300, Pi, 2*Pi, clred, 3, 60, DirectionalAim, -8, 0, 0);
          SpawnOpenCircle(vec(w + 1040, 300), 220, Pi/2, Pi, clred, 3, 22, DirectionalAim, -8, 0, 0);
          SpawnOpenCircle(vec(w + 1040, 300), 300, Pi/2, Pi, clred, 3, 30, DirectionalAim, -8, 0, 0);
          SpawnLine(Point(w + 1040, 0), Point(w + 1040, h-80), clred, 3, 50, DirectionalAim, -8, 0, 0);
        end;
        240: begin
          SpawnLine(Point(w, 0), Point(w, h-80), clred, 3, 50, DirectionalAim, -8, 0, 0);
          SpawnLine(Point(w, h-80), Point(w + 200, h-80), clred, 3, 20, DirectionalAim, -8, 0, 0);
          SpawnOpenCircle(vec(w + 200, 450), 70, -Pi/2, Pi/2, clred, 3, 14, DirectionalAim, -8, 0, 0);
          SpawnOpenCircle(vec(w + 200, 450), 150, -Pi/2, Pi/2, clred, 3, 30, DirectionalAim, -8, 0, 0);
          SpawnOpenCircle(vec(w + 200, 230), 70, Pi/2, 2*Pi, clred, 3, 21, DirectionalAim, -8, 0, 0);
          SpawnOpenCircle(vec(w + 200, 230), 150, Pi/2, 2*Pi, clred, 3, 45, DirectionalAim, -8, 0, 0);
          SpawnOpenCircle(vec(w + 420, 230), 70, 0, Pi, clred, 3, 14, DirectionalAim, -8, 0, 0);
          SpawnOpenCircle(vec(w + 420, 230), 150, 0, Pi, clred, 3, 30, DirectionalAim, -8, 0, 0);
          SpawnOpenCircle(vec(w + 640, 230), 70, Pi, 5*Pi/2, clred, 3, 21, DirectionalAim, -8, 0, 0);
          SpawnOpenCircle(vec(w + 640, 230), 150, Pi, 5*Pi/2, clred, 3, 45, DirectionalAim, -8, 0, 0);
          SpawnOpenCircle(vec(w + 640, 450), 70, Pi/2, 3*Pi/2, clred, 3, 14, DirectionalAim, -8, 0, 0);
          SpawnOpenCircle(vec(w + 640, 450), 150, Pi/2, 3*Pi/2, clred, 3, 30, DirectionalAim, -8, 0, 0);
          SpawnLine(Point(w + 640, h-80), Point(w + 840, h-80), clred, 3, 20, DirectionalAim, -8, 0, 0);
          SpawnLine(Point(w + 840, 0), Point(w + 840, h-80), clred, 3, 50, DirectionalAim, -8, 0, 0);
        end;
      end;
      if step = 850 then NextLevel;
    end;
    30: begin
      case step of
        -25: PlayMusic('11-Titan.mp3');
        0: SpawnBall(vec(500, 700), vec(0, -4), $fe00fe, 50);
        100: begin
          Balls[0].vX:= 0;
          Balls[0].vY:= 0;
        end;
        110..150, 280..300, 701..750: SpawnBall(center, AimAtPlayer(Point(500, 300), 6, 9, 0.1), $ff00ff, 3);
        160..200, 380..400, 820..840: SpawnBall(center, AimAtPlayer(Point(500, 300), 1, 5, Pi), $ff00ff, 3);
        210..270: SpawnCircle(center, 6, clred, 6, 6, step/50);
        310..370: SpawnOpenCircle(center, 600, (step-100)/50, (step-100)/50+2*Pi, clred, 3, 6, Converge, center.X, center.Y, 50);
        410, 430: SpawnCircle(center, 6, $ff00ff, 6, 6, step/50);
        500, 520, 540: SpawnCircle(center, 6, clred, 6, 30, step);
        600, 620, 640: SpawnOpenCircle(center, 600, (step-100), (step-100)+2*Pi, clred, 3, 30, Converge, Player.X, Player.Y, 130);
        760, 780, 800: SpawnCircle(center, 6, clred, 6, 30, step);
        860, 880, 900: SpawnOpenCircle(center, 600, (step-100), (step-100)+2*Pi, clred, 3, 30, Converge, Player.X, Player.Y, 50);
        510, 530: SpawnBall(center, vec(0, -6), clred, 10);
        560, 580: SpawnLine(Point(0, 0), Point(w, 0), clred, 3, 80, GetNormalVel, 4, 8, 3);
        1001..1100: begin
          if step mod 2 = 0 then dec(Balls[0].r);
          for i:= 0 to 1 do SpawnBall(center, AimAtPlayer(Point(500, 300), 6, 9, Pi), clred, 3);
        end;
      end;
      if step = 1200 then NextLevel;
    end;
    31: begin
      if step = -25 then PlayMusic('Ominous Intro.mp3');
      if step>=0 then begin
        if step mod 27 = 0 then begin
          for i:= 0 to 2 {+ step div 500} do begin
            p:= GetEdge(random(2*(w + h)));
            v:= GetNormalVel(p, 2, 6, 1);
            SpawnBall(vec(p), v, $ff00ff, 3);
            p:= GetEdge(random(2*(w + h)));
            v:= GetNormalVel(p, 2, 6, 1);
            SpawnBall(vec(p), v, claqua, 5);
          end;
        end;
      end;
      if step = 1000 then NextLevel;
    end;
    32: begin
      case step of
        -25: begin
          SpawnLine(Point(0, 0), Point(w, 0), clred, 3, 100, DirectionalAim, 0, 0, 0);
          SpawnLine(Point(0, h), Point(w, h), clred, 3, 100, DirectionalAim, 0, 0, 0);
          PlayMusic('Movement Proposition.mp3');
        end;
        0: begin
          SpawnLine(Point(w, 0), Point(w, h div 2), clred, 3, 30, DirectionalAim, -8, 0, 0);
          SpawnLine(Point(w + 300, h div 2), Point(w, h div 2), clred, 3, 30, DirectionalAim, -8, 0, 0);
          UpperCircleBarrier1(vec(w+500, 300), vec(-8, 0), 200, 100);
          SpawnLine(Point(w + 1000, 0), Point(w + 1000, h div 2), clred, 3, 30, DirectionalAim, -8, 0, 0);
          SpawnLine(Point(w + 700, h div 2), Point(w + 1000, h div 2), clred, 3, 30, DirectionalAim, -8, 0, 0);

          SpawnLine(Point(0, h), Point(0, h div 2), clred, 3, 30, DirectionalAim, 8, 0, 0);
          SpawnLine(Point(-300, h div 2), Point(0, h div 2), clred, 3, 30, DirectionalAim, 8, 0, 0);
          LowerCircleBarrier1(vec(-500, 300), vec(8, 0), 200, 100);
          SpawnLine(Point(-1000, h), Point(-1000, h div 2), clred, 3, 30, DirectionalAim, 8, 0, 0);
          SpawnLine(Point(-700, h div 2), Point(-1000, h div 2), clred, 3, 30, DirectionalAim, 8, 0, 0);
        end;
        200: begin
          SpawnLine(Point(w, 0), Point(w, h div 2), clred, 3, 30, DirectionalAim, -8, 0, 0);
          SpawnLine(Point(w + 300, h div 2), Point(w, h div 2), clred, 3, 30, DirectionalAim, -8, 0, 0);
          UpperBoxBarrier(Point(w+500, 300), Point(-8, 0), 200, 110);
          SpawnLine(Point(w + 1000, 0), Point(w + 1000, h div 2), clred, 3, 30, DirectionalAim, -8, 0, 0);
          SpawnLine(Point(w + 700, h div 2), Point(w + 1000, h div 2), clred, 3, 30, DirectionalAim, -8, 0, 0);

          SpawnLine(Point(0, h), Point(0, h div 2), clred, 3, 30, DirectionalAim, 8, 0, 0);
          SpawnLine(Point(-300, h div 2), Point(0, h div 2), clred, 3, 30, DirectionalAim, 8, 0, 0);
          LowerBoxBarrier(Point(-500, 300), Point(8, 0), 200, 110);
          SpawnLine(Point(-1000, h), Point(-1000, h div 2), clred, 3, 30, DirectionalAim, 8, 0, 0);
          SpawnLine(Point(-700, h div 2), Point(-1000, h div 2), clred, 3, 30, DirectionalAim, 8, 0, 0);
        end;
        400: begin
          SpawnLine(Point(w, 0), Point(w, h div 2), clred, 3, 30, DirectionalAim, -8, 0, 0);
          SpawnLine(Point(w + 200, h div 2), Point(w, h div 2), clred, 3, 30, DirectionalAim, -8, 0, 0);
          UpperBoxBarrier(Point(w+400, 300), Point(-8, 0), 200, 110);
          SpawnLine(Point(w + 600, 300), Point(w + 800, h div 2), clred, 3, 30, DirectionalAim, -8, 0, 0);
          UpperCircleBarrier1(vec(w+1000, 300), vec(-8, 0), 200, 100);
          SpawnLine(Point(w + 1400, 0), Point(w + 1400, h div 2), clred, 3, 30, DirectionalAim, -8, 0, 0);
          SpawnLine(Point(w + 1200, h div 2), Point(w + 1400, h div 2), clred, 3, 30, DirectionalAim, -8, 0, 0);

          SpawnLine(Point(0, h), Point(0, h div 2), clred, 3, 30, DirectionalAim, 8, 0, 0);
          SpawnLine(Point(-200, h div 2), Point(0, h div 2), clred, 3, 30, DirectionalAim, 8, 0, 0);
          LowerBoxBarrier(Point(-400, 300), Point(8, 0), 200, 110);
          SpawnLine(Point(-600, 300), Point(-800, h div 2), clred, 3, 30, DirectionalAim, 8, 0, 0);
          LowerCircleBarrier1(vec(-1000, 300), vec(8, 0), 200, 100);
          SpawnLine(Point(-1400, h), Point(-1400, h div 2), clred, 3, 30, DirectionalAim, 8, 0, 0);
          SpawnLine(Point(-1200, h div 2), Point(-1400, h div 2), clred, 3, 30, DirectionalAim, 8, 0, 0);
        end;
      end;
      if step = 700 then NextLevel;
    end;
    33: begin
      if step = -25 then PlayMusic('Not As It Seems.mp3');
      if step>=0 then begin
        if step mod 27 = 0 then begin
          for i:= 0 to 4 + step div 500 do begin
            p:= GetEdge(random(2*(w + h)));
            v:= GetNormalVel(p, 2, 6, 1);
            SpawnBall(vec(p), v, $ffffff, 5);
          end;
        end;
      end;
      if step = 1500 then NextLevel;
    end;
    34: begin
      case step of
        -25: begin
          SpawnLine(Point(0, 0), Point(w, 0), clred, 3, 100, DirectionalAim, 0, 0, 0);
          SpawnLine(Point(0, h), Point(w, h), clred, 3, 100, DirectionalAim, 0, 0, 0);
          PlayMusic('Rites.mp3');
        end;
        0, 70, 150, 230, 720: begin
          SpawnLine(Point(w, -200), Point(w, 250), clwhite, 5, 45, DirectionalAim, -8, 0, 0);
          SpawnLine(Point(w, 250), Point(w + 400, 250), clwhite, 5, 40, DirectionalAim, -8, 0, 0);
          SpawnLine(Point(w + 400, -200), Point(w + 400, 250), clwhite, 5, 45, DirectionalAim, -8, 0, 0);

          SpawnLine(Point(w, 800), Point(w, 350), clwhite, 5, 45, DirectionalAim, -8, 0, 0);
          SpawnLine(Point(w, 350), Point(w + 400, 350), clwhite, 5, 40, DirectionalAim, -8, 0, 0);
          SpawnLine(Point(w + 400, 800), Point(w + 400, 350), clwhite, 5, 45, DirectionalAim, -8, 0, 0);
        end;

        300, 380, 800: begin
          SpawnLine(Point(w, -200), Point(w, 480), clwhite, 5, 68, DirectionalAim, -8, 0, 0);
          SpawnLine(Point(w, 480), Point(w + 400, 0), clwhite, 5, 40, DirectionalAim, -8, 0, 0);
          SpawnLine(Point(w + 400, -200), Point(w + 400, 0), clwhite, 5, 20, DirectionalAim, -8, 0, 0);

          SpawnLine(Point(w, 800), Point(w, 600), clwhite, 5, 20, DirectionalAim, -8, 0, 0);
          SpawnLine(Point(w, 600), Point(w + 400, 120), clwhite, 5, 40, DirectionalAim, -8, 0, 0);
          SpawnLine(Point(w + 400, 800), Point(w + 400, 120), clwhite, 5, 68, DirectionalAim, -8, 0, 0);
        end;

        500, 570, 640: begin
          SpawnLine(Point(w, -200), Point(w, 250), clwhite, 5, 45, DirectionalAim, -8, 0, 0);
          SpawnLine(Point(w, 250), Point(w + 400, 250), clwhite, 5, 40, DirectionalAim, -8, 0, 0);
          SpawnLine(Point(w + 400, -200), Point(w + 400, 250), clwhite, 5, 45, DirectionalAim, -8, 0, 0);

          SpawnLine(Point(w, 800), Point(w, 350), $f8f8f8, 5, 45, DirectionalAim, -8, 0, 0);
          SpawnLine(Point(w, 350), Point(w + 400, 350), $f8f8f8, 5, 40, DirectionalAim, -8, 0, 0);
          SpawnLine(Point(w + 400, 800), Point(w + 400, 350), $f8f8f8, 5, 45, DirectionalAim, -8, 0, 0);
        end;
      end;
      if step = 950 then NextLevel;
    end;
    35: begin
      if length(Balls) > 0 then center:= vec(Balls[0].X, Balls[0].Y);
      case step of
        -25: PlayMusic('11-Titan.mp3');
        0: SpawnBall(vec(500, 700), vec(0, -4), $9f9f9f, 50);
        100: begin
          Balls[0].vX:= 0;
          Balls[0].vY:= 0;
        end;
        110..180, 700..750: SpawnBall(center, AimAtPlayer(Point(round(center.X), round(center.Y)), 6, 9, 0.1), $ffffff, 3);
        350..400, 1100..1150, 1240..1290: SpawnBall(center, AimAtPlayer(Point(round(center.X), round(center.Y)), 1, 5, Pi), $ffffff, 3);
        200..300, 950..1050: SpawnCircle(center, 6, clred, 3, 6, step/50);
        550..600, 860..900, 1170..1220, 1310..1360: SpawnCircle(center, 6, $ffffff, 3, 6, step/50);
        450, 470, 490, 780, 800, 820, 1400, 1420, 1440, 1460: SpawnCircle(center, 6, $ffffff, 6, 30, step);
        1501..1600: begin
          if step mod 2 = 0 then dec(Balls[0].r);
          for i:= 0 to 1 do SpawnBall(center, AimAtPlayer(Point(500, 300), 6, 9, Pi), $ffffff, 3);
        end;
      end;
      if step = 1700 then NextLevel;
    end;
    36: begin
      if step = -25 then PlayMusic('Not As It Seems.mp3');
      if step>=0 then begin
        if step mod 27 = 0 then begin
          for i:= 0 to 1 + step div 600 do begin
            p:= GetEdge(random(2*(w + h)));
            v:= AimAtPlayer(p, 2, 6, 1);
            SpawnBall(vec(p), v, $afafaf, 5);
            p:= GetEdge(random(2*(w + h)));
            v:= GetNormalVel(p, 2, 6, 1);
            SpawnBall(vec(p), v, $bfbfbf, 5);
          end;
        end;
      end;
      if step = 1500 then NextLevel;
    end;
    37: begin
      case step of
        -25: begin
          SpawnLine(Point(0, 0), Point(w, 0), clred, 3, 100, DirectionalAim, 0, 0, 0);
          SpawnLine(Point(0, h), Point(w, h), clred, 3, 100, DirectionalAim, 0, 0, 0);
          PlayMusic('Rites.mp3');
        end;
        0, 120: begin
          SpawnLine(Point(w, 0), Point(w, 500), $efefef, 5, 50, DirectionalAim, -8, 0, 0);
          SpawnLine(Point(w, 500), Point(w+200, 500), $efefef, 5, 20, DirectionalAim, -8, 0, 0);
          SpawnLine(Point(w+200, 0), Point(w+200, 500), $efefef, 5, 50, DirectionalAim, -8, 0, 0);

          SpawnLine(Point(w+300, 100), Point(w+300, 600), $e7e7e7, 5, 50, DirectionalAim, -8, 0, 0);
          SpawnLine(Point(w+300, 100), Point(w+500, 100), $e7e7e7, 5, 20, DirectionalAim, -8, 0, 0);
          SpawnLine(Point(w+500, 100), Point(w+500, 600), $e7e7e7, 5, 50, DirectionalAim, -8, 0, 0);
        end;
        220, 400: begin
          SpawnLine(Point(w, -300), Point(w, 500), $ffffff, 5, 80, DirectionalAim, -8, 0, 0);
          SpawnLine(Point(w, 500), Point(w+400, 500), $ffffff, 5, 40, DirectionalAim, -8, 0, 0);
          SpawnLine(Point(w+400, 500), Point(w+400, 350), $ffffff, 5, 15, DirectionalAim, -8, 0, 0);
          SpawnLine(Point(w+400, 350), Point(w+100, 350), $ffffff, 5, 30, DirectionalAim, -8, 0, 0);
          SpawnLine(Point(w+100, 350), Point(w+100, -300), $ffffff, 5, 65, DirectionalAim, -8, 0, 0);

          SpawnLine(Point(w+600, 900), Point(w+600, 100), $f7f7f7, 5, 80, DirectionalAim, -8, 0, 0);
          SpawnLine(Point(w+600, 100), Point(w+200, 100), $f7f7f7, 5, 40, DirectionalAim, -8, 0, 0);
          SpawnLine(Point(w+200, 100), Point(w+200, 250), $f7f7f7, 5, 15, DirectionalAim, -8, 0, 0);
          SpawnLine(Point(w+200, 250), Point(w+500, 250), $f7f7f7, 5, 30, DirectionalAim, -8, 0, 0);
          SpawnLine(Point(w+500, 250), Point(w+500, 900), $f7f7f7, 5, 65, DirectionalAim, -8, 0, 0);
        end;
        550: begin
          SpawnLine(Point(w, -300), Point(w, 500), $afafaf, 5, 80, DirectionalAim, -8, 0, 0);
          SpawnLine(Point(w, 500), Point(w+400, 500), $afafaf, 5, 40, DirectionalAim, -8, 0, 0);
          SpawnLine(Point(w+400, 500), Point(w+400, 350), $afafaf, 5, 15, DirectionalAim, -8, 0, 0);
          SpawnLine(Point(w+400, 350), Point(w+100, 350), $afafaf, 5, 30, DirectionalAim, -8, 0, 0);
          SpawnLine(Point(w+100, 350), Point(w+100, -300), $afafaf, 5, 65, DirectionalAim, -8, 0, 0);

          SpawnLine(Point(w+600, 900), Point(w+600, 100), $a7a7a7, 5, 80, DirectionalAim, -8, 0, 0);
          SpawnLine(Point(w+600, 100), Point(w+200, 100), $a7a7a7, 5, 40, DirectionalAim, -8, 0, 0);
          SpawnLine(Point(w+200, 100), Point(w+200, 250), $a7a7a7, 5, 15, DirectionalAim, -8, 0, 0);
          SpawnLine(Point(w+200, 250), Point(w+500, 250), $a7a7a7, 5, 30, DirectionalAim, -8, 0, 0);
          SpawnLine(Point(w+500, 250), Point(w+500, 900), $a7a7a7, 5, 65, DirectionalAim, -8, 0, 0);
        end;
      end;
      if step = 750 then NextLevel;
    end;
    38: begin
      if step>=0 then begin
        if step mod 27 = 0 then begin
          for i:= 0 to 2 + step div 400 do begin
            p:= GetEdge(random(2*(w + h)));
            v:= AimAtPlayer(p, 2, 6, 1);
            SpawnBall(vec(p), v, clred, 3);
          end;
        end;
      end;
      case step of
        -25: begin
          SpawnLine(Point(0, 0), Point(w, 0), clred, 3, 100, DirectionalAim, 0, 0, 0);
          SpawnLine(Point(0, h), Point(w, h), clred, 3, 100, DirectionalAim, 0, 0, 0);
          PlayMusic('Mistake the Getaway.mp3');
        end;
        0, 120, 550: begin
          SpawnLine(Point(w, 0), Point(w, 500), clred, 3, 50, DirectionalAim, -8, 0, 0);
          SpawnLine(Point(w, 500), Point(w+200, 500), clred, 3, 20, DirectionalAim, -8, 0, 0);
          SpawnLine(Point(w+200, 0), Point(w+200, 500), clred, 3, 50, DirectionalAim, -8, 0, 0);

          SpawnLine(Point(w+300, 100), Point(w+300, 600), clred, 3, 50, DirectionalAim, -8, 0, 0);
          SpawnLine(Point(w+300, 100), Point(w+500, 100), clred, 3, 20, DirectionalAim, -8, 0, 0);
          SpawnLine(Point(w+500, 100), Point(w+500, 600), clred, 3, 50, DirectionalAim, -8, 0, 0);
        end;
        220, 400, 700: begin
          SpawnLine(Point(w, 0), Point(w, 500), clred, 3, 50, DirectionalAim, -8, 0, 0);
          SpawnLine(Point(w, 500), Point(w+400, 500), clred, 3, 40, DirectionalAim, -8, 0, 0);
          SpawnLine(Point(w+400, 500), Point(w+400, 350), clred, 3, 15, DirectionalAim, -8, 0, 0);
          SpawnLine(Point(w+400, 350), Point(w+100, 350), clred, 3, 30, DirectionalAim, -8, 0, 0);
          SpawnLine(Point(w+100, 350), Point(w+100, 0), clred, 3, 35, DirectionalAim, -8, 0, 0);

          SpawnLine(Point(w+600, 600), Point(w+600, 100), clred, 3, 50, DirectionalAim, -8, 0, 0);
          SpawnLine(Point(w+600, 100), Point(w+200, 100), clred, 3, 40, DirectionalAim, -8, 0, 0);
          SpawnLine(Point(w+200, 100), Point(w+200, 250), clred, 3, 15, DirectionalAim, -8, 0, 0);
          SpawnLine(Point(w+200, 250), Point(w+500, 250), clred, 3, 30, DirectionalAim, -8, 0, 0);
          SpawnLine(Point(w+500, 250), Point(w+500, 600), clred, 3, 35, DirectionalAim, -8, 0, 0);
        end;
      end;
      if step = 900 then NextLevel;
    end;
    39: begin
      case step of
        -25: PlayMusic('Truth of the Legend.mp3');
        0, 25, 50, 75, 100, 125, 150, 175, 200, 800, 920, 1040, 1160, 1280:
          SpawnLine(Point(0, 0), Point(w, 0), gray($f0 + random(16)), 3, 100, AimAtPlayer, 7, 7, 0);
        860, 980, 1100, 1220, 1340: SpawnLine(Point(0, h), Point(w, h), gray($f0 + random(16)), 3, 100, AimAtPlayer, 7, 7, 0);
        300, 350, 400, 450, 500, 550, 600, 650, 830, 950, 1070, 1190, 1310:
          SpawnLine(Point(0, 0), Point(0, h), gray($e0 + random(16)), 3, 60, AimAtPlayer, 5, 5, 0);
        325, 375, 425, 475, 525, 575, 625, 675, 890, 1010, 1130, 1250, 1370:
          SpawnLine(Point(w, 0), Point(w, h), gray($e0 + random(16)), 3, 60, AimAtPlayer, 5, 5, 0);
      end;
      if step = 1500 then NextLevel;
    end;
    40: begin
      if length(Balls) > 0 then center:= vec(Balls[0].X, Balls[0].Y);
      if step mod 2 = 0 then cl:= $afafaf else cl:= $bfbfbf;
      case step of
        -25: PlayMusic('11-Titan.mp3');
        0: SpawnBall(vec(500, 700), vec(0, -4), $9e9e9e, 50);
        100: begin
          Balls[0].vX:= 0;
          Balls[0].vY:= 0;
        end;
        190..260, 740..800: SpawnBall(center, AimAtPlayer(Point(round(center.X), round(center.Y)), 6, 9, 0.1), cl, 3);
        300..350, 900..940: SpawnBall(center, AimAtPlayer(Point(round(center.X), round(center.Y)), 1, 5, Pi), cl, 3);
        110..160, 400..420, 440..460, 480..500, 1000..1020, 1030..1050: SpawnCircle(center, 6, clred, 3, 6, step/50);
        680..700: SpawnCircle(center, 6, cl, 3, 6, step/50);
        600, 640, 960, 1060: SpawnCircle(center, 6, $ffffff, 6, 30, step);
        1221..1320: begin
          if step mod 2 = 0 then dec(Balls[0].r);
          for i:= 0 to 1 do SpawnBall(center, AimAtPlayer(Point(500, 300), 6, 9, Pi), cl, 3);
        end;
      end;
      if step = 1450 then NextLevel;
    end;
    41: begin
      if step = -25 then PlayMusic('Ominous Intro.mp3');
      if step>=0 then begin
        if step mod 25 = 0 then begin
          for i:= 0 to 3 + step div 500 do begin
            p:= GetEdge(random(2*(w + h)));
            v:= GetNormalVel(p, 1, 2, 1);
            SpawnBall(vec(p), v, clblue, 3 + random(1+step div 500));
          end;
          p:= GetEdge(random(2*(w + h)));
          v:= GetNormalVel(p, 4, 6, 1);
          SpawnBall(vec(p), v, clblue, 6 + random(2+step div 500));
        end;
      end;
      if step = 1500 then NextLevel;
    end;
    42: begin
      if step = -25 then PlayMusic('Rising Game.mp3');
      if step>=0 then begin
        if step mod 35 = 0 then begin
          for i:= 0 to 1 do begin
            p:= GetEdge(random(2*(w + h)));
            v:= GetNormalVel(p, 4, 6, 1);
            SpawnBall(vec(p), v, $008080, 3 + random(2) + step div 500);
          end;
        end;
      end;
      if step = 1500 then NextLevel;
    end;
    43: begin
      case step of
        -25: begin
          SpawnLine(Point(0, 0), Point(w, 0), clred, 3, 100, DirectionalAim, 0, 0, 0);
          SpawnLine(Point(0, h), Point(w, h), clred, 3, 100, DirectionalAim, 0, 0, 0);
          PlayMusic('Eighties Action.mp3');
        end;
        0, 240: begin
          setlength(maze, 4);
          maze[0]:= Arr([2, 0, 0, 2]);
          maze[1]:= Arr([2, 1, 2, 2]);
          maze[2]:= Arr([1, 2, 2, 2]);
          maze[3]:= Arr([2, 0, 2, 0]);
          SpawnGrid(maze, vec(-5, 0));
        end;
        120, 480: begin
          setlength(Maze, 5);
          maze[0]:= Arr([2, 1, 0, 2, 0]);
          maze[1]:= Arr([2, 1, 2, 0, 2]);
          maze[2]:= Arr([1, 2, 1, 1, 2]);
          maze[3]:= Arr([2, 3, 1, 2, 2]);
          maze[4]:= Arr([2, 0, 2, 0, 2]);
          SpawnGrid(maze, vec(-5, 0));
        end;
        360: begin
          setlength(Maze, 6);
          maze[0]:= Arr([0, 2, 0, 2, 0, 2]);
          maze[1]:= Arr([2, 0, 2, 2, 2, 2]);
          maze[2]:= Arr([3, 1, 0, 2, 2, 2]);
          maze[3]:= Arr([2, 3, 1, 2, 2, 0]);
          maze[4]:= Arr([2, 2, 2, 2, 1, 2]);
          maze[5]:= Arr([2, 0, 2, 1, 0, 2]);
          SpawnGrid(maze, vec(-5, 0));
        end;
        600: begin
          setlength(Maze, 7);
          maze[0]:= Arr([0, 0, 0, 0, 2, 0, 2]);
          maze[1]:= Arr([3, 1, 1, 2, 0, 2, 2]);
          maze[2]:= Arr([2, 1, 2, 1, 3, 0, 2]);
          maze[3]:= Arr([3, 0, 3, 2, 0, 3, 0]);
          maze[4]:= Arr([2, 3, 2, 1, 3, 2, 2]);
          maze[5]:= Arr([2, 2, 0, 2, 0, 2, 2]);
          maze[6]:= Arr([2, 0, 2, 0, 2, 0, 2]);
          SpawnGrid(maze, vec(-5, 0));
        end;
        900: NextLevel;
      end;
    end;
    44: begin
      case step of
        -25: begin
          SpawnLine(Point(0, 0), Point(w, 0), clred, 3, 100, DirectionalAim, 0, 0, 0);
          SpawnLine(Point(0, h), Point(w, h), clred, 3, 100, DirectionalAim, 0, 0, 0);
          if nomusicyet then PlayMusic('Eighties Action.mp3');
        end;
        0: begin
          setlength(maze, 6);
          maze[0]:= Arr([1, 0, 0, 0, 0, 1]);
          maze[1]:= Arr([1, 0, 1, 1, 0, 1]);
          maze[2]:= Arr([0, 0, 1, 0, 0, 1]);
          maze[3]:= Arr([1, 1, 1, 0, 1, 1]);
          maze[4]:= Arr([1, 0, 0, 0, 1, 0]);
          maze[5]:= Arr([1, 0, 1, 0, 0, 0]);
          SpawnBlockMaze(maze, vec(-5, 0));
        end;
        150: begin
          setlength(maze, 7);
          maze[0]:= Arr([1, 0, 0, 0, 0, 1]);
          maze[1]:= Arr([1, 0, 1, 1, 0, 0, 1]);
          maze[2]:= Arr([1, 0, 0, 0, 1, 0]);
          maze[3]:= Arr([1, 0, 1, 0, 0, 1]);
          maze[4]:= Arr([0, 1, 1, 1, 0, 0, 1]);
          maze[5]:= Arr([1, 0, 0, 0, 1, 0, 1]);
          maze[6]:= Arr([0, 0, 1, 0, 0, 0, 1]);
          SpawnBlockMaze(maze, vec(-5, 0));
        end;
        300: begin
          setlength(maze, 9);
          maze[0]:= Arr([1, 0, 0, 0, 1, 0, 0, 0, 1]);
          maze[1]:= Arr([1, 0, 1, 0, 0, 0, 1, 1, 0]);
          maze[2]:= Arr([1, 0, 0, 1, 1, 0, 0, 0, 0]);
          maze[3]:= Arr([1, 1, 0, 0, 0, 1, 1, 1, 0]);
          maze[4]:= Arr([0, 0, 1, 1, 0, 0, 0, 0, 1]);
          maze[5]:= Arr([1, 0, 0, 0, 1, 0, 1, 1, 0]);
          maze[6]:= Arr([1, 1, 1, 0, 1, 0, 0, 0, 1]);
          maze[7]:= Arr([0, 0, 1, 0, 0, 1, 1, 0, 1]);
          maze[8]:= Arr([1, 0, 0, 1, 0, 0, 0, 0, 1]);
          SpawnBlockMaze(maze, vec(-5, 0));
        end;
        450: begin
          setlength(maze, 8);
          maze[0]:= Arr([0, 0, 1, 0, 0, 0, 0, 1]);
          maze[1]:= Arr([0, 1, 0, 0, 1, 1, 0, 1]);
          maze[2]:= Arr([0, 1, 0, 1, 0, 0, 0, 1]);
          maze[3]:= Arr([1, 0, 0, 1, 0, 1, 0, 1]);
          maze[4]:= Arr([1, 0, 1, 1, 0, 0, 1, 0]);
          maze[5]:= Arr([1, 0, 0, 0, 1, 0, 0, 1]);
          maze[6]:= Arr([0, 1, 1, 0, 0, 1, 0, 1]);
          maze[7]:= Arr([0, 0, 0, 0, 1, 0, 0, 0]);
          SpawnBlockMaze(maze, vec(-5, 0));
        end;
        800: NextLevel;
      end;
    end;
    45: begin
      case step of
        -25: PlayMusic('11-Titan.mp3');
        0: SpawnBall(vec(500, 700), vec(0, -4), $008080, 50);
        100: begin
          Balls[0].vX:= 0;
          Balls[0].vY:= 0;
        end;
        110..150, 250..300, 900..950: if step mod 5 = 0 then SpawnBall(center, AimAtPlayer(Point(round(center.X), round(center.Y)), 6, 9, 0.1), $008080, 3+random(3));
        200..240: SpawnCircle(center, 6, clred, 3, 6, step/50);
        450, 470, 490: SpawnCircle(center, 6, clred, 3, 45, step);
        530, 700, 800: SpawnCircle(center, 6, $008080, 3, 10, step);
        1001..1100: begin
          if step mod 2 = 0 then dec(Balls[0].r);
          for i:= 0 to 1 do SpawnBall(center, AimAtPlayer(Point(500, 300), 6, 9, Pi), clred, 3);
        end;
      end;
      if step = 1250 then NextLevel;
    end;
    46: begin
      if step = -25 then PlayMusic('Rising.mp3');
      if step>=0 then begin
        if step mod 10 - step div 400 = 0 then begin
          p:= GetEdge(random(2*(w + h)));
          v:= GetNormalVel(p, 3, 6, 0.1);
          SpawnBall(vec(p), v, cllime, 5);
          p:= GetEdge(random(2*(w + h)));
          v:= AimAtPlayer(p, 3, 6, 0.1);
          SpawnBall(vec(p), v, claqua, 5);
        end;
      end;
      if step = 1500 then NextLevel;
    end;
    47: begin
      if step = -25 then PlayMusic('Rising Game.mp3');
      if step>=0 then begin
        if step mod 35 - step div 200 = 0 then begin
          p:= GetEdge(random(2*(w + h)));
          v:= AimAtPlayer(p, 3, 6, 0.1);
          SpawnBall(vec(p), v, clyellow, 5);
          p:= GetEdge(random(2*(w + h)));
          v:= AimAtPlayer(p, 3, 6, 0.1);
          SpawnBall(vec(p), v, $008080, 5);
        end;
      end;
      if step = 1500 then NextLevel;
    end;
    48: begin
      case step of
        -25: begin
          SpawnLine(Point(0, 0), Point(w, 0), clred, 3, 100, DirectionalAim, 0, 0, 0);
          SpawnLine(Point(0, h), Point(w, h), clred, 3, 100, DirectionalAim, 0, 0, 0);
          SpawnLine(Point(0, 0), Point(0, h), clred, 3, 60, DirectionalAim, 0, 0, 0);
          SpawnLine(Point(w, 0), Point(w, h), clred, 3, 60, DirectionalAim, 0, 0, 0);
          PlayMusic('Rites.mp3');
        end;
        0: begin
          SpawnLine(Point(w, 210), Point(w+6100, 210), $f4f4f4, 7, 302, DirectionalAim, -5, 0, 0);
          SpawnLine(Point(w, 390), Point(w+6100, 390), $f4f4f4, 7, 302, DirectionalAim, -5, 0, 0);
          SpawnLine(Point(w, -300), Point(w, 210), $f4f4f4, 7, 20, DirectionalAim, -5, 0, 0);
          SpawnLine(Point(w, h+300), Point(w, 390), $f4f4f4, 7, 20, DirectionalAim, -5, 0, 0);
          SpawnStrMaze(['D                                    Da      Da    D',
                        '                  ___ ___ ___     __ Da ____ Da __ D',
                        ' ^ _ ^ _  ^_^_^_^_                Da Da  Da  Da  D D',
                        '                    ^^^ ^^^ ^^^   Da ^^^ Da ^^^^ D^^',
                        'D                                 Da     Da      D  '], vec(-5, 0));
        end;
        1400: NextLevel;
      end;
    end;
    49: case step of
      -25: begin
          SpawnLine(Point(0, 0), Point(w, 0), clred, 3, 100, DirectionalAim, 0, 0, 0);
          SpawnLine(Point(0, h), Point(w, h), clred, 3, 100, DirectionalAim, 0, 0, 0);
          if nomusicyet then PlayMusic('Rites.mp3');
        end;
        0, 100, 200: begin
          SpawnGrayLine(Point(w, 250), Point(w+500, 250), $f0, 16, 3, 50, DirectionalAim, -6, 0, 0);
          SpawnGrayLine(Point(w, 350), Point(w+500, 350), $f0, 16, 3, 50, DirectionalAim, -6, 0, 0);
          SpawnLine(Point(w, -100), Point(w, 250), $f0f0f0, 3, 35, DirectionalAim, -6, 0, 0);
          SpawnLine(Point(w, h+100), Point(w, 350), $f0f0f0, 3, 35, DirectionalAim, -6, 0, 0);
          SpawnLine(Point(w+500, -100), Point(w+500, 250), $ffffff, 3, 35, DirectionalAim, -6, 0, 0);
          SpawnLine(Point(w+500, h+100), Point(w+500, 350), $ffffff, 3, 35, DirectionalAim, -6, 0, 0);
        end;
        300, 380, 460: begin
          SpawnGrayLine(Point(w+100, 600), Point(w+100, 100), $e0, 16, 3, 50, DirectionalAim, -6, 0, 0);
          SpawnGrayLine(Point(w+200, 500), Point(w+200, 0), $e0, 16, 3, 50, DirectionalAim, -6, 0, 0);
          SpawnLine(Point(w, 100), Point(w+100, 100), $efefef, 3, 10, DirectionalAim, -6, 0, 0);
          SpawnLine(Point(w+200, 500), Point(w+300, 500), $e0e0e0, 3, 10, DirectionalAim, -6, 0, 0);
          SpawnLine(Point(w, 100), Point(w, 600), $efefef, 3, 50, DirectionalAim, -6, 0, 0);
          SpawnLine(Point(w+300, 500), Point(w+300, 0), $e0e0e0, 3, 50, DirectionalAim, -6, 0, 0);
        end;
        660: NextLevel;
    end;
    50: begin
      if length(Balls) > 0 then center:= vec(Balls[0].X, Balls[0].Y);
      case step of
        -25: PlayMusic('11-Titan.mp3');
        0: SpawnBall(vec(500, 700), vec(5, -7), cllime, 50);
        50..100: SpawnBall(center, AimAtPlayer(Point(round(center.X), round(center.Y)), 6, 9, 0.1), cllime, 5);
        {260..300,} 600..650: SpawnBall(center, AimAtPlayer(Point(500, 300), 1, 5, 1), clred, 3);
        150..240, 670..740: SpawnCircle(center, 12, clred, 3, 6, step/50);
        340, 360, 380, 800, 850: SpawnCircle(center, 6, clred, 6, 30, step/50);
        440, 460, 480, 900, 950: SpawnOpenCircle(vec(500, 300), 600, 0, 2*Pi, clred, 3, 30, converge, Player.X, Player.Y, 50);
        1050: SpawnCircle(center, 6, cllime, 4, 30, step);
        1101..1160: begin
          if step mod 2 = 0 then dec(Balls[0].r);
          for i:= 0 to 1 do SpawnBall(center, AimAtPlayer(Point(500, 300), 6, 9, Pi), cllime, 5);
        end;
      end;
      if step = 1350 then NextLevel;
    end;
    51: begin
      case step of
        -25: begin
          SpawnLine(Point(0, 0), Point(w, 0), clred, 3, 100, DirectionalAim, 0, 0, 0);
          SpawnLine(Point(0, h), Point(w, h), clred, 3, 100, DirectionalAim, 0, 0, 0);
          PlayMusic('Eighties Action.mp3');
        end;
        0, 420: begin
          setlength(cmaze, 4);
          cmaze[0]:= CArr(['\', '\', '/', '\']);{\\/\}
          cmaze[1]:= CArr(['\', '/', '/', '/']);{\///}
          cmaze[2]:= CArr(['/', '\', '\', '\']);{/\\\}
          cmaze[3]:= CArr(['/', '\', '/', '\']);{/\/\}
          SpawnCharMaze(cmaze, vec(-5, 0));
        end;
        140, 720: begin
          setlength(cmaze, 4);
          cmaze[0]:= CArr(['/', '\', ' ', '\']);{/\ \}
          cmaze[1]:= CArr(['/', '/', '/', '/']);{////}
          cmaze[2]:= CArr(['\', '/', '/', '\']);{\//\}
          cmaze[3]:= CArr(['\', '\', '/', '\']);{\\/\}
          SpawnCharMaze(cmaze, vec(-5, 0));
        end;
        280: begin
          setlength(cmaze, 5);
          cmaze[0]:= CArr(['\', '/', '\', '/', '\']);{\/\/\}
          cmaze[1]:= CArr(['\', '/', '/', ' ', '\']);{\// \}
          cmaze[2]:= CArr(['/', '\', '\', '/', '/']);{/\\//}
          cmaze[3]:= CArr(['/', '/', '/', '/', ' ']);{////}
          cmaze[4]:= CArr(['\', '\', '/', ' ', ' ']);{\\/}
          SpawnCharMaze(cmaze, vec(-5, 0));
        end;
        580: begin
          setlength(cmaze, 6);
          cmaze[0]:= CArr(['/', '\', ' ', '\', ' ', ' ']); {/\ \  }
          cmaze[1]:= CArr(['/', '/', '\', '\', '\', '\']); {//\\\\}
          cmaze[2]:= CArr(['\', ' ', ' ', '/', '/', '/']); {\  ///}
          cmaze[3]:= CArr(['/', '\', '/', '/', '/', ' ']); {/\/// }
          cmaze[4]:= CArr(['\', '\', '/', '\', '\', ' ']); {\\/\\ }
          cmaze[5]:= CArr(['/', '\', '/', '\', '/', ' ']); {/\/\/ }
          SpawnCharMaze(cmaze, vec(-5, 0));
        end;
        950: NextLevel;
      end;
    end;
    52: begin
      if step = -25 then PlayMusic('Not As It Seems.mp3');
      if step>=0 then begin
        if step mod 13 - step div 200 = 0 then begin
          p:= GetEdge(random(2*(w + h)));
          v:= AimAtPlayer(p, 3, 6, 0.1);
          SpawnBall(vec(p), v, $e7e7e7, 5);
          p:= GetEdge(random(2*(w + h)));
          v:= AimAtPlayer(p, 3, 6, 0.1);
          SpawnBall(vec(p), v, $e0e0e0, 5);
        end;
      end;
      if step = 1500 then NextLevel;
    end;
    53: begin
      case step of
        -25: begin
          SpawnLine(Point(0, 0), Point(w, 0), clred, 3, 100, DirectionalAim, 0, 0, 0);
          SpawnLine(Point(0, h), Point(w, h), clred, 3, 100, DirectionalAim, 0, 0, 0);
          PlayMusic('Movement Proposition.mp3');
        end;
        0, 1240: begin
          setlength(cmaze, 4);
          cmaze[0]:= CArr(['/', ' ', '_', ' ', ' ', ' ', '_', ' ', '\']);{}
          cmaze[1]:= CArr(['\', '/', ' ', '\', '_', '/', ' ', '\', '/']);{}
          cmaze[2]:= CArr([' ', ' ', '|', ' ', ' ', ' ', '|', ' ', ' ']);{}
          cmaze[3]:= CArr([' ', ' ', '|', ' ', ' ', ' ', '|', ' ', ' ']);{}
          SpawnCharMaze(cmaze, vec(-5, 0));

          setlength(cmaze, 4);
          cmaze[0]:= CArr([' ', ' ', ' ', ' ', '|', ' ', ' ', ' ', ' ']);{}
          cmaze[1]:= CArr([' ', ' ', ' ', ' ', '|', ' ', ' ', ' ', ' ']);{}
          cmaze[2]:= CArr(['/', '^', '^', '\', ' ', '/', '^', '^', '\']);{}
          cmaze[3]:= CArr(['\', ' ', ' ', ' ', '^', ' ', ' ', ' ', '/']);{}
          SpawnCharMaze(cmaze, vec(5, 0));
        end;
        300, 940: begin
          setlength(cmaze, 4);
          cmaze[0]:= CArr(['/', ' ', ' ', '/', '_', '\', ' ', ' ', '\']);{}
          cmaze[1]:= CArr(['\', '_', '/', '/', ' ', '\', '\', '_', '/']);{}
          cmaze[2]:= CArr([' ', ' ', ' ', '^', '|', '^', ' ', ' ', ' ']);{}
          cmaze[3]:= CArr([' ', ' ', ' ', ' ', '|', ' ', ' ', ' ', ' ']);{}
          SpawnCharMaze(cmaze, vec(-5, 0));

          setlength(cmaze, 4);
          cmaze[0]:= CArr([' ', ' ', ' ', ' ', '|', ' ', ' ', ' ', ' ']);{}
          cmaze[1]:= CArr([' ', ' ', ' ', '_', '|', '_', ' ', ' ', ' ']);{}
          cmaze[2]:= CArr(['/', '^', '\', '\', ' ', '/', '/', '^', '\']);{}
          cmaze[3]:= CArr(['\', ' ', ' ', '\', '^', '/', ' ', ' ', '/']);{}
          SpawnCharMaze(cmaze, vec(5, 0));
        end;
        620: begin
          setlength(cmaze, 6);
          cmaze[0]:= CArr(['\', '/', '_', ' ', '/', '\', ' ', '_', '\', '/']);{}
          cmaze[1]:= CArr(['/', ' ', '/', '/', '|', '|', '\', '\', ' ', '\']);{}
          cmaze[2]:= CArr(['\', '_', '\', '_', '\', '/', '_', '/', ' ', '/']);{}
          cmaze[3]:= CArr([' ', ' ', ' ', '|', ' ', ' ', '|', ' ', ' ', ' ']);{}
          cmaze[4]:= CArr([' ', ' ', ' ', '|', ' ', ' ', '|', ' ', ' ', ' ']);{}
          cmaze[5]:= CArr([' ', ' ', ' ', '|', ' ', ' ', '|', ' ', ' ', ' ']);{}
          SpawnCharMaze(cmaze, vec(-5, 0));

          setlength(cmaze, 6);
          cmaze[0]:= CArr([' ', ' ', ' ', '|', ' ', ' ', '|', ' ', ' ', ' ']);{}
          cmaze[1]:= CArr([' ', ' ', ' ', '|', ' ', ' ', '|', ' ', ' ', ' ']);{}
          cmaze[2]:= CArr([' ', ' ', ' ', '|', ' ', ' ', '|', ' ', ' ', ' ']);{}
          cmaze[3]:= CArr(['/', '^', '/', '^', '/', '\', '^', '\', '^', '\']);{}
          cmaze[4]:= CArr(['\', ' ', '\', '\', '|', '|', '/', '/', ' ', '/']);{}
          cmaze[5]:= CArr(['/', '\', '^', ' ', '\', '/', ' ', '^', '/', '\']);{}
          SpawnCharMaze(cmaze, vec(5, 0));
        end;
        1640: NextLevel;
      end;
    end;
    54: begin
      case step of
        -25: begin
          SpawnLine(Point(0, -200), Point(w, -200), clred, 3, 100, DirectionalAim, 0, 0.3, 0);
          SpawnLine(Point(0, h+200), Point(w, h+200), clred, 3, 100, DirectionalAim, 0, -0.3, 0);
          SpawnLine(Point(w, 0), Point(w, h), clred, 3, 60, DirectionalAim, -0.3, 0, 0);
          SpawnLine(Point(0, 0), Point(0, h), clred, 3, 60, DirectionalAim, 0.3, 0, 0);
          PlayMusic('Ominous Intro.mp3');
        end;
        0..999: begin
          if step mod 5 = 0 then begin
            p:= GetEdge(random(2*(w + h)));
            v:= GetNormalVel(p, 1, 2, 0.1);
            SpawnBall(vec(p), v, clblue, 3);
          end;
        end;
        1000: NextLevel;
      end;
    end;
    55: begin
      if length(Balls) > 0 then center:= vec(Balls[0].X, Balls[0].Y);
      case step of
        -25: PlayMusic('11-Titan.mp3');
        0: SpawnBall(vec(500, 700), vec(0, -9), claqua, 50);
        50..100, 800..850: SpawnBall(center, AimAtPlayer(Point(round(center.X), round(center.Y)), 6, 9, 0.1), claqua, 5);
        250..300, 910..920: SpawnBall(center, AimAtPlayer(Point(500, 300), 1, 5, 1), claqua, 4);
        120..200, 880..900, 930..950: SpawnCircle(center, 12, clred, 3, 6, step/50);
        350, 380, 1000, 1040, 1080: SpawnBall(center, vec(0, -center.Y/50), clred, 10);
        400: SpawnLine(Point(0, 0), Point(w, 0), claqua, 4, 100, AimAtPlayer, 5, 5, 0);
        430, 1050, 1090, 1130: SpawnLine(Point(0, 0), Point(w, 0), clred, 3, 90, GetNormalVel, 4, 8, 3);
        600, 630, 660: SpawnCircle(center, 6, claqua, 4, 30, step);
        1201..1300: begin
          if Balls[0].r>3 then begin
            if step mod 2 = 0 then dec(Balls[0].r);
            for i:= 0 to 1 do SpawnBall(center, AimAtPlayer(Point(500, 300), 6, 9, Pi), claqua, 5);
          end;
        end;
      end;
      if step = 1450 then NextLevel;
    end;
    56: begin
      case step of
        -25: begin
          SpawnLine(Point(0, 0), Point(w, 0), clred, 3, 100, DirectionalAim, 0, 0, 0);
          SpawnLine(Point(0, h), Point(w, h), clred, 3, 100, DirectionalAim, 0, 0, 0);
          PlayMusic('Eighties Action.mp3');
        end;
        0: begin
          SpawnStrMaze(['= =a',
                        '|| /',
                        'D=aa',
                        'D=^a'], vec(-5, 0));
        end;
        140: SpawnStrMaze(['/=\ a',
                           '|  /a',
                           '_==D/',
                           '/==/a',
                           '\  ^a'], vec(-5, 0));

        280: SpawnStrMaze(['_aa  \',
                           'D/_aa/',
                           '\/_^/\',
                           '/a ^||',
                           '|^a_//',
                           'D/\ \/'], vec(-5, 0));

        420, 800: SpawnStrMaze(['| ==a __a =__Da',
                                ' | _a Daa =a =a',
                                '|a _^D|a_==a aa',
                                '| =aa aa  __Daa',
                                'D==a =a ^D  ^a'], vec(-5, 0));
        1250: NextLevel;
      end;
    end;
    57: begin
      if step = -25 then PlayMusic('Not As It Seems.mp3');
      if step>=0 then begin
        if step mod 15 - step div 200 = 0 then begin
          p:= GetEdge(random(2*(w + h)));
          v:= AimAtPlayer(p, 3, 6, 0.1);
          SpawnBall(vec(p), v, Gray($e0 + random(16)), 5);
          p:= GetEdge(random(2*(w + h)));
          v:= AimAtPlayer(p, 3, 6, 0.1);
          SpawnBall(vec(p), v, Gray($f0 + random(16)), 5);
        end;
      end;
      if step = 1500 then NextLevel;
    end;
    58: begin
      case step of
        -25: begin
          SpawnLine(Point(0, 0), Point(w, 0), clred, 3, 100, DirectionalAim, 0, 0, 0);
          SpawnLine(Point(0, h), Point(w, h), clred, 3, 100, DirectionalAim, 0, 0, 0);
          PlayMusic('Movement Proposition.mp3');
        end;
        0, 200:
           SpawnStrMaze(['D  /',
                         'D //',
                         '\//\',
                         '// a',
                         '/  a'], vec(-5, 0));

        1, 201, 601:
           SpawnStrMaze(['\  a',
                         '\\ a',
                         '/\\/',
                         'D \\',
                         'D  \'], vec(5, 0));

        100, 700:
             SpawnStrMaze(['\  a',
                           '\\ a',
                           '/\\/',
                           'D \\',
                           'D  \'], vec(-5, 0));

        101: SpawnStrMaze(['D  /',
                           'D //',
                           '\//\',
                           '// a',
                           '/  a'], vec(5, 0));

        350, 600: begin
          SpawnLine(Point(w, 0), Point(w, h-120), clred, 3, 50, DirectionalAim, -5, 0, 0);
          SpawnOpenCircle(vec(w, 300), 180, 0, Pi/2, clred, 3, 18, DirectionalAim, -5, 0, 0);
          SpawnOpenCircle(vec(w, 300), 300, 0, Pi/2, clred, 3, 30, DirectionalAim, -5, 0, 0);
          SpawnOpenCircle(vec(w + 480, 300), 180, Pi, 3*Pi/2, clred, 3, 18, DirectionalAim, -5, 0, 0);
          SpawnOpenCircle(vec(w + 480, 300), 300, Pi, 3*Pi/2, clred, 3, 30, DirectionalAim, -5, 0, 0);
          SpawnLine(Point(w + 480, 120), Point(w + 480, h), clred, 3, 50, DirectionalAim, -5, 0, 0);
        end;
        351: begin
          SpawnLine(Point(0, 0), Point(0, h-120), clred, 3, 50, DirectionalAim, 5, 0, 0);
          SpawnOpenCircle(vec(0, 300), 180, Pi, Pi/2, clred, 3, 18, DirectionalAim, 5, 0, 0);
          SpawnOpenCircle(vec(0, 300), 300, Pi, Pi/2, clred, 3, 30, DirectionalAim, 5, 0, 0);
          SpawnOpenCircle(vec(-480, 300), 180, 2*Pi, 3*Pi/2, clred, 3, 18, DirectionalAim, 5, 0, 0);
          SpawnOpenCircle(vec(-480, 300), 300, 2*Pi, 3*Pi/2, clred, 3, 30, DirectionalAim, 5, 0, 0);
          SpawnLine(Point(-480, 120), Point(-480, h), clred, 3, 50, DirectionalAim, 5, 0, 0);
        end;
        450: begin
          SpawnLine(Point(w, h), Point(w, 120), clred, 3, 50, DirectionalAim, -5, 0, 0);
          SpawnOpenCircle(vec(w, 300), 180, 0, -Pi/2, clred, 3, 18, DirectionalAim, -5, 0, 0);
          SpawnOpenCircle(vec(w, 300), 300, 0, -Pi/2, clred, 3, 30, DirectionalAim, -5, 0, 0);
          SpawnOpenCircle(vec(w + 480, 300), 180, Pi, Pi/2, clred, 3, 18, DirectionalAim, -5, 0, 0);
          SpawnOpenCircle(vec(w + 480, 300), 300, Pi, Pi/2, clred, 3, 30, DirectionalAim, -5, 0, 0);
          SpawnLine(Point(w + 480, h-120), Point(w + 480, 0), clred, 3, 50, DirectionalAim, -5, 0, 0);
        end;
        451, 701: begin
          SpawnLine(Point(0, h), Point(0, 120), clred, 3, 50, DirectionalAim, 5, 0, 0);
          SpawnOpenCircle(vec(0, 300), 180, Pi, 3*Pi/2, clred, 3, 18, DirectionalAim, 5, 0, 0);
          SpawnOpenCircle(vec(0, 300), 300, Pi, 3*Pi/2, clred, 3, 30, DirectionalAim, 5, 0, 0);
          SpawnOpenCircle(vec(-480, 300), 180, 0, Pi/2, clred, 3, 18, DirectionalAim, 5, 0, 0);
          SpawnOpenCircle(vec(-480, 300), 300, 0, Pi/2, clred, 3, 30, DirectionalAim, 5, 0, 0);
          SpawnLine(Point(-480, h-120), Point(-480, 0), clred, 3, 50, DirectionalAim, 5, 0, 0);
        end;
        950: NextLevel;
      end;
    end;
    59: begin
      if step = -25 then PlayMusic('Not As It Seems.mp3');
      if step>=0 then begin
        if step mod 27 = 0 then begin
          for i:= 0 to 1 + step div 600 do begin
            p:= GetEdge(random(2*(w + h)));
            v:= AimAtPlayer(p, 2, 6, 1);
            SpawnBall(vec(p), v, Gray($a0 + random(16)), 5);
            p:= GetEdge(random(2*(w + h)));
            v:= GetNormalVel(p, 2, 6, 1);
            SpawnBall(vec(p), v, Gray($b0 + random(16)), 5);
          end;
        end;
      end;
      if step = 1500 then NextLevel;
    end;
    60: begin
      if length(Balls) > 0 then center:= vec(Balls[0].X, Balls[0].Y);
      case step of
        -25: PlayMusic('11-Titan.mp3');
        0: SpawnBall(vec(500, 700), vec(0, -9), clblue, 50);
        50..100, 600..650: SpawnBall(center, AimAtPlayer(Point(round(center.X), round(center.Y)), 6, 15, 0.1), claqua, 5);
        250..300: SpawnBall(center, AimAtPlayer(Point(500, 300), 1, 5, 1), $ff00ff, 4);
        120..200: SpawnCircle(center, 12, clred, 3, 6, step/50);
        350, 370, 390, 700, 720, 740, 760: SpawnCircle(center, 6, clred, 3, 30, step);
        450, 490, 800, 860, 920: SpawnBall(center, vec(0, -center.Y/50), clred, 10);
        500, 540, 850, 910, 970: SpawnLine(Point(0, 0), Point(w, 0), clred, 3, 90, GetNormalVel, 4, 8, 3);
        1051..1150: begin
          if Balls[0].r>3 then begin
            if step mod 2 = 0 then dec(Balls[0].r);
            for i:= 0 to 1 do SpawnBall(center, AimAtPlayer(Point(500, 300), 6, 9, Pi), clblue, 3);
          end;
        end;
      end;
      if step = 1300 then NextLevel;
    end;
    61: begin
      if step = -25 then PlayMusic('Not As It Seems.mp3');
      if step>=0 then begin
        if step mod 35 - step div 200 = 0 then begin
          p:= GetEdge(random(2*(w + h)));
          v:= AimAtPlayer(p, 3, 6, 0.1);
          SpawnBall(vec(p), v, Gray($a0 + random(16)), 5);
          p:= GetEdge(random(2*(w + h)));
          v:= AimAtPlayer(p, 3, 6, 0.1);
          SpawnBall(vec(p), v, Gray($b0 + random(16)), 5);
          p:= GetEdge(random(2*(w + h)));
          v:= GetNormalVel(p, 3, 6, 0.1);
          SpawnBall(vec(p), v, $ff00ff, 3);
        end;
      end;
      if step = 1500 then NextLevel;
    end;
    62: begin
      case step of
        -25: begin
          SpawnLine(Point(0, 0), Point(w, 0), clred, 3, 100, DirectionalAim, 0, 0, 0);
          SpawnLine(Point(0, h), Point(w, h), clred, 3, 100, DirectionalAim, 0, 0, 0);
          PlayMusic('Eighties Action.mp3');
        end;
        0: SpawnStrMaze(['|  aaa a a a aaa __aa a a a a a a a',
                         '|a^D_Daaaaaaa_aaa __Daaaaa aaaaa a a',
                         'a a__aa a _a aa a___aaaaaa^^Da aa a',
                         '|aa aa//\\a^aaaaa  aa___a |aa ^\^^^^D',
                         'Da =DDDDaaa_aaaaa ^aa____D| ^^^D^^^a',
                         '|^^D_DDDaa _a_aa ^ ^Da   _a ^^D^^^D^^D',
                         '=_D_Da aaa^aaa^a^^^aaa ^^D^^^a ^^D^^D^D',
                         'Da^a^\^^a ^a aaa ^^^Da^ ^^^D^^^^a^ ^^a',
                         'a a a ^^D^^a ^a ^^^aa ^^^ ^^^^^ ^^^^ ^D'], vec(-2, 0));
        1650: NextLevel;
      end;
    end;
    63: begin
      case step of
        -25: begin
          SpawnLine(Point(0, 0), Point(w, 0), clred, 3, 100, DirectionalAim, 0, 0, 0);
          SpawnLine(Point(0, h), Point(w, h), clred, 3, 100, DirectionalAim, 0, 0, 0);
          PlayMusic('Not As It Seems.mp3');
        end;
        0: SpawnStrMaze(['Da    a   a a ____aa',
                         '|a ^^^a ^^aa__D____D',
                         '| ===a^==aa__aa a aa',
                         '|a ___a  ^_Daaaaaaaa',
                         'aa    a ^^ a a a a a'], vec(-5, 0));
        1..500: if step mod 15 = 0 then begin
          p:= GetEdge(random(2*(w + h)));
          v:= AimAtPlayer(p, 2, 6, 1);
          SpawnBall(vec(p), v, $afafaf, 5);
          p:= GetEdge(random(2*(w + h)));
          v:= GetNormalVel(p, 2, 6, 1);
          SpawnBall(vec(p), v, $bfbfbf, 5);
        end;
        700: NextLevel;
      end;
    end;
    64: begin
      case step of
        -25: begin
          SpawnLine(Point(0, 0), Point(w, 0), clred, 3, 100, DirectionalAim, 0, 0, 0);
          SpawnLine(Point(0, h), Point(w, h), clred, 3, 100, DirectionalAim, 0, 0, 0);
          PlayMusic('Movement Proposition.mp3');
        end;
        0: begin
          SpawnStrMaze(['/   /__\    /__\   \',
                        '\__//  \\__//  \\__/',
                        '    D  a    D  a    ',
                        '    D  a    D  a    '], vec(-5, 0));

          SpawnStrMaze(['    D  a    D  a    ',
                        '    D  a    D  a    ',
                        '/^^\\  //^^\\  //^^\',
                        '\   \^^/    \^^/   /'], vec(5, 0));
        end;
        650: begin
          SpawnStrMaze(['   /__\_/__\    / \       ',
                        '   \__\ /__/   //^\\__/^\ ',
                        '      a^D     //   \__/^\\',
                        '      a D     /          \'], vec(-5, 0));

          SpawnStrMaze(['         /\       a D   ',
                        ' /^^^\/^^/\\      a_D   ',
                        '//^^^\/^^  \\  /^^/ \^^\',
                        '/           \  \^^/^\^^/'], vec(5, 0));
        end;
        1550: NextLevel;
      end;
    end;
    65: begin
      if length(Balls) > 0 then center:= vec(Balls[0].X, Balls[0].Y);
      if length(Balls) > 1 then center2:= vec(Balls[1].X, Balls[1].Y);
      case step of
        -25: PlayMusic('11-Titan.mp3');
        0: for i:= 0 to 1 do SpawnBall(vec(500, 700), vec(0, -4), clyellow, 50);
        100, 600: begin
          Balls[0].vY:= 0;
          Balls[0].vX:= -4;
          Balls[1].vY:= 0;
          Balls[1].vX:= 4;
        end;
        150, 650: begin
          Balls[0].vX:= 0;
          Balls[1].vX:= 0;
        end;
        160..200, 660..700: begin
          SpawnBall(center, AimAtPlayer(Point(round(center.X), round(center.Y)), 6, 15, 0.1), clred, 3);
          SpawnBall(center2, AimAtPlayer(Point(round(center2.X), round(center2.Y)), 6, 15, 0.1), clred, 3);
        end;
        230..300, 730..800: begin
          SpawnBall(center, AimAtPlayer(Point(round(center.X), round(center.Y)), 6, 9, 1), clred, 3);
          SpawnBall(center2, AimAtPlayer(Point(round(center2.X), round(center2.Y)), 6, 9, 1), clred, 3);
        end;
        320..330: SpawnCircle(center, 12, clred, 3, 6, step/50);
        340..350: SpawnCircle(center2, 12, clred, 3, 6, -step/50);
        380..450, 830..900, 930..1000: begin
          SpawnCircle(center, 12, clred, 3, 6, step/50);
          SpawnCircle(center2, 12, clred, 3, 6, -step/50);
        end;
        480, 500, 520, 1040, 1060, 1080, 1100: begin
          SpawnCircle(center, 6, clred, 3, 30, step);
          SpawnCircle(center2, 6, clred, 3, 30, step);
        end;
        1201..1300: begin
          if step mod 2 = 0 then begin
            dec(Balls[0].r);
          end;
          for i:= 0 to 1 do begin
            SpawnBall(center, AimAtPlayer(Point(round(center.X), round(center.Y)), 6, 9, Pi), clred, 3);
            SpawnBall(center2, AimAtPlayer(Point(round(center2.X), round(center2.Y)), 6, 9, Pi), clred, 3);
            SpawnBall(center, AimAtPlayer(Point(round(center.X), round(center.Y)), 6, 9, Pi), clred, 3);
            SpawnBall(center2, AimAtPlayer(Point(round(center2.X), round(center2.Y)), 6, 9, Pi), clred, 3);
          end;
        end;
      end;
      if step = 1400 then NextLevel;
    end;
    66: begin
      case step of
        -25: PlayMusic('Opening Theme B.mp3');
        0, 25, 50, 75, 100, 125, 150, 175, 200, 225, 250, 275, 300, 325, 350, 375, 400: begin
          SpawnTurning(vec(500, -200), 10, 254, 234, 254, 254, 243, 243, 3, AimAtPlayer, 6, 6, 0);
          SpawnTurning(vec(500, -200), 10, 254, 234, 190, 190, 243, 243, 3, AimAtPlayer, 6, 6, 0);
        end;

        500, 550, 600, 650, 700, 750, 800, 850, 900: begin
          SpawnTurning(vec(-200, 300), 10, 254, 234, 254, 254, 223, 223, 3, AimAtPlayer, 6, 6, 0);
          SpawnTurning(vec(-200, 300), 10, 254, 234, 190, 190, 223, 223, 3, AimAtPlayer, 6, 6, 0);
        end;
        525, 575, 625, 675, 725, 775, 825, 875: begin
          SpawnTurning(vec(1200, 300), 10, 254, 234, 254, 254, 223, 223, 3, AimAtPlayer, 6, 6, 0);
          SpawnTurning(vec(1200, 300), 10, 254, 234, 190, 190, 223, 223, 3, AimAtPlayer, 6, 6, 0);
        end;

        1000, 1100, 1200, 1300, 1400: begin
          SpawnTurning(vec(-200, 300), 10, 254, 234, 254, 254, 223, 223, 3, AimAtPlayer, 6, 6, 0);
          SpawnTurning(vec(-200, 300), 10, 254, 234, 190, 190, 223, 223, 3, AimAtPlayer, 6, 6, 0);
        end;
        1050, 1150, 1250, 1350: begin
          SpawnTurning(vec(1200, 300), 10, 254, 234, 254, 254, 223, 223, 3, AimAtPlayer, 6, 6, 0);
          SpawnTurning(vec(1200, 300), 10, 254, 234, 190, 190, 223, 223, 3, AimAtPlayer, 6, 6, 0);
        end;
        1025, 1125, 1225, 1325: begin
          SpawnTurning(vec(500, -200), 10, 254, 234, 254, 254, 223, 223, 3, AimAtPlayer, 6, 6, 0);
          SpawnTurning(vec(500, -200), 10, 254, 234, 190, 190, 223, 223, 3, AimAtPlayer, 6, 6, 0);
        end;
        1075, 1175, 1275, 1375: begin
          SpawnTurning(vec(500, 800), 10, 254, 234, 254, 254, 223, 223, 3, AimAtPlayer, 6, 6, 0);
          SpawnTurning(vec(500, 800), 10, 254, 234, 190, 190, 223, 223, 3, AimAtPlayer, 6, 6, 0);
        end;

        1500: NextLevel;
      end;
    end;
    67:begin
      if step = -25 then PlayMusic('Opening Theme B.mp3');
      if (step >= 0) then if step mod (60) = 0 then begin
        SpawnTurning(vec(-200, -200), 33, 234, 234, 254, 221, 218, 218, 3, AimAtPlayer, 5, 5, 0);
        SpawnTurning(vec(-200, -200), 33, 234, 234, 190, 157, 218, 218, 3, AimAtPlayer, 5, 5, 0);

        SpawnTurning(vec(-200, 800), 33, 234, 234, 254, 221, 218, 218, 3, AimAtPlayer, 5, 5, 0);
        SpawnTurning(vec(-200, 800), 33, 234, 234, 190, 157, 218, 218, 3, AimAtPlayer, 5, 5, 0);
      end;
      if step = 900 then NextLevel;
    end;
    
  end;
end;

procedure TForm1.Timer1Timer(Sender: TObject);
begin
  if not lost then begin
    Script;
    unit1.update;
    CheckCollision;
  end;
  Draw;
  inc(step);
end;

end.
