public static GameObject[] GenerateWindows(Texture2D texture, Rectangle rect, GraphicsDevice graphicsDevice)
        {
            SpriteBatch spriteBatch = new SpriteBatch(graphicsDevice);

            //graphicsDevice.Clear(Color.White);

            spriteBatch.Begin(SpriteBlendMode.AlphaBlend, SpriteSortMode.Deferred, SaveStateMode.None);

            DrawFrames(spriteBatch, rect, texture);
            int nUnitWidth  = rect.Width / HouseGenerator.HouseWidth;
            int nUnitHeight = (rect.Height / HouseGenerator.HouseHeight) - 1;

            //first window on the bottom floor
            Rectangle frameRect = new Rectangle((rect.Width / nUnitWidth) / 2 - ((rect.Width / nUnitWidth) / 6),
                                                (rect.Height - HouseGenerator.HouseHeight) / 2 - ((rect.Height - HouseGenerator.HouseHeight) / 6),
                                                (rect.Width / nUnitWidth) / 3,
                                                (rect.Height - HouseGenerator.HouseHeight) / 3);

            switch (RandomManager.GetInt(0, 3))
            {
            case 0:
            {
                Rectangle windowRect = new Rectangle(frameRect.Width / 10, frameRect.Width / 10, frameRect.Width - frameRect.Width / 5, frameRect.Height - frameRect.Width / 5);
                //draw the glass(find a glasscolour)
                spriteBatch.Draw(texture, windowRect, Color.Blue);
                break;
            }

            case 1:
            {
                Rectangle   temp       = new Rectangle(frameRect.X, frameRect.Y, frameRect.Width / 2, frameRect.Height);
                Rectangle[] windowRect = new Rectangle[2];
                windowRect[0] = new Rectangle(temp.Width / 10, temp.Width / 10, temp.Width - temp.Width / 5, temp.Height - temp.Width / 5);
                windowRect[1] = new Rectangle(temp.Width + temp.Width / 10, temp.Width / 10, temp.Width - temp.Width / 5, temp.Height - temp.Width / 5);
                spriteBatch.Draw(texture, windowRect[0], Color.Blue);
                spriteBatch.Draw(texture, windowRect[1], Color.Blue);
                break;
            }

            case 2:
            {
                //windows arranged 0 1
                //                 2 3
                Rectangle   temp       = new Rectangle(frameRect.X, frameRect.Y, frameRect.Width / 2, frameRect.Height / 2);
                Rectangle[] windowRect = new Rectangle[4];
                windowRect[0] = new Rectangle(temp.Width / 10, temp.Width / 10, temp.Width - temp.Width / 5, temp.Height - temp.Width / 5);
                windowRect[1] = new Rectangle(temp.Width + temp.Width / 10, temp.Width / 10, temp.Width - temp.Width / 5, temp.Height - temp.Width / 5);
                windowRect[2] = new Rectangle(temp.Width / 10, temp.Height + temp.Width / 10, temp.Width - temp.Width / 5, temp.Height - temp.Width / 5);
                windowRect[3] = new Rectangle(temp.Width + temp.Width / 10, temp.Height + temp.Width / 10, temp.Width - temp.Width / 5, temp.Height - temp.Width / 5);
                break;
            }
            }
            spriteBatch.End();
            return(returnWindows(HouseGenerator.RenderGraphicsDevice(graphicsDevice, rect), rect));
        }
        public static Texture2D generateDoor(Texture2D door, Rectangle rect, GraphicsDevice graphicsDevice)
        {
            SpriteBatch spriteBatch = new SpriteBatch(graphicsDevice);
            Color       doorColor   = RandomManager.GetRandomColour();

            spriteBatch.Begin(SpriteBlendMode.AlphaBlend, SpriteSortMode.Deferred, SaveStateMode.None);
            spriteBatch.Draw(door, rect, doorColor);
            spriteBatch.End();

            return(HouseGenerator.RenderGraphicsDevice(graphicsDevice, rect));
        }
 public static void DrawFrames(SpriteBatch spriteBatch, Rectangle rect, Texture2D texture)
 {
     if (RandomManager.GetInt(0, 2) == 0)
     {
         //white window frames
         spriteBatch.Draw(texture, rect, Color.White);
     }
     else
     {
         //wooden window frames(brown)
         spriteBatch.Draw(texture, rect, Color.Brown);
     }
 }
Exemplo n.º 4
0
        public static GameObject[] GenerateHouse(Rectangle map, float density, GraphicsDevice graphicsDevice, ContentManager Content)
        {
            //Make sure the class has been loaded
            if (blank == null)
            {
                Load(Content);
            }

            //Calculate number of houses
            int total = CalculateDensity(density, map.Width);

            //Instantiate array
            GameObject[] houses = new GameObject[total];

            //Instantiate a SpriteBatch for rendering textures
            SpriteBatch spriteBatch = new SpriteBatch(graphicsDevice);

            for (int i = 0; i < total; i++)
            {
                //Calculate the rectangle the building should fit in
                //Using the density float
                Rectangle rect = CalculateHouse(i, total, map);

                //Select a brick texture to use
                Texture2D brick = bricks[RandomManager.GetInt(0, bricks.Length)];

                //Instantiate the house's elements
                GameObject   building = GenerateBuilding(rect, brick, graphicsDevice);
                GameObject   roof     = GenerateRoof(rect, brick, graphicsDevice);
                GameObject   chimney  = GenerateChimney(rect, brick, graphicsDevice);
                GameObject[] windows  = GenerateWindows(blank, rect, graphicsDevice);
                GameObject   door     = GenerateDoor(blank, rect, graphicsDevice);

                //Draw all the elements to the graphics card
                graphicsDevice.Clear(Color.White);
                spriteBatch.Begin(SpriteBlendMode.AlphaBlend, SpriteSortMode.Deferred, SaveStateMode.None);
                chimney.Draw(spriteBatch);
                building.Draw(spriteBatch);
                roof.Draw(spriteBatch);
                foreach (GameObject window in windows)
                {
                    window.Draw(spriteBatch);
                }
                door.Draw(spriteBatch);
                spriteBatch.End();

                //Render the house to a texture
                //Don't know if this will work
                Texture2D houseSprite = RenderGraphicsDevice(graphicsDevice, rect);

                //Push house on to array
                houses[i] = new GameObject(houseSprite, rect, 0.2f);

                //Dispose of the GameObjects
                building.Dispose();
                roof.Dispose();
                chimney.Dispose();
                foreach (GameObject window in windows)
                {
                    window.Dispose();
                }
                door.Dispose();
            }

            return(houses);
        }