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.

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