Beispiel #1
0
        /// <summary>
        /// Adds objects only once to the passed collection.
        /// </summary>
        /// <param name="objects"></param>
        public void Initiliaze(List<EnvironmentObject> objects)
        {
            objects.Add(new Ground(0, 25, 50, 2));

            Random rnd = new Random();

            for (int i = 0; i < StarCount; i++)
            {
                int x = rnd.Next(0, WorldWidth);
                int y = rnd.Next(0, 24);
                var envObject = new Star(x, y, 1, 1);

                objects.Add(envObject);
            }

            for (int i = 0; i < UnstableStarCount; i++)
            {
                int x = rnd.Next(0, WorldWidth);
                int y = rnd.Next(0, 24);
                var envObject = new UnstableStar(x, y, 1, 1);

                objects.Add(envObject);
            }
        }
        /// <summary>
        /// Adds objects only once to the passed collection.
        /// </summary>
        /// <param name="objects"></param>
        public void Initiliaze(List<EnvironmentObject> objects)
        {
            objects.Add(new Ground(0, 25, 50, 2));

            for (int i = 0; i < 10; i++)
            {
                int x = rnd.Next(0, WorldWidth);
                int y = rnd.Next(0, WorldHeight - 10);
                var envObject = new Star(x, y, 1, 1, new Point(0, 0));
                var overlappingStar = objects.Select(o => o).Where(o => o.Bounds.TopLeft.X == x && o.Bounds.TopLeft.Y == y);
                if (overlappingStar.Count() == 0)
                {
                    objects.Add(envObject);
                }
                else
                {
                    i--;
                }
            }
        }