public static Texture2D GenerateRoof(Texture2D brick, Rectangle rect, GraphicsDevice graphicsDevice) { //Instantiate the drawing variables Color tileFilter = Color.DarkRed; SpriteBatch spriteBatch = new SpriteBatch(graphicsDevice); //graphicsDevice.Clear(Color.White); Rectangle tileRect = new Rectangle(rect.X, rect.Y, (int)Math.Round(rect.Width / 10f), (int)Math.Round(rect.Height / 10f)); //Calculate how many tiles will be required int height = (int)Math.Round(rect.Height / 10f); int width = (int)Math.Round(rect.Width / 10f); int widthLimit = rect.Width; int i = 0; spriteBatch.Begin(SpriteBlendMode.AlphaBlend, SpriteSortMode.Deferred, SaveStateMode.None); for (Vector2 drawPosition = new Vector2(rect.X, rect.Y + rect.Height - tileRect.Height); drawPosition.Y < rect.Y; drawPosition.Y += tileRect.Height) { drawPosition.X = rect.X + (i * (int)Math.Round(tileRect.Width / 2f)); for ( ; drawPosition.X < widthLimit; drawPosition.X += tileRect.Height) { Rectangle drawRect = new Rectangle((int)drawPosition.X, (int)drawPosition.Y, tileRect.Width, tileRect.Height); spriteBatch.Draw(brick, drawRect, tileFilter); } widthLimit -= (int)Math.Round(tileRect.Width / 2f); i++; } spriteBatch.End(); return(HouseGenerator.RenderGraphicsDevice(graphicsDevice, rect)); }
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)); }
static Texture2D TileBricks(Rectangle rect, GraphicsDevice graphicsDevice, Texture2D brick) { SpriteBatch spriteBatch = new SpriteBatch(graphicsDevice); //graphicsDevice.Clear(Color.White); //Calculate dimensions of each brick Rectangle brickRect = new Rectangle(rect.X, rect.Y, HouseGenerator.HouseWidth / 10, HouseGenerator.HouseHeight / 10); //Calculate the number of bricks int height = rect.Height / brickRect.Height; int width = rect.Width / brickRect.Width; //Draws half a brick each time, the layer below is a half brick out from above //This gives a good effect of an actual building's bricks spriteBatch.Begin(SpriteBlendMode.AlphaBlend, SpriteSortMode.Deferred, SaveStateMode.None); for (int i = 0; i < height / 2; i++) { Rectangle sourceRect1 = new Rectangle(0, 0, brick.Width / 2, brick.Height); Rectangle sourceRect2 = new Rectangle(brick.Width / 2, 0, brick.Width / 2, brick.Height); for (int j = 0; j < width * 2; j++) { Rectangle drawRect1 = new Rectangle(rect.X + (j * (brickRect.Width / 2)), rect.Y + (i * brickRect.Height), brickRect.Width, brickRect.Height); Rectangle drawRect2 = new Rectangle(rect.X + (j * (brickRect.Width / 2)), rect.Y + ((i + 1) * brickRect.Height), brickRect.Width, brickRect.Height); spriteBatch.Draw(brick, drawRect1, sourceRect1, Color.White); spriteBatch.Draw(brick, drawRect2, sourceRect2, Color.White); sourceRect1.X += brick.Width / 2; if (sourceRect1.X >= brick.Width) { sourceRect1.X = 0; } sourceRect2.X += brick.Width / 2; if (sourceRect2.X >= brick.Width) { sourceRect2.X = 0; } } } spriteBatch.End(); return(HouseGenerator.RenderGraphicsDevice(graphicsDevice, rect)); }
public static Texture2D GenerateChimney(Texture2D brick, Rectangle rect, GraphicsDevice graphicsDevice) { //Instantiate all the variables for drawing SpriteBatch spriteBatch = new SpriteBatch(graphicsDevice); Rectangle brickRect = new Rectangle(rect.X, rect.Y, (int)Math.Round(HouseGenerator.HouseWidth / 10f), (int)Math.Round(HouseGenerator.HouseHeight / 10f)); Color brickFilter = Color.White; //graphicsDevice.Clear(Color.White); //Calculate how many bricks are needed int height = rect.Height / brickRect.Height; int width = rect.Width / brickRect.Width; spriteBatch.Begin(SpriteBlendMode.AlphaBlend, SpriteSortMode.Deferred, SaveStateMode.None); for (int i = 0; i < height / 2; i++) { Rectangle sourceRect1 = new Rectangle(0, 0, brick.Width / 2, brick.Height); Rectangle sourceRect2 = new Rectangle(brick.Width / 2, 0, brick.Width / 2, brick.Height); for (int j = 0; j < width * 2; j++) { Rectangle drawRect1 = new Rectangle(rect.X + (j * (brickRect.Width / 2)), rect.Y + (i * brickRect.Height), brickRect.Width, brickRect.Height); Rectangle drawRect2 = new Rectangle(rect.X + (j * (brickRect.Width / 2)), rect.Y + ((i + 1) * brickRect.Height), brickRect.Width, brickRect.Height); spriteBatch.Draw(brick, drawRect1, sourceRect1, Color.White); spriteBatch.Draw(brick, drawRect2, sourceRect2, Color.White); sourceRect1.X += brick.Width / 2; if (sourceRect1.X >= brick.Width) { sourceRect1.X = 0; } sourceRect2.X += brick.Width / 2; if (sourceRect2.X >= brick.Width) { sourceRect2.X = 0; } } } spriteBatch.End(); return(HouseGenerator.RenderGraphicsDevice(graphicsDevice, rect)); }