Exemple #1
0
    // Use this for initialization
    void Start()
    {
        this.damageable = this.gameObject.GetComponent <Damageable>();
        this.explodes   = this.gameObject.GetComponent <Explodes>();
        Vector3 min = Camera.main.ViewportToWorldPoint(new Vector3(0, 0, 0));
        Vector3 max = Camera.main.ViewportToWorldPoint(new Vector3(1, 1, 0));

        this.GetComponent <Rigidbody2D>().velocity = new Vector3(Random.Range(min.x, max.x), Random.Range(min.y, max.y), 0).normalized;
    }
Exemple #2
0
    // Use this for initialization
    void Start()
    {
        this.damageable = this.gameObject.GetComponent <Damageable>();
        this.explodes   = this.gameObject.GetComponent <Explodes>();

        Vector3 min = Camera.main.ViewportToWorldPoint(new Vector3(0, 0, 0));
        Vector3 max = Camera.main.ViewportToWorldPoint(new Vector3(1, 1, 0));

        this.GetComponent <Rigidbody2D>().velocity = new Vector3(Random.Range(min.x, max.x), Random.Range(min.y, max.y), 0).normalized;
        InvokeRepeating("ShootPlayer", 0.5f, 1.0f / this.shoot_rate);
    }
Exemple #3
0
 /// <summary>
 /// Отрисовка объектов
 /// </summary>
 public static void Draw()
 {
     Buffer.Graphics.DrawImage(SpaceImg, new Point(0, 0)); // Отрисовка фона
     CreateEnemiesShips();
     foreach (var e in BaseObj)
     {
         e.Draw();
     }
     if (Ship != null)
     {
         for (int i = EmpireShips.Count - 1; i >= 0; i--)
         {
             if (EmpireShips[i].Collision(Ship)) // Проверка столкновения корабля-противника с кораблём
             {
                 Explodes.Add(new Explode(EmpireShips[i].Pos));
                 Ship.GetDamage(EmpireShips[i].Health);
                 EmpireShips[i].Die(EmpireShips, i);
                 continue;
             }
             for (int j = PlayerBullets.Count - 1; j >= 0; j--)
             {
                 if (EmpireShips[i].Collision(PlayerBullets[j])) // Проверка столкновения кораблей-противников с пулями
                 {
                     PlayerBullets[j].Del(PlayerBullets, j);
                     Explodes.Add(new Explode(EmpireShips[i].Pos));
                     EmpireShips[i].Die(EmpireShips, i);
                     break;
                 }
             }
         }
         for (int i = EnemiesBullets.Count - 1; i >= 0; i--)
         {
             if (EnemiesBullets[i].Collision(Ship)) // Проверка на столкновение пули корабля-противника с кораблём игрока
             {
                 Explodes.Add(new Explode(EnemiesBullets[i].Pos));
                 Ship.GetDamage(EnemiesBullets[i].Health);
                 EnemiesBullets[i].Del(EnemiesBullets, i);
                 continue;
             }
             for (int j = PlayerBullets.Count - 1; j >= 0; j--)
             {
                 if (EnemiesBullets[i].Collision(PlayerBullets[j])) // Проверка на столкновение пуль игрока с пулями кораблей-противников
                 {
                     PlayerBullets[j].Del(PlayerBullets, j);
                     Explodes.Add(new Explode(EnemiesBullets[i].Pos));
                     EnemiesBullets[i].Del(EnemiesBullets, i);
                     break;
                 }
             }
         }
         for (int i = Kits.Count - 1; i >= 0; i--)
         {
             if (Ship != null && Kits[i].Collision(Ship)) // Проверка столкновения аптечки с кораблём
             {
                 Ship.GetDamage(Kits[i].Health);
                 Kits[i].Del(Kits, i);
             }
         }
     }
     foreach (var e in PlayerBullets)
     {
         e.Draw();
     }
     foreach (var e in EnemiesBullets)
     {
         e.Draw();
     }
     foreach (var e in EnemiesBullets)
     {
         e.Draw();
     }
     foreach (var e in Explodes)
     {
         e.Draw();
     }
     foreach (var e in Kits)
     {
         e.Draw();
     }
     foreach (var e in EmpireShips)
     {
         e.Draw();
     }
     foreach (var e in Stats)
     {
         e.Draw();
     }
     Ship?.Draw();
     Buffer.Render();
 }