debugprintq.bmx 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. ' Debug Print Queue...
  2. ' Copy and paste the DebugQ type and the PrintQ/UpdateQ functions. Use
  3. ' PrintQ to add a debug message to your game, and UpdateQ in your main
  4. ' loop to display/update messages...
  5. Type DebugQ
  6. Global DebugQList:TList
  7. Field message$
  8. Field alpha# = 1
  9. Function Print (message$)
  10. If DebugQList = Null Then DebugQList= New TList
  11. p:DebugQ = New DebugQ
  12. p.message = message$
  13. DebugQList.AddLast p
  14. End Function
  15. Function Update (alphacut# = 0.01)
  16. If DebugQList = Null Then Return
  17. y = 0
  18. For p:DebugQ = EachIn DebugQList
  19. SetBlend ALPHABLEND
  20. SetAlpha p.alpha
  21. DrawText p.message$, 0, y
  22. y = y + TextHeight("")
  23. p.alpha = p.alpha - alphacut; If p.alpha < 0 Then DebugQList.Remove p
  24. Next
  25. SetBlend SOLID ' Need to get old values!
  26. SetAlpha 1 ' Need to get old values!
  27. End Function
  28. End Type
  29. ' Functional interfaces for non-OO'ers...
  30. Function PrintQ (message$)
  31. DebugQ.Print message$
  32. End Function
  33. Function UpdateQ ()
  34. DebugQ.Update
  35. End Function
  36. ' D E M O . . .
  37. Graphics 640, 480
  38. Repeat
  39. Cls
  40. x = MouseX ()
  41. y = MouseY ()
  42. DrawRect x, y, 32, 32
  43. ' Add items to debug print queue...
  44. If MouseHit (1) Then PrintQ "Left mouse button hit!"
  45. If MouseHit (2) Then PrintQ "Right mouse button hit!"
  46. ' Print/remove all debug items...
  47. UpdateQ
  48. DrawText "Click mouse...", 0, GraphicsHeight () - 20
  49. Flip
  50. Until KeyHit (KEY_ESCAPE)
  51. End