Exemple #1
0
        /// <summary>
        /// Get a random point within the section to spawn an entity
        /// </summary>
        /// <returns></returns>
        public Point GetSpawnSpot(Being b)
        {
            var x = _bounds.Left + Globals.Random.Next(_bounds.Width);
            var y = _bounds.Top + Globals.Random.Next(_bounds.Height);
            // TODO: is this okay?
            var hitbox = b.Hitbox().First().Scale(1.35f);
            var tries  = 0;

            while (HasCollidingWallTile(new Rectangle(x - hitbox.Width / 2, y - hitbox.Height / 2, hitbox.Width, hitbox.Height)))
            {
                x = _bounds.Left + Globals.Random.Next(_bounds.Width);
                y = _bounds.Top + Globals.Random.Next(_bounds.Height);
                // Some ting wong?
                if (tries++ > 50)
                {
                    throw new Exception("Tried to create an enemy but could not");
                }
            }
            return(new Point(x, y));
        }