{
  Main game unit

  Mefistofel
  24.03.2013
}
unit WorldScene;

interface

Uses
  _Geometry,
  Frost.Forms,
  Frost.GL,     
  Frost.Utils,
  Frost.Renderers,
  Frost.Engine,
  Planetoid,
  BaseEnemy,
  DiscEnemy,
  StarField,
  Bullet,
  Capsule,
  Hero;

{$REGION 'planetar wave Colors'}
const
  MAX_WAVE = 25;
  PLANET_COLORS: Array [0..MAX_WAVE] of TVector3 =  (
        (A : (0.1, 1, 0.1)),
        (A : (0.1, 1, 0.1)),
        (A : (0,0.7,0.2)),
        (A : (0,0.4,0.3)),
        (A : (0,0.2,0.5)),
        (A : (0,0.1,0.9)),
        (A : (0,0.0,1.0)),
        (A : (0.2,0.0,0.8)),
        (A : (0.4,0.0,0.5)),
        (A : (0.6,0.0,0.3)),
        (A : (0.8,0.0,0.1)),
        (A : (0.8,0.1,0.0)),
        (A : (0.6,0.4,0.0)),
        (A : (0.8,0.6,0.1)),
        (A : (0.9,0.8,0.2)),
        (A : (0.9,0.9,0.3)),
        (A : (0.9,0.9,0.6)),
        (A : (0.9,0.9,0.9)),
        (A : (0.4,0.4,0.4)),
        (A : (0.1,0.1,0.1)),
        (A : (0,0.0,0.0)),
        (A : (0.1, 0.2, 0.1)),
        (A : (0.1, 0.4, 0.1)),
        (A : (0.1, 0.6, 0.1)),
        (A : (0.1, 0.8, 0.1)),
        (A : (0.1, 1, 0.1)));  
{$ENDREGION}

type
TWorld = class(TScene)
  private             
    FMouseDeltaX,
    FMouseDeltaY: Integer;
    FStressTime: Single;
    FCameraPosition: TVector3;    
    FStressCameraPosition: TVector3;
    FPointUpdateFrame: Integer;         
    FPoints,
    FCurrentPoints: Integer;
    FEnemyCounter: Integer;
    FNextWaveTimer: Single;
    FWave: Integer;
    FPlanet: TPlanetoid;   
    FHeroObject: TGameObject;   
    FHero: THero;
    function GetMouseDelta: TVector2;   
    procedure CreateAction(Rotation: TMatrix3; Tag: Integer);
  public                                  
    procedure Restart();
    procedure AddPoints(Points: Integer);
    procedure NextWave();       
    procedure StartNextWave();  
    procedure CountEnemies(Count: Integer);
    procedure Stress(Time: Single = 10);
    procedure OnStart; override;
    procedure OnUpdate(delta: Double); override;    
    procedure OnDestroy; override;
    property MouseDelta: TVector2 read GetMouseDelta;
  end;

var
  World: TWorld;
                              
function CreateCubeMesh(Size: Single = 0.2): TMesh;

implementation

{$REGION 'CreateCubeMesh'}
function CreateCubeMesh(Size: Single = 0.2): TMesh;
var
  Vertex:   TVertexes;
  Normals:  TNormals;
  Textures: TTextures;    
  Colors:   TColors;
  Faces: TFaces;
  S: Single;
begin
  S := Size;
  SetLength(Vertex, 24);   
  SetLength(Textures, 24);
  SetLength(Normals, 24);  
  SetLength(Colors, 24);
  SetLength(Faces, 12);
  Vertex[0 ] := Vector3( S, -S,  S); //up
  Vertex[1 ] := Vector3( S,  S,  S);
  Vertex[2 ] := Vector3(-S,  S,  S);
  Vertex[3 ] := Vector3(-S, -S,  S);
  Vertex[4 ] := Vector3( S,  S, -S); //down
  Vertex[5 ] := Vector3( S, -S, -S);
  Vertex[6 ] := Vector3(-S, -S, -S);
  Vertex[7 ] := Vector3(-S,  S, -S);
  Vertex[8 ] := Vector3( S,  S,  S); //forward
  Vertex[9 ] := Vector3( S,  S, -S);
  Vertex[10] := Vector3(-S,  S, -S);
  Vertex[11] := Vector3(-S,  S,  S);
  Vertex[12] := Vector3( S, -S, -S); //backward
  Vertex[13] := Vector3( S, -S,  S);
  Vertex[14] := Vector3(-S, -S,  S);
  Vertex[15] := Vector3(-S, -S, -S);
  Vertex[16] := Vector3( S,  S, -S); //left
  Vertex[17] := Vector3( S,  S,  S);
  Vertex[18] := Vector3( S, -S,  S);
  Vertex[19] := Vector3( S, -S, -S);
  Vertex[20] := Vector3(-S,  S,  S); //right
  Vertex[21] := Vector3(-S,  S, -S);
  Vertex[22] := Vector3(-S, -S, -S);
  Vertex[23] := Vector3(-S, -S,  S);

  Normals[0 ] := Vector3( 0,  0,  1); //up
  Normals[1 ] := Vector3( 0,  0,  1);
  Normals[2 ] := Vector3( 0,  0,  1);
  Normals[3 ] := Vector3( 0,  0,  1);
  Normals[4 ] := Vector3( 0,  0, -1); //down
  Normals[5 ] := Vector3( 0,  0, -1);
  Normals[6 ] := Vector3( 0,  0, -1);
  Normals[7 ] := Vector3( 0,  0, -1);
  Normals[8 ] := Vector3( 0,  1,  0); //forward
  Normals[9 ] := Vector3( 0,  1,  0);
  Normals[10] := Vector3( 0,  1,  0);
  Normals[11] := Vector3( 0,  1,  0);
  Normals[12] := Vector3( 0, -1,  0); //backward
  Normals[13] := Vector3( 0, -1,  0);
  Normals[14] := Vector3( 0, -1,  0);
  Normals[15] := Vector3( 0, -1,  0);
  Normals[16] := Vector3( 1,  0,  0); //left
  Normals[17] := Vector3( 1,  0,  0);
  Normals[18] := Vector3( 1,  0,  0);
  Normals[19] := Vector3( 1,  0,  0);
  Normals[20] := Vector3(-1,  0,  0); //right
  Normals[21] := Vector3(-1,  0,  0);
  Normals[22] := Vector3(-1,  0,  0);
  Normals[23] := Vector3(-1,  0,  0);

  Textures[0 ] := Vector2(0, 0); //up
  Textures[1 ] := Vector2(1, 0);
  Textures[2 ] := Vector2(1, 1);
  Textures[3 ] := Vector2(0, 1);
  Textures[4 ] := Vector2(0, 0); //down
  Textures[5 ] := Vector2(1, 0);
  Textures[6 ] := Vector2(1, 1);
  Textures[7 ] := Vector2(0, 1);
  Textures[8 ] := Vector2(1, 0); //forward
  Textures[9 ] := Vector2(0, 0);
  Textures[10] := Vector2(0, 1);
  Textures[11] := Vector2(1, 1);
  Textures[12] := Vector2(1, 0);
  Textures[13] := Vector2(0, 0); //backward
  Textures[14] := Vector2(0, 1);
  Textures[15] := Vector2(1, 1);
  Textures[16] := Vector2(0, 0); //left
  Textures[17] := Vector2(1, 0);
  Textures[18] := Vector2(1, 1);
  Textures[19] := Vector2(0, 1);
  Textures[20] := Vector2(0, 0); //right
  Textures[21] := Vector2(1, 0);
  Textures[22] := Vector2(1, 1);
  Textures[23] := Vector2(0, 1);
  
  Colors[0 ] := Vector4(0, 0, 1, 1); //up
  Colors[1 ] := Vector4(1, 0, 1, 1);
  Colors[2 ] := Vector4(1, 1, 1, 1);
  Colors[3 ] := Vector4(0, 1, 1, 1);
  Colors[4 ] := Vector4(0, 0, 1, 1); //down
  Colors[5 ] := Vector4(1, 0, 1, 1);
  Colors[6 ] := Vector4(1, 1, 1, 1);
  Colors[7 ] := Vector4(0, 1, 1, 1);
  Colors[8 ] := Vector4(1, 0, 1, 1); //forward
  Colors[9 ] := Vector4(0, 0, 1, 1);
  Colors[10] := Vector4(0, 1, 1, 1);
  Colors[11] := Vector4(1, 1, 1, 1);
  Colors[12] := Vector4(1, 0, 1, 1);
  Colors[13] := Vector4(0, 0, 1, 1); //backward
  Colors[14] := Vector4(0, 1, 1, 1);
  Colors[15] := Vector4(1, 1, 1, 1);
  Colors[16] := Vector4(0, 0, 1, 1); //left
  Colors[17] := Vector4(1, 0, 1, 1);
  Colors[18] := Vector4(1, 1, 1, 1);
  Colors[19] := Vector4(0, 1, 1, 1);
  Colors[20] := Vector4(0, 0, 1, 1); //right
  Colors[21] := Vector4(1, 0, 1, 1);
  Colors[22] := Vector4(1, 1, 1, 1);
  Colors[23] := Vector4(0, 1, 1, 1);

  Faces[ 0] := Face( 0, 1, 2);
  Faces[ 1] := Face( 0, 2, 3);
  Faces[ 2] := Face( 4, 5, 6);
  Faces[ 3] := Face( 4, 6, 7);
  Faces[ 4] := Face( 8, 9,10);
  Faces[ 5] := Face( 8,10,11);
  Faces[ 6] := Face(12,13,14);
  Faces[ 7] := Face(12,14,15);
  Faces[ 8] := Face(16,17,18);
  Faces[ 9] := Face(16,18,19);
  Faces[10] := Face(20,21,22);
  Faces[11] := Face(20,22,23);

  Result := TMesh.Create(Faces, Vertex, Textures, Normals, Colors);
  SetLength(Vertex, 0);
  SetLength(Textures, 0);
  SetLength(Normals, 0);
  SetLength(Colors, 0);
  SetLength(Faces, 0);
end;
{$ENDREGION}
 //World
{$REGION 'World'}
procedure TWorld.OnStart;
begin
  World := Self;

  FPlanet := TPlanetoid.Create(TGameObject.Create(nil, Vector3(0, 0, 0)), 10);
  TStarField.Create(TGameObject.Create(nil, Vector3(0, 0, 0)), 100);

  TBullet.Init;
  TCapsule.Init;
  TBaseEnemy.Init;
  TDiscEnemy.Init;

  FHeroObject := TGameObject.Create(nil);
  FHero := THero.Create(FHeroObject);
  FCameraController.Parent := FHeroObject;
  FCameraPosition := Vector3( 0, 12, -1);
  FCameraController.LocalPosition := FCameraPosition;
  FCameraController.LocalRotation := Rotate(75, Vector3(1, 0, 0)); 
  Control.SetMousePosition(Window.Width  div 2, Window.Height div 2);
  FEnemyCounter := 0;

  FWave := 0;
  StartNextWave;
end;

procedure TWorld.CreateAction(Rotation: TMatrix3; Tag: Integer);
begin
  case Tag of
    0: begin
      TBaseEnemy.Awake(1, Vector3(1,1,1), Rotation);
    end;     
    1: begin
      TBaseEnemy.Awake(2, Vector3(0.2,0.2,1), Rotation);
    end;     
    2: begin
      TBaseEnemy.Awake(4, Vector3(1,0.2,0.2), Rotation);
    end;
    3: begin
      TBaseEnemy.Awake(2, Vector3(1,0.2,0.2), Rotate(0, Vector3(0,1,0)) * Rotation);    
      TBaseEnemy.Awake(2, Vector3(1,0.2,0.2), Rotate(120, Vector3(0,1,0)) * Rotation);
      TBaseEnemy.Awake(2, Vector3(1,0.2,0.2), Rotate(240, Vector3(0,1,0)) * Rotation);
      CountEnemies(2);
    end; 
    4: begin
      TBaseEnemy.Awake(6, Vector3(1,  1,0.2), Rotate(0, Vector3(0,1,0)) * Rotation);
      TBaseEnemy.Awake(2, Vector3(0.2,0.2,1), Rotate(120, Vector3(0,1,0)) * Rotation);
      TBaseEnemy.Awake(4, Vector3(1,0.2,0.2), Rotate(240, Vector3(0,1,0)) * Rotation);
      CountEnemies(2);
    end;           
    5: begin
      TBaseEnemy.Awake(12, Vector3(1,1,0), Rotation);
    end;
    6: begin
      TDiscEnemy.Awake(4, Vector3(1,1,1), Rotation);
    end;
    7: begin
      TDiscEnemy.Awake(8, Vector3(1,1,1), Rotation);
    end;
    else 
      TBaseEnemy.Awake(1, Vector3(1,1,1), Rotation);
  end;
end;

procedure  TWorld.Restart();
begin
  FPointUpdateFrame := -200;      
  Window.Title := 'Points: ' + IntToStr(FCurrentPoints);
  FPlanet.ChangeColor(PLANET_COLORS[FWave], Vector3(0, 0, 0), Vector3(0.15,0.2,0.1));
  TBaseEnemy.Stop;
  TDiscEnemy.Stop;
  FWave := 0;
  FNextWaveTimer := 228;
  FEnemyCounter := 0;    
  FCurrentPoints := 0;                                  
  FPoints := 0;
end;

procedure TWorld.AddPoints(Points: Integer);
begin
  FPoints := FPoints + Points;
end;

procedure TWorld.CountEnemies(Count: Integer);
begin
  FEnemyCounter := FEnemyCounter + Count;
end;

function TWorld.GetMouseDelta: TVector2;
begin
  Result := Vector2( FMouseDeltaX, FMouseDeltaY );
end;

procedure TWorld.Stress(Time: Single = 10);
begin
  if (FStressTime < Time) then
    FStressTime := Time;
end;

procedure TWorld.NextWave();
begin
  Inc(FWave);
  if (FWave >= MAX_WAVE - 1) then
    FWave := 0;
  FPlanet.ChangeColor(PLANET_COLORS[FWave], PLANET_COLORS[FWave + 1], Vector3(0.15,0.2,0.1));
  FNextWaveTimer := 5;
end;

procedure TWorld.OnUpdate(delta: Double);
begin
  if Control.Key[KEY_ESC] then
    Application.Close;   
  if Control.Key[KEY_SPACE] then
    Application.Close;

  FMouseDeltaX := Round(Window.Width  / 2) - Control.Mouse.X - Window.Left;
  FMouseDeltaY := Round(Window.Height / 2) - Control.Mouse.Y - Window.Top;
  Control.SetMousePosition(Window.Width  div 2, Window.Height div 2);

  Inc(FPointUpdateFrame);

  if (FEnemyCounter <= 0) and (FNextWaveTimer <= 0) then
  begin
    NextWave;
  end;
  if (FNextWaveTimer > 0) then
  begin
    FNextWaveTimer := FNextWaveTimer - Delta;
    if (FNextWaveTimer > 180) and (FNextWaveTimer < 200) then
    begin   
      FWave := 0;
      FPlanet.ChangeColor(Vector3(0, 0, 0), PLANET_COLORS[FWave], Vector3(0.15,0.2,0.1));
      FNextWaveTimer := 8;
    end;
    if (FNextWaveTimer <= 0) then
      StartnextWave();
  end;

  if (FPointUpdateFrame > 5) then
  begin
    FPointUpdateFrame := 0;
    Window.Title := 'Points: ' + IntToStr(FCurrentPoints);
  end;
  if (FCurrentPoints < FPoints) then
    FCurrentPoints := FCurrentPoints + 10;

  if (Control.Key[KEY_Q]) then
    FCameraController.LocalRotation := FCameraController.LocalRotation * Rotate(3 * delta, Vector3(0, 1, 0));
  if (Control.Key[KEY_E]) then
    FCameraController.LocalRotation := FCameraController.LocalRotation * Rotate(-3 * delta, Vector3(0, 1, 0));
  //TDOD - Set enum  
  Control.Mouse.Wheel := 0;
  //Stress
  if (FStressTime > 0) then
  begin
    FStressTime := FStressTime - Delta;
    if (FStressTime <= 0) then
    begin
      FStressTime := 0;
    end;
    FStressCameraPosition := FStressCameraPosition * 0.96 + Vector3(Random(10) - 5, Random(10) - 5, Random(10) - 5) * 0.01;
    FCameraController.LocalPosition :=
      FCameraPosition +
      FStressCameraPosition * FStressTime * 0.2;
  end;
end;

procedure TWorld.OnDestroy;
begin

end;
{$ENDREGION}

{$REGION 'Levels'}
procedure TWorld.StartNextWave();
var
  i: Integer;
begin         
  FHero.AddLevel;
  case FWave of
    0:for i := 0 to 18 do
      begin
        TCapsule.Add(
          (Rotate(Random(20) - 10, Vector3(1,0,0)) * Rotate(Random(20) - 10, Vector3(0,0,1))) *
          Rotate(30, Vector3(1,0,0)) *
          FHeroObject.LocalRotation, CreateAction, 0, 12 + i / 2);
        CountEnemies(1);
      end;
    1:for i := 0 to 18 do
      begin
        TCapsule.Add(
          (Rotate(Random(20) - 10, Vector3(1,0,0)) * Rotate(Random(20) - 10, Vector3(0,0,1))) *
          Rotate(30, Vector3(1,0,0)) *
          FHeroObject.LocalRotation, CreateAction, 1, 12 + i / 2);
        CountEnemies(1);
      end;      
    2: begin
      //Blue
      for i := 0 to 18 do
      begin
        TCapsule.Add(
          (Rotate(Random(20) - 10, Vector3(1,0,0)) * Rotate(Random(20) - 10, Vector3(0,0,1))) *
          Rotate(30, Vector3(1,0,0)) *
          FHeroObject.LocalRotation, CreateAction, 1, 12 + i / 2);
        CountEnemies(1);
      end;
      //Disc
      for i := 0 to 3 do
      begin
        TCapsule.Add(
          (Rotate(Random(20) - 10, Vector3(1,0,0)) * Rotate(Random(20) - 10, Vector3(0,0,1))) *
          Rotate(30, Vector3(1,0,0)) *
          FHeroObject.LocalRotation, CreateAction, 6, 12 + i / 2);
        CountEnemies(1);
      end;
    end;
    3:for i := 0 to 24 do
      begin
        TCapsule.Add(
          (Rotate(Random(40) - 20, Vector3(1,0,0)) * Rotate(Random(40) - 20, Vector3(0,0,1))) *
          Rotate(40, Vector3(1,0,0)) *
          FHeroObject.LocalRotation, CreateAction, 2, 12 + i / 2);
        CountEnemies(1);
      end;
    4:for i := 0 to 15 do
      begin
        TCapsule.Add(
          (Rotate(Random(6) - 3, Vector3(1,0,0)) * Rotate(i * 10 - 75, Vector3(0,0,1))) *
          Rotate(40, Vector3(1,0,0)) *
          FHeroObject.LocalRotation, CreateAction, 4, 12 + i / 2);
        CountEnemies(1);
      end;
    5:for i := 0 to 30 do
      begin
        TCapsule.Add(
          //(Rotate(Random(6) - 3, Vector3(1,0,0)) * Rotate(Random(6) - 3, Vector3(0,0,1))) *
          Rotate(40 - i * 3, Vector3(1,0,0)) *
          FHeroObject.LocalRotation, CreateAction, 3, 10 + i / 2.6);
        CountEnemies(1);
      end;
    6:for i := 0 to 12 do
      begin
        TCapsule.Add(
          (Rotate(Random(6) - 3, Vector3(1,0,0)) * Rotate(i * 10 - 60, Vector3(0,0,1))) *
          Rotate(40, Vector3(1,0,0)) *
          FHeroObject.LocalRotation, CreateAction, 5, 12 + i / 2);
        CountEnemies(1);
      end;
    7:begin
      for i := 0 to 30 do
      begin
        TCapsule.Add(
          //(Rotate(Random(6) - 3, Vector3(1,0,0)) * Rotate(Random(6) - 3, Vector3(0,0,1))) *
          Rotate(40 - i * 3, Vector3(1,0,0)) *
          FHeroObject.LocalRotation, CreateAction, 3, 10 + i / 2.6);
        CountEnemies(1);
      end;             
      //Disc        
      for i := 0 to 3 do
      begin
        TCapsule.Add(
          (Rotate(Random(20) - 10, Vector3(1,0,0)) * Rotate(Random(20) - 10, Vector3(0,0,1))) *
          Rotate(30, Vector3(1,0,0)) *
          FHeroObject.LocalRotation, CreateAction, 7, 12 + i / 2);
        CountEnemies(1);
      end;
    end;
    8:begin
        for i := 0 to 10 do
        begin
          TCapsule.Add(
            (Rotate(Random(6) - 3, Vector3(1,0,0)) * Rotate(i * 10 - 75, Vector3(0,0,1))) *
            Rotate(45, Vector3(1,0,0)) *
            FHeroObject.LocalRotation, CreateAction, 3, 10 + i / 2.6);
          CountEnemies(1);
        end;
        for i := 0 to 10 do
        begin
          TCapsule.Add(
            (Rotate(Random(6) - 3, Vector3(1,0,0)) * Rotate(i * 10 - 75, Vector3(0,0,1))) *
            Rotate(40, Vector3(1,0,0)) *
            FHeroObject.LocalRotation, CreateAction, 0, 10 + i / 2.6);
          CountEnemies(1);
        end;
        for i := 0 to 15 do
        begin
          TCapsule.Add(
            (Rotate(Random(6) - 3, Vector3(1,0,0)) * Rotate(i * 10 - 75, Vector3(0,0,1))) *
            Rotate(35, Vector3(1,0,0)) *
            FHeroObject.LocalRotation, CreateAction, 1, 10 + i / 2.6);
          CountEnemies(1);
        end;
     end;
    9:begin
        for i := 0 to 10 do
        begin
          TCapsule.Add(
            (Rotate(Random(6) - 3, Vector3(1,0,0)) * Rotate(i * 10 - 75, Vector3(0,0,1))) *
            Rotate(30, Vector3(1,0,0)) *
            FHeroObject.LocalRotation, CreateAction, 4, 10 + i / 2.6);
          CountEnemies(1);
        end;  
        for i := 0 to 15 do
        begin
          TCapsule.Add(
            (Rotate(Random(6) - 3, Vector3(1,0,0)) * Rotate(i * 10 - 75, Vector3(0,0,1))) *
            Rotate(35, Vector3(1,0,0)) *
            FHeroObject.LocalRotation, CreateAction, 1, 10 + i / 2.6);
          CountEnemies(1);
        end;
    end;  
    10:begin
        for i := 0 to 60 do
        begin
          TCapsule.Add(
            (Rotate(Random(6) - 3, Vector3(1,0,0)) * Rotate(i * 5 - 4, Vector3(0,0,1))) *
            Rotate(30, Vector3(1,0,0)) *
            FHeroObject.LocalRotation, CreateAction, 0, 10 + i / 2.6);
          CountEnemies(1);
        end;     
        for i := 0 to 20 do
        begin
          TCapsule.Add(
            (Rotate(Random(6) - 3, Vector3(1,0,0)) * Rotate(i * 10 - 50, Vector3(0,0,1))) *
            Rotate(30, Vector3(1,0,0)) *
            FHeroObject.LocalRotation, CreateAction, 1, 10 + i / 2.6);
          CountEnemies(1);
        end;
    end;    
    11:begin
        for i := 0 to 10 do
        begin
          TCapsule.Add(
            (Rotate(Random(6) - 3, Vector3(1,0,0)) * Rotate(i * 10 - 50, Vector3(0,0,1))) *
            Rotate(30, Vector3(1,0,0)) *
            FHeroObject.LocalRotation, CreateAction, 6, 10 + i / 2.6);
          CountEnemies(1);
        end;
        for i := 0 to 10 do
        begin
          TCapsule.Add(
            (Rotate(Random(6) - 3, Vector3(1,0,0)) * Rotate(i * 10 - 50, Vector3(0,0,1))) *
            Rotate(30, Vector3(1,0,0)) *
            FHeroObject.LocalRotation, CreateAction, 7, 10 + i / 2.6);
          CountEnemies(1);
        end;
    end;    
    12:begin
        for i := 0 to 60 do
        begin
          TCapsule.Add(
            (Rotate(Random(6) - 3, Vector3(1,0,0)) * Rotate(i * 3 - 4, Vector3(0,0,1))) *
            Rotate(30, Vector3(1,0,0)) *
            FHeroObject.LocalRotation, CreateAction, 1, 10 + i / 2.6);
          CountEnemies(1);
        end;     
        for i := 0 to 20 do
        begin
          TCapsule.Add(
            (Rotate(Random(6) - 3, Vector3(1,0,0)) * Rotate(i * 4 - 75, Vector3(0,0,1))) *
            Rotate(30, Vector3(1,0,0)) *
            FHeroObject.LocalRotation, CreateAction, 2, 10 + i / 2.6);
          CountEnemies(1);
        end;
    end;
    13:begin
        for i := 0 to 20 do
        begin
          TCapsule.Add(
            (Rotate(Random(6) - 3, Vector3(1,0,0)) * Rotate(i * 3 - 4, Vector3(0,0,1))) *
            Rotate(30, Vector3(1,0,0)) *
            FHeroObject.LocalRotation, CreateAction, 4, 10 + i / 2.6);
          CountEnemies(1);
        end;     
        for i := 0 to 10 do
        begin
          TCapsule.Add(
            (Rotate(Random(6) - 3, Vector3(1,0,0)) * Rotate(i * 10 - 50, Vector3(0,0,1))) *
            Rotate(30, Vector3(1,0,0)) *
            FHeroObject.LocalRotation, CreateAction, 7, 10 + i / 2.6);
          CountEnemies(1);
        end;
    end;   
    14:begin
      for i := 0 to 20 do
        begin
          TCapsule.Add(
            (Rotate(Random(6) - 3, Vector3(1,0,0)) * Rotate(i * 3 - 4, Vector3(0,0,1))) *
            Rotate(30, Vector3(1,0,0)) *
          FHeroObject.LocalRotation, CreateAction, 5, 12 + i / 2);
        CountEnemies(1);
      end;
    end;
    15:for i := 0 to 40 do
      begin
        TCapsule.Add(
          //(Rotate(Random(6) - 3, Vector3(1,0,0)) * Rotate(Random(6) - 3, Vector3(0,0,1))) *
          Rotate(40 - i * 3, Vector3(1,0,0)) *
          FHeroObject.LocalRotation, CreateAction, 3, 10 + i / 2.6);
        CountEnemies(1);
      end;
    16:for i := 0 to 18 do
      begin
        TCapsule.Add(
          (Rotate(Random(6) - 3, Vector3(1,0,0)) * Rotate(i * 10 - 60, Vector3(0,0,1))) *
          Rotate(40, Vector3(1,0,0)) *
          FHeroObject.LocalRotation, CreateAction, 5, 12 + i / 2);
        CountEnemies(1);
      end;
    17:begin
      for i := 0 to 40 do
      begin
        TCapsule.Add(
          //(Rotate(Random(6) - 3, Vector3(1,0,0)) * Rotate(Random(6) - 3, Vector3(0,0,1))) *
          Rotate(40 - i * 3, Vector3(1,0,0)) *
          FHeroObject.LocalRotation, CreateAction, 3, 10 + i / 2.6);
        CountEnemies(1);
      end;             
      //Disc        
      for i := 0 to 5 do
      begin
        TCapsule.Add(
          (Rotate(Random(20) - 10, Vector3(1,0,0)) * Rotate(Random(20) - 10, Vector3(0,0,1))) *
          Rotate(30, Vector3(1,0,0)) *
          FHeroObject.LocalRotation, CreateAction, 7, 12 + i / 2);
        CountEnemies(1);
      end;
    end;
    18:begin
        for i := 0 to 10 do
        begin
          TCapsule.Add(
            (Rotate(Random(6) - 3, Vector3(1,0,0)) * Rotate(i * 10 - 75, Vector3(0,0,1))) *
            Rotate(45, Vector3(1,0,0)) *
            FHeroObject.LocalRotation, CreateAction, 3, 10 + i / 2.6);
          CountEnemies(1);
        end;
        for i := 0 to 10 do
        begin
          TCapsule.Add(
            (Rotate(Random(6) - 3, Vector3(1,0,0)) * Rotate(i * 10 - 75, Vector3(0,0,1))) *
            Rotate(40, Vector3(1,0,0)) *
            FHeroObject.LocalRotation, CreateAction, 2, 10 + i / 2.6);
          CountEnemies(1);
        end;
        for i := 0 to 15 do
        begin
          TCapsule.Add(
            (Rotate(Random(6) - 3, Vector3(1,0,0)) * Rotate(i * 10 - 75, Vector3(0,0,1))) *
            Rotate(35, Vector3(1,0,0)) *
            FHeroObject.LocalRotation, CreateAction, 1, 10 + i / 2.6);
          CountEnemies(1);
        end;
     end;
    19:begin
        for i := 0 to 12 do
        begin
          TCapsule.Add(
            (Rotate(Random(6) - 3, Vector3(1,0,0)) * Rotate(i * 10 - 75, Vector3(0,0,1))) *
            Rotate(30, Vector3(1,0,0)) *
            FHeroObject.LocalRotation, CreateAction, 4, 10 + i / 2.6);
          CountEnemies(1);
        end;  
        for i := 0 to 15 do
        begin
          TCapsule.Add(
            (Rotate(Random(6) - 3, Vector3(1,0,0)) * Rotate(i * 10 - 75, Vector3(0,0,1))) *
            Rotate(35, Vector3(1,0,0)) *
            FHeroObject.LocalRotation, CreateAction, 2, 10 + i / 2.6);
          CountEnemies(1);
        end;
    end;  
    20:begin
        for i := 0 to 60 do
        begin
          TCapsule.Add(
            (Rotate(Random(6) - 3, Vector3(1,0,0)) * Rotate(i * 5 - 4, Vector3(0,0,1))) *
            Rotate(30, Vector3(1,0,0)) *
            FHeroObject.LocalRotation, CreateAction, 1, 10 + i / 2.6);
          CountEnemies(1);
        end;     
        for i := 0 to 20 do
        begin
          TCapsule.Add(
            (Rotate(Random(6) - 3, Vector3(1,0,0)) * Rotate(i * 10 - 50, Vector3(0,0,1))) *
            Rotate(30, Vector3(1,0,0)) *
            FHeroObject.LocalRotation, CreateAction, 2, 10 + i / 2.6);
          CountEnemies(1);
        end;
    end;    
    21:begin
        for i := 0 to 12 do
        begin
          TCapsule.Add(
            (Rotate(Random(6) - 3, Vector3(1,0,0)) * Rotate(i * 10 - 50, Vector3(0,0,1))) *
            Rotate(30, Vector3(1,0,0)) *
            FHeroObject.LocalRotation, CreateAction, 6, 10 + i / 2.6);
          CountEnemies(1);
        end;
        for i := 0 to 12 do
        begin
          TCapsule.Add(
            (Rotate(Random(6) - 3, Vector3(1,0,0)) * Rotate(i * 10 - 50, Vector3(0,0,1))) *
            Rotate(30, Vector3(1,0,0)) *
            FHeroObject.LocalRotation, CreateAction, 7, 10 + i / 2.6);
          CountEnemies(1);
        end;
    end;    
    22:begin
        for i := 0 to 60 do
        begin
          TCapsule.Add(
            (Rotate(Random(6) - 3, Vector3(1,0,0)) * Rotate(i * 3 - 4, Vector3(0,0,1))) *
            Rotate(30, Vector3(1,0,0)) *
            FHeroObject.LocalRotation, CreateAction, 2, 10 + i / 2.6);
          CountEnemies(1);
        end;     
        for i := 0 to 20 do
        begin
          TCapsule.Add(
            (Rotate(Random(6) - 3, Vector3(1,0,0)) * Rotate(i * 4 - 75, Vector3(0,0,1))) *
            Rotate(30, Vector3(1,0,0)) *
            FHeroObject.LocalRotation, CreateAction, 3, 10 + i / 1.6);
          CountEnemies(1);
        end;
    end;
    23:begin
        for i := 0 to 20 do
        begin
          TCapsule.Add(
            (Rotate(Random(6) - 3, Vector3(1,0,0)) * Rotate(i * 3 - 4, Vector3(0,0,1))) *
            Rotate(30, Vector3(1,0,0)) *
            FHeroObject.LocalRotation, CreateAction, 4, 10 + i / 2.2);
          CountEnemies(1);
        end;     
        for i := 0 to 20 do
        begin
          TCapsule.Add(
            (Rotate(Random(6) - 3, Vector3(1,0,0)) * Rotate(i * 10 - 50, Vector3(0,0,1))) *
            Rotate(30, Vector3(1,0,0)) *
            FHeroObject.LocalRotation, CreateAction, 6, 10 + i / 1.6);
          CountEnemies(1);
        end;
    end;   
    24:begin
      for i := 0 to 20 do
        begin
          TCapsule.Add(
            (Rotate(Random(6) - 3, Vector3(1,0,0)) * Rotate(i * 3 - 4, Vector3(0,0,1))) *
            Rotate(30, Vector3(1,0,0)) *
          FHeroObject.LocalRotation, CreateAction, 5, 12 + i / 1.4);
        CountEnemies(1);
      end;
    end
    else  
      for i := 0 to 50 do
      begin
        TCapsule.Add(
          (Rotate(Random(20) - 10, Vector3(1,0,0)) * Rotate(Random(20) - 10, Vector3(0,0,1))) *
          Rotate(30, Vector3(1,0,0)) *
          FHeroObject.LocalRotation, CreateAction, 0, 12 + i / 2);
        CountEnemies(1);
      end;
  end;
end;

{$ENDREGION}

end.
