PageRenderTime 123ms CodeModel.GetById 60ms app.highlight 5ms RepoModel.GetById 56ms app.codeStats 0ms

/InputSystem/Tests/WiiMote.cs

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