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.

78 lines
2.2 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. public static bool Enabled;
  15. static List<DebugRect> rects = new List<DebugRect>();
  16. static Texture2D whiteTexture;
  17. static string toast = null;
  18. public static void Toast(string s) {
  19. toast = s;
  20. }
  21. public static void WriteLine(string s) {
  22. System.Diagnostics.Debug.WriteLine(s);
  23. }
  24. public static void WriteLine(string s, params object[] args) {
  25. System.Diagnostics.Debug.WriteLine(s, args);
  26. }
  27. public static void Initialize(GraphicsDevice graphics) {
  28. whiteTexture = new Texture2D(graphics, 1, 1);
  29. whiteTexture.SetData(new Color[] { Color.White });
  30. }
  31. public static void Clear() {
  32. rects.Clear();
  33. }
  34. public static void AddRect(Rectangle rect, Color color) {
  35. rects.Add(new DebugRect(rect, color));
  36. }
  37. public static void DrawToast(SpriteBatch spriteBatch, SpriteFont font) {
  38. if (toast == null) {
  39. return;
  40. }
  41. spriteBatch.DrawString(font, toast, new Vector2(10, 40), Color.Teal);
  42. toast = null;
  43. }
  44. public static void Draw(SpriteBatch spriteBatch, Camera camera) {
  45. if (!Enabled) {
  46. return;
  47. }
  48. foreach (var debugRect in rects) {
  49. var rect = debugRect.rect;
  50. rect.Offset(-camera.Left, 0);
  51. var color = debugRect.color;
  52. // top side
  53. spriteBatch.Draw(
  54. whiteTexture, new Rectangle(rect.Left, rect.Top, rect.Width, 1), color);
  55. // bottom side
  56. spriteBatch.Draw(
  57. whiteTexture, new Rectangle(rect.Left, rect.Bottom - 1, rect.Width, 1), color);
  58. // left side
  59. spriteBatch.Draw(
  60. whiteTexture, new Rectangle(rect.Left, rect.Top, 1, rect.Height), color);
  61. // right side
  62. spriteBatch.Draw(
  63. whiteTexture, new Rectangle(rect.Right - 1, rect.Top, 1, rect.Height), color);
  64. }
  65. }
  66. }
  67. }