mirror of
https://github.com/openeggbert/mobile-eggbert-monogame-desktop.git
synced 2025-03-29 06:22:27 +01:00
Added support for the keyboard
This commit is contained in:
parent
cdda21a0cc
commit
b8b6e613fd
5
Def.cs
5
Def.cs
@ -72,6 +72,11 @@ namespace WindowsPhoneSpeedyBlupi
|
|||||||
Cheat9
|
Cheat9
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public enum KeyboardPress
|
||||||
|
{
|
||||||
|
None, Up, Right, Down, Left, LeftControl, Space, Escape, Pause
|
||||||
|
}
|
||||||
|
|
||||||
public const int LXIMAGE = 640;
|
public const int LXIMAGE = 640;
|
||||||
|
|
||||||
public const int LYIMAGE = 480;
|
public const int LYIMAGE = 480;
|
||||||
|
8
Game1.cs
8
Game1.cs
@ -4,6 +4,7 @@ using System;
|
|||||||
using Microsoft.Xna.Framework;
|
using Microsoft.Xna.Framework;
|
||||||
//using Microsoft.Xna.Framework.GamerServices;//todo remove me
|
//using Microsoft.Xna.Framework.GamerServices;//todo remove me
|
||||||
using Microsoft.Xna.Framework.Input;
|
using Microsoft.Xna.Framework.Input;
|
||||||
|
using Microsoft.Xna.Framework.Input.Touch;
|
||||||
using Microsoft.Xna.Framework.Media;
|
using Microsoft.Xna.Framework.Media;
|
||||||
using WindowsPhoneSpeedyBlupi;
|
using WindowsPhoneSpeedyBlupi;
|
||||||
using static System.Net.Mime.MediaTypeNames;
|
using static System.Net.Mime.MediaTypeNames;
|
||||||
@ -98,8 +99,13 @@ namespace WindowsPhoneSpeedyBlupi
|
|||||||
public Game1()
|
public Game1()
|
||||||
{
|
{
|
||||||
Exiting += OnExiting;
|
Exiting += OnExiting;
|
||||||
|
if(!TouchPanel.GetCapabilities().IsConnected)
|
||||||
|
{
|
||||||
|
this.IsMouseVisible = true;
|
||||||
|
Mouse.SetCursor(MouseCursor.Arrow);
|
||||||
|
}
|
||||||
graphics = new GraphicsDeviceManager(this);
|
graphics = new GraphicsDeviceManager(this);
|
||||||
graphics.IsFullScreen = true;
|
graphics.IsFullScreen = false;
|
||||||
base.Content.RootDirectory = "Content";
|
base.Content.RootDirectory = "Content";
|
||||||
base.TargetElapsedTime = TimeSpan.FromTicks(500000L);
|
base.TargetElapsedTime = TimeSpan.FromTicks(500000L);
|
||||||
base.InactiveSleepTime = TimeSpan.FromSeconds(1.0);
|
base.InactiveSleepTime = TimeSpan.FromSeconds(1.0);
|
||||||
|
107
InputPad.cs
107
InputPad.cs
@ -2,10 +2,12 @@
|
|||||||
// WindowsPhoneSpeedyBlupi.InputPad
|
// WindowsPhoneSpeedyBlupi.InputPad
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Diagnostics;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Microsoft.Xna.Framework.Input;
|
using Microsoft.Xna.Framework.Input;
|
||||||
using Microsoft.Xna.Framework.Input.Touch;
|
using Microsoft.Xna.Framework.Input.Touch;
|
||||||
using WindowsPhoneSpeedyBlupi;
|
using WindowsPhoneSpeedyBlupi;
|
||||||
|
using static WindowsPhoneSpeedyBlupi.Def;
|
||||||
|
|
||||||
namespace WindowsPhoneSpeedyBlupi
|
namespace WindowsPhoneSpeedyBlupi
|
||||||
{
|
{
|
||||||
@ -234,6 +236,13 @@ namespace WindowsPhoneSpeedyBlupi
|
|||||||
accelWaitZero = true;
|
accelWaitZero = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private TinyPoint createTinyPoint(int x, int y)
|
||||||
|
{
|
||||||
|
TinyPoint tinyPoint = new TinyPoint();
|
||||||
|
tinyPoint.X = x;
|
||||||
|
tinyPoint.Y = y;
|
||||||
|
return tinyPoint;
|
||||||
|
}
|
||||||
public void Update()
|
public void Update()
|
||||||
{
|
{
|
||||||
pressedGlyphs.Clear();
|
pressedGlyphs.Clear();
|
||||||
@ -249,8 +258,8 @@ namespace WindowsPhoneSpeedyBlupi
|
|||||||
StopAccel();
|
StopAccel();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
double num = 0.0;
|
double horizontalChange = 0.0;
|
||||||
double num2 = 0.0;
|
double verticalChange = 0.0;
|
||||||
int num3 = 0;
|
int num3 = 0;
|
||||||
padPressed = false;
|
padPressed = false;
|
||||||
Def.ButtonGlygh buttonGlygh = Def.ButtonGlygh.None;
|
Def.ButtonGlygh buttonGlygh = Def.ButtonGlygh.None;
|
||||||
@ -278,23 +287,58 @@ namespace WindowsPhoneSpeedyBlupi
|
|||||||
touchesOrClicks.Add(click);
|
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)
|
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))
|
if (!accelStarted && Misc.IsInside(GetPadBounds(PadCenter, padSize), tinyPoint2))
|
||||||
{
|
{
|
||||||
padPressed = true;
|
padPressed = true;
|
||||||
padTouchPos = tinyPoint2;
|
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);
|
Def.ButtonGlygh buttonGlygh2 = ButtonDetect(tinyPoint2);
|
||||||
|
Debug.WriteLine("buttonGlyph2 =" + buttonGlygh2);
|
||||||
if (buttonGlygh2 != 0)
|
if (buttonGlygh2 != 0)
|
||||||
{
|
{
|
||||||
pressedGlyphs.Add(buttonGlygh2);
|
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))
|
if ((Phase == Def.Phase.MainSetup || Phase == Def.Phase.PlaySetup) && accelSlider.Move(tinyPoint2))
|
||||||
{
|
{
|
||||||
gameData.AccelSensitivity = accelSlider.Value;
|
gameData.AccelSensitivity = accelSlider.Value;
|
||||||
@ -302,6 +346,7 @@ namespace WindowsPhoneSpeedyBlupi
|
|||||||
switch (buttonGlygh2)
|
switch (buttonGlygh2)
|
||||||
{
|
{
|
||||||
case Def.ButtonGlygh.PlayJump:
|
case Def.ButtonGlygh.PlayJump:
|
||||||
|
Debug.WriteLine("Jumping detected");
|
||||||
accelWaitZero = false;
|
accelWaitZero = false;
|
||||||
num3 |= 1;
|
num3 |= 1;
|
||||||
break;
|
break;
|
||||||
@ -372,36 +417,58 @@ namespace WindowsPhoneSpeedyBlupi
|
|||||||
lastButtonDown = buttonGlygh;
|
lastButtonDown = buttonGlygh;
|
||||||
if (padPressed)
|
if (padPressed)
|
||||||
{
|
{
|
||||||
double num4 = padTouchPos.X - PadCenter.X;
|
Debug.WriteLine("PadCenter.X=" + PadCenter.X);
|
||||||
double num5 = padTouchPos.Y - PadCenter.Y;
|
Debug.WriteLine("PadCenter.Y=" + PadCenter.Y);
|
||||||
if (num4 > 20.0)
|
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)
|
if (accelStarted)
|
||||||
{
|
{
|
||||||
num = accelSpeedX;
|
horizontalChange = accelSpeedX;
|
||||||
num2 = 0.0;
|
verticalChange = 0.0;
|
||||||
if (((uint)num3 & 4u) != 0)
|
if (((uint)num3 & 4u) != 0)
|
||||||
{
|
{
|
||||||
num2 = 1.0;
|
verticalChange = 1.0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
decor.SetSpeedX(num);
|
decor.SetSpeedX(horizontalChange);
|
||||||
decor.SetSpeedY(num2);
|
decor.SetSpeedY(verticalChange);
|
||||||
decor.KeyChange(num3);
|
decor.KeyChange(num3);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
33
Misc.cs
33
Misc.cs
@ -3,6 +3,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using Microsoft.Xna.Framework;
|
using Microsoft.Xna.Framework;
|
||||||
using WindowsPhoneSpeedyBlupi;
|
using WindowsPhoneSpeedyBlupi;
|
||||||
|
using static WindowsPhoneSpeedyBlupi.Def;
|
||||||
|
|
||||||
|
|
||||||
namespace WindowsPhoneSpeedyBlupi
|
namespace WindowsPhoneSpeedyBlupi
|
||||||
@ -119,5 +120,37 @@ namespace WindowsPhoneSpeedyBlupi
|
|||||||
}
|
}
|
||||||
return true;
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user