PageRenderTime 43ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/InputSystem/Tests/WiiMote.cs

#
C# | 80 lines | 66 code | 2 blank | 12 comment | 4 complexity | ce53ffb142222a8d93d1f7b6e692176f MD5 | raw file
Possible License(s): Apache-2.0
  1. using Delta.Engine;
  2. using Delta.Rendering.Basics.Fonts;
  3. using Delta.Utilities.Datatypes;
  4. using NUnit.Framework;
  5. namespace Delta.InputSystem.Tests
  6. {
  7. /// <summary>
  8. /// Testing the WiiMote device.
  9. /// </summary>
  10. internal class WiiMote
  11. {
  12. #region CheckWiiMoteStates (Static)
  13. /// <summary>
  14. /// Check WiiMote states
  15. /// </summary>
  16. [Test, Category("Visual")]
  17. public static void CheckWiiMoteStates()
  18. {
  19. Application.Start(delegate
  20. {
  21. Font.Default.Draw(
  22. "GamePad IsConnected " + Input.GamePad.IsConnected,
  23. Rectangle.FromCenter(new Point(0.5f, 0.45f), Size.Half));
  24. Font.Default.Draw(
  25. "A " + Input.GamePad.GetState(InputButton.GamePadA),
  26. Rectangle.FromCenter(new Point(0.5f, 0.50f), Size.Half));
  27. // Also rumble if the A button was pressed
  28. if (Input.GamePad.UpIsPressed)
  29. {
  30. Input.GamePad.Rumble(0.0f, 0.0f);
  31. }
  32. Font.Default.Draw(
  33. "B " + Input.GamePad.GetState(InputButton.GamePadB),
  34. Rectangle.FromCenter(new Point(0.5f, 0.55f), Size.Half));
  35. Font.Default.Draw(
  36. "Accelerometer Position" + Input.Accelerometer.Position.ToString(),
  37. Rectangle.FromCenter(new Point(0.5f, 0.60f), Size.Half));
  38. // Move the cursor left or right to check the cursor
  39. Font.Default.Draw(
  40. "Cursor Position" + Input.GamePad.Position.ToString(),
  41. Rectangle.FromCenter(new Point(0.5f, 0.65f), Size.Half));
  42. });
  43. }
  44. #endregion
  45. #region CheckRummble (Static)
  46. /// <summary>
  47. /// Check if the device rumbles and stops rumbling if certain keys are
  48. /// pressed
  49. /// </summary>
  50. [Test, Category("Visual")]
  51. public static void CheckRummble()
  52. {
  53. Application.Start(delegate
  54. {
  55. if (Input.GamePad.IsConnected)
  56. {
  57. Font.Default.Draw(
  58. "Press 'A' to Rumble and release and 'B' to stop rumbling",
  59. Rectangle.FromCenter(new Point(0.5f, 0.45f), Size.Half));
  60. if (Input.GamePad.IsPressed(InputButton.GamePadA))
  61. {
  62. Input.GamePad.Rumble(5.0f, 5.0f);
  63. }
  64. if (Input.GamePad.IsPressed(InputButton.GamePadB))
  65. {
  66. Input.GamePad.Rumble(false);
  67. }
  68. }
  69. else
  70. {
  71. Font.Default.Draw("Wii not connected!",
  72. Rectangle.FromCenter(new Point(0.5f, 0.45f), Size.Half));
  73. }
  74. });
  75. }
  76. #endregion
  77. }
  78. }