예제 #1
0
 public void DestroyCircle(int centerX, int centerY, int radius)
 {
     View.DrawToTerrain(Terrain.DestroyCircle(centerX, centerY, radius), centerX - radius, centerY - radius, radius * 2 + 1, radius * 2 + 1);
 }
예제 #2
0
        /// <summary>
        /// Places an entity in the level so its bounding box is fully inside the level and not colliding with the terrain.
        /// </summary>
        /// <param name="e">The entity to be placed.</param>
        public void PlaceEntity(Entity e)
        {
            int  timeOutCounter = 100;
            bool freespaceFound = true;

            e.Position = new Vector2(rand.Next(Terrain.Width), rand.Next(Terrain.Height));
            do
            {
                if (CollisionEngine.BoundingBoxTerrainCollision(e.BoundingBox, Terrain) || !Terrain.IsRectangleClear(e.BoundingBox))
                {
                    freespaceFound = false;
                }
                else
                {
                    foreach (Entity e2 in EntityList)
                    {
                        if (e.BoundingBox.Intersects(e2.BoundingBox))
                        {
                            freespaceFound = false;
                        }
                    }
                }
                timeOutCounter--;
                if (timeOutCounter == 0)
                {
                    DestroyCircle((int)e.Position.X, (int)e.Position.Y, (int)(MathHelper.Max(e.Size.X, e.Size.Y) / 2));
                    freespaceFound = true;
                }
                if (!freespaceFound)
                {
                    e.Position -= new Vector2(0, e.Size.Y / 2);
                    if (e.Position.Y - e.Origin.Y < 0)
                    {
                        e.Position = new Vector2(rand.Next(Terrain.Width), rand.Next(Terrain.Height));
                    }
                }
            } while (!freespaceFound);
        }