From b8b6e613fd7d8c87fd46f8333148c8df5efac9b5 Mon Sep 17 00:00:00 2001 From: Your Name Date: Sun, 24 Nov 2024 01:33:27 +0100 Subject: [PATCH] Added support for the keyboard --- Def.cs | 5 +++ Game1.cs | 8 +++- InputPad.cs | 107 ++++++++++++++++++++++++++++++++++++++++++---------- Misc.cs | 33 ++++++++++++++++ 4 files changed, 132 insertions(+), 21 deletions(-) diff --git a/Def.cs b/Def.cs index 5f457f9..b2bf44f 100644 --- a/Def.cs +++ b/Def.cs @@ -72,6 +72,11 @@ namespace WindowsPhoneSpeedyBlupi Cheat9 } + public enum KeyboardPress + { + None, Up, Right, Down, Left, LeftControl, Space, Escape, Pause + } + public const int LXIMAGE = 640; public const int LYIMAGE = 480; diff --git a/Game1.cs b/Game1.cs index d84850d..1c4d5cf 100644 --- a/Game1.cs +++ b/Game1.cs @@ -4,6 +4,7 @@ using System; using Microsoft.Xna.Framework; //using Microsoft.Xna.Framework.GamerServices;//todo remove me using Microsoft.Xna.Framework.Input; +using Microsoft.Xna.Framework.Input.Touch; using Microsoft.Xna.Framework.Media; using WindowsPhoneSpeedyBlupi; using static System.Net.Mime.MediaTypeNames; @@ -98,8 +99,13 @@ namespace WindowsPhoneSpeedyBlupi public Game1() { Exiting += OnExiting; + if(!TouchPanel.GetCapabilities().IsConnected) + { + this.IsMouseVisible = true; + Mouse.SetCursor(MouseCursor.Arrow); + } graphics = new GraphicsDeviceManager(this); - graphics.IsFullScreen = true; + graphics.IsFullScreen = false; base.Content.RootDirectory = "Content"; base.TargetElapsedTime = TimeSpan.FromTicks(500000L); base.InactiveSleepTime = TimeSpan.FromSeconds(1.0); diff --git a/InputPad.cs b/InputPad.cs index 125b0e8..d4347af 100644 --- a/InputPad.cs +++ b/InputPad.cs @@ -2,10 +2,12 @@ // WindowsPhoneSpeedyBlupi.InputPad using System; using System.Collections.Generic; +using System.Diagnostics; using System.Linq; using Microsoft.Xna.Framework.Input; using Microsoft.Xna.Framework.Input.Touch; using WindowsPhoneSpeedyBlupi; +using static WindowsPhoneSpeedyBlupi.Def; namespace WindowsPhoneSpeedyBlupi { @@ -234,6 +236,13 @@ namespace WindowsPhoneSpeedyBlupi accelWaitZero = true; } + private TinyPoint createTinyPoint(int x, int y) + { + TinyPoint tinyPoint = new TinyPoint(); + tinyPoint.X = x; + tinyPoint.Y = y; + return tinyPoint; + } public void Update() { pressedGlyphs.Clear(); @@ -249,8 +258,8 @@ namespace WindowsPhoneSpeedyBlupi StopAccel(); } } - double num = 0.0; - double num2 = 0.0; + double horizontalChange = 0.0; + double verticalChange = 0.0; int num3 = 0; padPressed = false; Def.ButtonGlygh buttonGlygh = Def.ButtonGlygh.None; @@ -278,23 +287,58 @@ namespace WindowsPhoneSpeedyBlupi touchesOrClicks.Add(click); } + KeyboardState newState = Keyboard.GetState(); + { + if(newState.IsKeyDown(Keys.LeftControl)) touchesOrClicks.Add(createTinyPoint(-1, Misc.keyboardPressToInt(KeyboardPress.LeftControl))); + if (newState.IsKeyDown(Keys.Up)) touchesOrClicks.Add(createTinyPoint(-1, Misc.keyboardPressToInt(KeyboardPress.Up))); + if (newState.IsKeyDown(Keys.Right)) touchesOrClicks.Add(createTinyPoint(-1, Misc.keyboardPressToInt(KeyboardPress.Right))); + if (newState.IsKeyDown(Keys.Down)) touchesOrClicks.Add(createTinyPoint(-1, Misc.keyboardPressToInt(KeyboardPress.Down))); + if (newState.IsKeyDown(Keys.Left)) touchesOrClicks.Add(createTinyPoint(-1, Misc.keyboardPressToInt(KeyboardPress.Left))); + if (newState.IsKeyDown(Keys.Space)) touchesOrClicks.Add(createTinyPoint(-1, Misc.keyboardPressToInt(KeyboardPress.Space))); + } - + KeyboardPress keyboardPress_ = KeyboardPress.None; foreach (TinyPoint touchOrClick in touchesOrClicks) { - + Boolean keyboardPressed = false; + if (touchOrClick.X == -1) { - TinyPoint tinyPoint2 = touchOrClick; + keyboardPressed = true; + } + KeyboardPress keyboardPress = keyboardPressed ? Misc.intToKeyboardPress(touchOrClick.Y) : KeyboardPress.None; + keyboardPress_ = keyboardPress; + if (keyboardPress_ != KeyboardPress.None) + { + Debug.WriteLine("Pressed: " + keyboardPress_); + } + + { + TinyPoint tinyPoint2 = keyboardPressed ? createTinyPoint(1,1) : touchOrClick; if (!accelStarted && Misc.IsInside(GetPadBounds(PadCenter, padSize), tinyPoint2)) { padPressed = true; padTouchPos = tinyPoint2; } + if(keyboardPress == KeyboardPress.Up || keyboardPress == KeyboardPress.Right || keyboardPress == KeyboardPress.Down || keyboardPress == KeyboardPress.Left) + { + padPressed = true; + } + Debug.WriteLine("padPressed=" + padPressed); Def.ButtonGlygh buttonGlygh2 = ButtonDetect(tinyPoint2); + Debug.WriteLine("buttonGlyph2 =" + buttonGlygh2); if (buttonGlygh2 != 0) { pressedGlyphs.Add(buttonGlygh2); } + if(keyboardPressed) + { + switch (keyboardPress) + { + case KeyboardPress.LeftControl: buttonGlygh2 = Def.ButtonGlygh.PlayJump; pressedGlyphs.Add(buttonGlygh2); break; + case KeyboardPress.Space: buttonGlygh2 = Def.ButtonGlygh.PlayAction; pressedGlyphs.Add(buttonGlygh2); break; + } + } + if ((Phase == Def.Phase.MainSetup || Phase == Def.Phase.PlaySetup) && accelSlider.Move(tinyPoint2)) { gameData.AccelSensitivity = accelSlider.Value; @@ -302,6 +346,7 @@ namespace WindowsPhoneSpeedyBlupi switch (buttonGlygh2) { case Def.ButtonGlygh.PlayJump: + Debug.WriteLine("Jumping detected"); accelWaitZero = false; num3 |= 1; break; @@ -372,36 +417,58 @@ namespace WindowsPhoneSpeedyBlupi lastButtonDown = buttonGlygh; if (padPressed) { - double num4 = padTouchPos.X - PadCenter.X; - double num5 = padTouchPos.Y - PadCenter.Y; - if (num4 > 20.0) + Debug.WriteLine("PadCenter.X=" + PadCenter.X); + Debug.WriteLine("PadCenter.Y=" + PadCenter.Y); + Debug.WriteLine("padTouchPos.X=" + padTouchPos.X); + Debug.WriteLine("padTouchPos.Y=" + padTouchPos.Y); + if (keyboardPress_ != KeyboardPress.None) { - num += 1.0; + switch (keyboardPress_) + { + case KeyboardPress.Up: padTouchPos.X = PadCenter.X; padTouchPos.Y = PadCenter.Y - 30;break; + case KeyboardPress.Down: padTouchPos.X = PadCenter.X; padTouchPos.Y = PadCenter.Y + 30; break; + case KeyboardPress.Left: padTouchPos.X = PadCenter.X - 30; padTouchPos.Y = PadCenter.Y; break; + case KeyboardPress.Right: padTouchPos.X = PadCenter.X + 30; padTouchPos.Y = PadCenter.Y; break; + } } - if (num4 < -20.0) + double horizontalPosition = padTouchPos.X - PadCenter.X; + double verticalPosition = padTouchPos.Y - PadCenter.Y; + + if (horizontalPosition > 20.0) { - num -= 1.0; + horizontalChange += 1.0; + Debug.WriteLine(" horizontalChange += 1.0;"); } - if (num5 > 20.0) + if (horizontalPosition < -20.0) { - num2 += 1.0; + horizontalChange -= 1.0; + Debug.WriteLine(" horizontalChange -= 1.0;"); + } - if (num5 < -20.0) + if (verticalPosition > 20.0) { - num2 -= 1.0; + verticalChange += 1.0; + Debug.WriteLine(" verticalPosition += 1.0;"); + } + if (verticalPosition < -20.0) + { + verticalChange -= 1.0; + Debug.WriteLine(" verticalPosition -= 1.0;"); + } + } if (accelStarted) { - num = accelSpeedX; - num2 = 0.0; + horizontalChange = accelSpeedX; + verticalChange = 0.0; if (((uint)num3 & 4u) != 0) { - num2 = 1.0; + verticalChange = 1.0; } } - decor.SetSpeedX(num); - decor.SetSpeedY(num2); + decor.SetSpeedX(horizontalChange); + decor.SetSpeedY(verticalChange); decor.KeyChange(num3); } diff --git a/Misc.cs b/Misc.cs index b097c6f..d8ca51b 100644 --- a/Misc.cs +++ b/Misc.cs @@ -3,6 +3,7 @@ using System; using Microsoft.Xna.Framework; using WindowsPhoneSpeedyBlupi; +using static WindowsPhoneSpeedyBlupi.Def; namespace WindowsPhoneSpeedyBlupi @@ -119,5 +120,37 @@ namespace WindowsPhoneSpeedyBlupi } return true; } + + public static KeyboardPress intToKeyboardPress(int i) { + switch (i) + { + case 0: return KeyboardPress.None; + case 1: return KeyboardPress.Up; + case 2: return KeyboardPress.Right; + case 3: return KeyboardPress.Down; + case 4: return KeyboardPress.Left; + case 5: return KeyboardPress.LeftControl; + case 6: return KeyboardPress.Space; + case 7: return KeyboardPress.Escape; + case 8: return KeyboardPress.Pause; + default: throw new Exception("Unsupported number for KeyboardPress: " + i); + } + } + public static int keyboardPressToInt(KeyboardPress kp) + { + switch (kp) + { + case KeyboardPress.None: return 0; + case KeyboardPress.Up: return 1; + case KeyboardPress.Right: return 2; + case KeyboardPress.Down: return 3; + case KeyboardPress.Left: return 4; + case KeyboardPress.LeftControl: return 5; + case KeyboardPress.Space: return 6; + case KeyboardPress.Escape: return 7; + case KeyboardPress.Pause: return 8; + default: throw new Exception("Unsupported KeyboardPress: " + kp); + } + } } } \ No newline at end of file