A stealth-based 2D platformer where you don't have to kill anyone unless you want to. https://www.semicolin.games
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

96 lines
2.6 KiB

  1. using Microsoft.Xna.Framework;
  2. using Microsoft.Xna.Framework.Graphics;
  3. using System.Collections.Generic;
  4. namespace SemiColinGames {
  5. static class Debug {
  6. struct DebugRect {
  7. public Rectangle rect;
  8. public Color color;
  9. public DebugRect(Rectangle rect, Color color) {
  10. this.rect = rect;
  11. this.color = color;
  12. }
  13. }
  14. struct DebugLine {
  15. public Point start;
  16. public Point end;
  17. public Color color;
  18. public DebugLine(Point start, Point end, Color color) {
  19. this.start = start;
  20. this.end = end;
  21. this.color = color;
  22. }
  23. }
  24. public static bool Enabled;
  25. static List<DebugRect> rects = new List<DebugRect>();
  26. static List<DebugLine> lines = new List<DebugLine>();
  27. static Texture2D whiteTexture;
  28. static string toast = null;
  29. public static void Toast(string s) {
  30. toast = s;
  31. }
  32. public static void WriteLine(string s) {
  33. System.Diagnostics.Debug.WriteLine(s);
  34. }
  35. public static void WriteLine(string s, params object[] args) {
  36. System.Diagnostics.Debug.WriteLine(s, args);
  37. }
  38. public static void Initialize(GraphicsDevice graphics) {
  39. whiteTexture = new Texture2D(graphics, 1, 1);
  40. whiteTexture.SetData(new Color[] { Color.White });
  41. }
  42. public static void Clear() {
  43. rects.Clear();
  44. lines.Clear();
  45. }
  46. public static void AddRect(Rectangle rect, Color color) {
  47. rects.Add(new DebugRect(rect, color));
  48. }
  49. public static void AddLine(Point start, Point end, Color color) {
  50. lines.Add(new DebugLine(start, end, color));
  51. }
  52. public static void DrawToast(SpriteBatch spriteBatch, SpriteFont font) {
  53. if (toast == null) {
  54. return;
  55. }
  56. spriteBatch.DrawString(font, toast, new Vector2(10, 40), Color.Teal);
  57. toast = null;
  58. }
  59. public static void Draw(SpriteBatch spriteBatch, Camera camera) {
  60. if (!Enabled) {
  61. return;
  62. }
  63. foreach (var debugRect in rects) {
  64. var rect = debugRect.rect;
  65. rect.Offset(-camera.Left, 0);
  66. var color = debugRect.color;
  67. // top side
  68. spriteBatch.Draw(
  69. whiteTexture, new Rectangle(rect.Left, rect.Top, rect.Width, 1), color);
  70. // bottom side
  71. spriteBatch.Draw(
  72. whiteTexture, new Rectangle(rect.Left, rect.Bottom - 1, rect.Width, 1), color);
  73. // left side
  74. spriteBatch.Draw(
  75. whiteTexture, new Rectangle(rect.Left, rect.Top, 1, rect.Height), color);
  76. // right side
  77. spriteBatch.Draw(
  78. whiteTexture, new Rectangle(rect.Right - 1, rect.Top, 1, rect.Height), color);
  79. }
  80. }
  81. }
  82. }