public void Draw(SpriteBatch spritebatch) { List<IDrawable> SortDrawables() { List<IDrawable> drawables = new List<IDrawable>(); List<IDrawable> itemsToInsert = new List<IDrawable>(); itemsToInsert.AddRange(world.Pjs.Values); itemsToInsert.AddRange(world.Drops.Values); itemsToInsert.Sort((a, b) => b.GetSortY().CompareTo(a.GetSortY())); int mazeW = world.maze.GetLength(1); int mazeH = world.maze.GetLength(0); for (int y = 0; y < mazeH; y++) { for (int i = itemsToInsert.Count - 1; i >= 0; i--) { IDrawable item = itemsToInsert[i]; Rectangle itemAabb = ((IIntersectable)item).GetAABB(); int leftX = itemAabb.Left / Tile.Size; int rightX = itemAabb.Right / Tile.Size; if (leftX < 0 || rightX >= world.maze.GetLength(1)) { itemsToInsert.RemoveAt(i); } else { Cell leftCell = world.maze[y, leftX]; Cell rightCell = world.maze[y, rightX]; if (item.GetSortY() < leftCell.GetSortY() && item.GetSortY() < rightCell.GetSortY()) { drawables.Add(item); itemsToInsert.RemoveAt(i); } } } for (int x = 0; x < mazeW; x++) { drawables.Add(world.maze[y, x]); } } return drawables; } // Draw the game onto a texture spritebatch.GraphicsDevice.SetRenderTarget(renderTarget); { // Draw Background spritebatch.GraphicsDevice.Clear(Color.TransparentBlack); biomeBackgroundEffect.Parameters["u_blendMode"].SetValue((int)biome.BackgroundBlendingMode); spritebatch.Begin(SpriteSortMode.Immediate, null, SamplerState.PointWrap, null, null, biomeBackgroundEffect); spritebatch.Draw(biome.BackgroundOverlayTexture ?? pixel, renderTargetRectangle, renderTargetRectangle, biome.BackgroundColor); spritebatch.End(); // Draw floor biomeBackgroundEffect.Parameters["u_blendMode"].SetValue((int)biome.FloorBlendingMode); spritebatch.Begin(SpriteSortMode.Deferred, null, SamplerState.PointWrap, null, null, biomeBackgroundEffect, cameraMatrix); spritebatch.Draw(biome.FloorOverlayTexture ?? pixel, floorRectangle, floorRectangle, biome.FloorColor); spritebatch.End(); spritebatch.Begin(SpriteSortMode.Deferred, null, null, null, null, null, cameraMatrix); foreach (IDrawable drawable in SortDrawables()) { drawable.Draw(spritebatch, cameraMatrix); } spritebatch.End(); } // Post-process the texture and draw it to the back buffer spritebatch.GraphicsDevice.SetRenderTarget(null); spritebatch.GraphicsDevice.Clear(Color.Crimson); { spritebatch.Begin(SpriteSortMode.Immediate, null, null, null, null, biomeEffect); spritebatch.Draw(renderTarget, renderTargetRectangle, Color.White); spritebatch.End(); } }
public void Draw(SpriteBatch spritebatch) { List <IDrawable> SortDrawables() { List <IDrawable> drawables = new List <IDrawable>(); List <IDrawable> itemsToInsert = new List <IDrawable>(); itemsToInsert.AddRange(world.Pjs.Values); itemsToInsert.AddRange(world.Drops.Values); itemsToInsert.Sort((a, b) => b.GetSortY().CompareTo(a.GetSortY())); int mazeW = world.maze.GetLength(1); int mazeH = world.maze.GetLength(0); for (int y = 0; y < mazeH; y++) { for (int i = itemsToInsert.Count - 1; i >= 0; i--) { IDrawable item = itemsToInsert[i]; Rectangle itemAabb = ((IIntersectable)item).GetAABB(); int leftX = itemAabb.Left / Tile.Size; int rightX = itemAabb.Right / Tile.Size; if (leftX < 0 || rightX >= world.maze.GetLength(1)) { itemsToInsert.RemoveAt(i); } else { Cell leftCell = world.maze[y, leftX]; Cell rightCell = world.maze[y, rightX]; if (item.GetSortY() < leftCell.GetSortY() && item.GetSortY() < rightCell.GetSortY()) { drawables.Add(item); itemsToInsert.RemoveAt(i); } } } for (int x = 0; x < mazeW; x++) { drawables.Add(world.maze[y, x]); } } return(drawables); } // Draw the game onto a texture spritebatch.GraphicsDevice.SetRenderTarget(renderTarget); { spritebatch.GraphicsDevice.Clear(backgroundColor); spritebatch.Begin(SpriteSortMode.Deferred, null, SamplerState.PointClamp, null, null, null, cameraMatrix); spritebatch.Draw(pixel, floorRectangle, floorColor); foreach (IDrawable drawable in SortDrawables()) { drawable.Draw(spritebatch, cameraMatrix); } spritebatch.End(); } // Post-process the texture and draw it to the back buffer spritebatch.GraphicsDevice.SetRenderTarget(null); spritebatch.GraphicsDevice.Clear(Color.Crimson); { spritebatch.Begin(); spritebatch.Draw(renderTarget, renderTargetRectangle, biomeTintColor); spritebatch.End(); } // Draw extra gameplay elements (projected into world space but not affected by post-processing) { spritebatch.Begin(SpriteSortMode.Deferred, null, SamplerState.PointClamp, null, null, null, cameraMatrix); foreach (Pj pj in world.Pjs.Values) { if (!pj.Invisible) { spritebatch.DrawString(Button.Font, pj.ID, new Vector2(pj.x - Button.Font.MeasureString(pj.ID).X / 2, pj.y - 40), Color.White); } } foreach (TintaSplash splash in world.TintaSplashes.Values) { splash.Draw(spritebatch, cameraMatrix); } spritebatch.End(); } // Draw GUI { spritebatch.Begin(); int screenWidth = spritebatch.GraphicsDevice.PresentationParameters.BackBufferWidth; int portraitWidth = 80; int portraitPadding = 15; // the separation from one portrait to the next int sideMargin = (screenWidth - (portraitWidth + portraitPadding) * world.Pjs.Count) / 2; // the distance from the side of the screen to the first portrait int y = spritebatch.GraphicsDevice.PresentationParameters.BackBufferHeight - portraitWidth - 5; int i = 0; foreach (Pj pj in world.Pjs.Values) { spritebatch.Draw(pixel, new Rectangle(sideMargin + i * (portraitWidth + portraitPadding), y, portraitWidth, portraitWidth), new Color(Color.Black, 0.16f)); if (pj.PowerUp != null) { spritebatch.Draw(pj.PowerUp.GetIcon(), new Rectangle(sideMargin + i * (portraitWidth + portraitPadding) + 5, y + 5, portraitWidth - 10, portraitWidth - 10), pj.PowerUp.GetColor()); } spritebatch.DrawString(Button.Font, pj.ID, new Vector2(sideMargin + i * (portraitWidth + portraitPadding), y), Color.White); i++; } spritebatch.DrawString(Button.Font, $"PNG: {client.Ping}ms", new Vector2(0, 0), Color.White); TimeSpan elapsedTime = DateTime.UtcNow.Subtract(world.GameStartedTime); spritebatch.DrawString(Button.Font, $"{elapsedTime.Minutes}:{elapsedTime.Seconds},{elapsedTime.Milliseconds}", new Vector2(0, 20), Color.White); spritebatch.End(); } }