Exemple #1
0
    void OnTriggerEnter2D(Collider2D other)
    {
        PacDots script = other.gameObject.GetComponent <PacDots> ();

        if (script != null)
        {
            script.OnEaten();
        }
    }
Exemple #2
0
        /// <summary>
        /// Handles The Random Spawns of fruits when the player score is added 1200 points
        /// </summary>
        private void SpawnFruit()
        {
            int          type;
            List <Point> availablePositions = new List <Point>();

            string[] file = File.ReadAllLines($@"{Content.RootDirectory}\board.txt");

            int width  = file[0].Length;
            int height = file.Length;

            for (int y = 0; y < height; y++)
            {
                for (int x = 0; x < width; x++)
                {
                    switch (file[y][x])
                    {
                    case ' ':
                        availablePositions.Add(new Point(x, y));
                        break;
                    }
                }
            }

            int chance = Rnd.Next(0, 100);

            if (chance <= 50)
            {
                type = 0;
            }
            else if (chance <= 75)
            {
                type = 1;
            }
            else if (chance <= 90)
            {
                type = 2;
            }
            else if (chance <= 98)
            {
                type = 3;
            }
            else
            {
                type = 4;
            }

            int   index    = Rnd.Next(availablePositions.Count);
            Point position = availablePositions[index];

            PacDot dot = PacDots.FirstOrDefault(p => p.Position == position);

            if (dot != null)
            {
                PacDots.Remove(dot);
                Components.Remove(dot);
            }

            Fruit fruit = new Fruit(this, position, type);

            Fruits.Add(fruit);
            Components.Add(fruit);
        }