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.

65 lines
1.8 KiB

  1. using Microsoft.Xna.Framework;
  2. using Microsoft.Xna.Framework.Graphics;
  3. using System.Collections.Generic;
  4. namespace Jumpy {
  5. // TODO: add a WriteLine sort of functionality.
  6. static class Debug {
  7. struct DebugRect {
  8. public Rectangle rect;
  9. public Color color;
  10. public DebugRect(Rectangle rect, Color color) {
  11. this.rect = rect;
  12. this.color = color;
  13. }
  14. }
  15. public static bool Enabled;
  16. static List<DebugRect> rects = new List<DebugRect>();
  17. static Texture2D whiteTexture;
  18. public static void WriteLine(string s) {
  19. System.Diagnostics.Debug.WriteLine(s);
  20. }
  21. public static void WriteLine(string s, params object[] args) {
  22. System.Diagnostics.Debug.WriteLine(s, args);
  23. }
  24. public static void Initialize(GraphicsDevice graphics) {
  25. whiteTexture = new Texture2D(graphics, 1, 1);
  26. whiteTexture.SetData(new Color[] { Color.White });
  27. }
  28. public static void Clear() {
  29. rects.Clear();
  30. }
  31. public static void AddRect(Rectangle rect, Color color) {
  32. rects.Add(new DebugRect(rect, color));
  33. }
  34. public static void Draw(SpriteBatch spriteBatch) {
  35. if (!Enabled) {
  36. return;
  37. }
  38. foreach (var debugRect in rects) {
  39. var rect = debugRect.rect;
  40. var color = debugRect.color;
  41. // top side
  42. spriteBatch.Draw(
  43. whiteTexture, new Rectangle(rect.Left, rect.Top, rect.Width, 1), color);
  44. // bottom side
  45. spriteBatch.Draw(
  46. whiteTexture, new Rectangle(rect.Left, rect.Bottom - 1, rect.Width, 1), color);
  47. // left side
  48. spriteBatch.Draw(
  49. whiteTexture, new Rectangle(rect.Left, rect.Top, 1, rect.Height), color);
  50. // right side
  51. spriteBatch.Draw(
  52. whiteTexture, new Rectangle(rect.Right - 1, rect.Top, 1, rect.Height), color);
  53. }
  54. }
  55. }
  56. }