/// <summary>
        /// Spawn in the ladybirds based on the constant count
        /// </summary>
        static void InitializeLadybirds()
        {
            var random = new Random();

            // Spawn the starting count of insects
            for (int i = 0; i < StartingLadybirdCount; i++)
            {
                var validPosition = false;
                //qwertyuiopasdfghjklzxcvbnm
                // Retrieve a random insect coordinate that is not occupied
                do
                {
                    var randomXPosition = random.Next(0, MaxGridSize);
                    var randomYPosition = random.Next(0, MaxGridSize);

                    if (Grid[randomXPosition, randomYPosition].CellStatus == EmptyCell)
                    {
                        // Assign the cell to a ladybird
                        Grid[randomXPosition, randomYPosition].CellStatus = LadybirdCell;

                        // Create the insect
                        var newInsect = new Ladybird(randomXPosition, randomYPosition);

                        // Add the insect to the list
                        Insects.Add(newInsect);

                        // Flag that the position generated was valid
                        validPosition = true;
                    }

                    // Retry as random coordinate has already been occupied
                } while (validPosition == false);
            }
        }
Exemplo n.º 2
0
Arquivo: Hornet.cs Projeto: Yakka/Aku
 /// <summary>
 /// Starts grabbing the target and sets grabbingTarget to true.
 /// Does nothing if it already grabs a target.
 /// It may causes trouble to the target.
 /// It also sets a release time after which hornets will release their target.
 /// </summary>
 private void GrabTarget()
 {
     if (!grabbingTarget)
     {
         if (Level.Get.levelID == 1)
         {
             SoundLevel1.Instance.HornetOnHead();
         }
         Drake drake = targets[index].GetComponent <Drake>();
         if (drake != null)
         {
             drake.GrabbedByHornet();
             willRelease = true;
         }
         Ladybird ladybird = targets[index].GetComponent <Ladybird>();
         if (ladybird != null)
         {
             ladybird.GrabbedByHornet();
             willRelease = false;
         }
         grabbingTarget    = true;
         releaseTargetTime = Time.time + Random.Range(4f, 8f);
     }
 }