diff --git a/.gitignore b/.gitignore index 1c9a181..6e589ac 100644 --- a/.gitignore +++ b/.gitignore @@ -240,3 +240,5 @@ ModelManifest.xml # FAKE - F# Make .fake/ + +*.bak diff --git a/Accelerometer.cs b/Accelerometer.cs deleted file mode 100644 index 40729a6..0000000 --- a/Accelerometer.cs +++ /dev/null @@ -1,15 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace WindowsPhoneSpeedyBlupi -{ - public interface Accelerometer - { - void Start(); - void Stop(); - event EventHandler CurrentValueChanged; - } -} diff --git a/AccelerometerDummyImpl.cs b/AccelerometerDummyImpl.cs deleted file mode 100644 index ffa1524..0000000 --- a/AccelerometerDummyImpl.cs +++ /dev/null @@ -1,23 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace WindowsPhoneSpeedyBlupi -{ - public class AccelerometerDummyImpl : Accelerometer - { - public event EventHandler CurrentValueChanged; - - public void Start() - { - //throw new AccelerometerFailedException(); - } - - public void Stop() - { - //throw new AccelerometerFailedException(); - } - } -} diff --git a/AccelerometerEventArgs.cs b/AccelerometerEventArgs.cs deleted file mode 100644 index c70753e..0000000 --- a/AccelerometerEventArgs.cs +++ /dev/null @@ -1,23 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace WindowsPhoneSpeedyBlupi -{ - public class AccelerometerEventArgs : EventArgs - { - - public float X { get; } - public float Y { get; } - public float Z { get; } - - public AccelerometerEventArgs(float x, float y, float z) - { - X = x; - Y = y; - Z = z; - } - } -} diff --git a/AccelerometerFactory.cs b/AccelerometerFactory.cs deleted file mode 100644 index 5097a8c..0000000 --- a/AccelerometerFactory.cs +++ /dev/null @@ -1,13 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace WindowsPhoneSpeedyBlupi -{ - public class AccelerometerFactory - { - public static Accelerometer Create() { return new AccelerometerDummyImpl(); } - } -} diff --git a/AccelerometerFailedException.cs b/AccelerometerFailedException.cs deleted file mode 100644 index d388fa7..0000000 --- a/AccelerometerFailedException.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace WindowsPhoneSpeedyBlupi -{ - public class AccelerometerFailedException : Exception - { - } -} diff --git a/Def.cs b/Def.cs index b2bf44f..7954d94 100644 --- a/Def.cs +++ b/Def.cs @@ -3,10 +3,22 @@ namespace WindowsPhoneSpeedyBlupi -{ +{ public static class Def { + public const bool DETAILED_DEBUGGING = false; + + public const Platform PLATFORM = Platform.Desktop; + + public enum Platform + { + Desktop, + Android, + iOS, + Web + } + public enum Phase { None, diff --git a/Game1.cs b/Game1.cs index 507bcdd..0c4b062 100644 --- a/Game1.cs +++ b/Game1.cs @@ -979,5 +979,10 @@ namespace WindowsPhoneSpeedyBlupi this.graphics.ToggleFullScreen(); } public bool IsFullScreen() { return this.graphics.IsFullScreen; } + + public GraphicsDeviceManager getGraphics() + { + return graphics; + } } } \ No newline at end of file diff --git a/InputPad.cs b/InputPad.cs index 322256a..8ee2c25 100644 --- a/InputPad.cs +++ b/InputPad.cs @@ -4,6 +4,7 @@ using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; +using Microsoft.Devices.Sensors; using Microsoft.Xna.Framework.Input; using Microsoft.Xna.Framework.Input.Touch; using WindowsPhoneSpeedyBlupi; @@ -215,7 +216,7 @@ namespace WindowsPhoneSpeedyBlupi this.sound = sound; this.gameData = gameData; pressedGlyphs = new List(); - accelSensor = AccelerometerFactory.Create(); + accelSensor = new Accelerometer(); accelSensor.CurrentValueChanged += HandleAccelSensorCurrentValueChanged; accelSlider = new Slider { @@ -286,6 +287,44 @@ namespace WindowsPhoneSpeedyBlupi click.Y = mouseState.Y; touchesOrClicks.Add(click); } + + float screenWidth = game1.getGraphics().GraphicsDevice.Viewport.Width; + float screenHeight = game1.getGraphics().GraphicsDevice.Viewport.Height; + float screenRatio = screenWidth / screenHeight; + + if (Def.PLATFORM == Platform.Android &&screenRatio < 1.3333333333333333) + { + for (int i = 0; i < touchesOrClicks.Count; i++) + { + + var touchOrClick = touchesOrClicks[i]; + if (touchOrClick.X == -1) continue; + + float originalX = touchOrClick.X; + float originalY = touchOrClick.Y; + + float widthHeightRatio = screenWidth / screenHeight; + float heightRatio = 480 / screenHeight; + float widthRatio = 640 / screenWidth; + if(Def.DETAILED_DEBUGGING) + { + Debug.WriteLine("-----"); + Debug.WriteLine("originalX=" + originalX); + Debug.WriteLine("originalY=" + originalY); + Debug.WriteLine("heightRatio=" + heightRatio); + Debug.WriteLine("widthRatio=" + widthRatio); + Debug.WriteLine("widthHeightRatio=" + widthHeightRatio); + } + if (screenHeight> 480) { + touchOrClick.X = (int)(originalX * heightRatio); + touchOrClick.Y = (int)(originalY * heightRatio); + touchesOrClicks[i] = touchOrClick; + } + + if(Def.DETAILED_DEBUGGING) Debug.WriteLine("new X" + touchOrClick.X); + if(Def.DETAILED_DEBUGGING) Debug.WriteLine("new Y" + touchOrClick.Y); + } + } KeyboardState newState = Keyboard.GetState(); { @@ -952,12 +991,13 @@ namespace WindowsPhoneSpeedyBlupi } - private void HandleAccelSensorCurrentValueChanged(object sender, AccelerometerEventArgs e) + private void HandleAccelSensorCurrentValueChanged(object sender, SensorReadingEventArgs e) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Unknown result type (might be due to invalid IL or missing references) - float y = e.Y; + AccelerometerReading sensorReading = e.SensorReading; + float y = ((AccelerometerReading)(sensorReading)).Acceleration.Y; float num = (1f - (float)gameData.AccelSensitivity) * 0.06f + 0.04f; float num2 = (accelLastState ? (num * 0.6f) : num); if (y > num2) diff --git a/Microsoft.Devices.Sensors/Accelerometer.cs b/Microsoft.Devices.Sensors/Accelerometer.cs new file mode 100644 index 0000000..2856b67 --- /dev/null +++ b/Microsoft.Devices.Sensors/Accelerometer.cs @@ -0,0 +1,10 @@ +using Microsoft.Devices.Sensors; + +namespace Microsoft.Devices.Sensors +{ + public class Accelerometer : SensorBase + { + public void Start() { } + public void Stop() { } + } +} diff --git a/Microsoft.Devices.Sensors/AccelerometerFailedException.cs b/Microsoft.Devices.Sensors/AccelerometerFailedException.cs new file mode 100644 index 0000000..e125b68 --- /dev/null +++ b/Microsoft.Devices.Sensors/AccelerometerFailedException.cs @@ -0,0 +1,6 @@ +namespace Microsoft.Devices.Sensors +{ + public class AccelerometerFailedException : SensorFailedException + { + } +} diff --git a/Microsoft.Devices.Sensors/AccelerometerReading.cs b/Microsoft.Devices.Sensors/AccelerometerReading.cs new file mode 100644 index 0000000..48663e8 --- /dev/null +++ b/Microsoft.Devices.Sensors/AccelerometerReading.cs @@ -0,0 +1,12 @@ +using System; +using Microsoft.Xna.Framework; + +namespace Microsoft.Devices.Sensors + +{ + public struct AccelerometerReading : ISensorReading + { + public Vector3 Acceleration { get; internal set; } + public DateTimeOffset Timestamp { get; internal set; } + } +} diff --git a/Microsoft.Devices.Sensors/ISensorReading.cs b/Microsoft.Devices.Sensors/ISensorReading.cs new file mode 100644 index 0000000..02cc293 --- /dev/null +++ b/Microsoft.Devices.Sensors/ISensorReading.cs @@ -0,0 +1,10 @@ +using System; + +namespace Microsoft.Devices.Sensors + +{ + public interface ISensorReading + { + DateTimeOffset Timestamp { get; } + } +} diff --git a/Microsoft.Devices.Sensors/SensorBase.cs b/Microsoft.Devices.Sensors/SensorBase.cs new file mode 100644 index 0000000..d82bdd0 --- /dev/null +++ b/Microsoft.Devices.Sensors/SensorBase.cs @@ -0,0 +1,15 @@ +using System; + +namespace Microsoft.Devices.Sensors +{ + public abstract class SensorBase : IDisposable where TSensorReading : ISensorReading + { + private TSensorReading currentValue; + + public event EventHandler> CurrentValueChanged; + + public void Dispose() + { + } + } +} \ No newline at end of file diff --git a/Microsoft.Devices.Sensors/SensorFailedException.cs b/Microsoft.Devices.Sensors/SensorFailedException.cs new file mode 100644 index 0000000..4eb2813 --- /dev/null +++ b/Microsoft.Devices.Sensors/SensorFailedException.cs @@ -0,0 +1,8 @@ +using System; + +namespace Microsoft.Devices.Sensors +{ + public class SensorFailedException : Exception + { + } +} diff --git a/Microsoft.Devices.Sensors/SensorReadingEventArgs.cs b/Microsoft.Devices.Sensors/SensorReadingEventArgs.cs new file mode 100644 index 0000000..81f4627 --- /dev/null +++ b/Microsoft.Devices.Sensors/SensorReadingEventArgs.cs @@ -0,0 +1,10 @@ +using System; + +namespace Microsoft.Devices.Sensors +{ + + public class SensorReadingEventArgs : EventArgs where T : ISensorReading + { + public T SensorReading { get; set; } + } +} \ No newline at end of file diff --git a/Misc.cs b/Misc.cs index d8ca51b..ca5575d 100644 --- a/Misc.cs +++ b/Misc.cs @@ -1,6 +1,7 @@ // WindowsPhoneSpeedyBlupi, Version=1.0.0.5, Culture=neutral, PublicKeyToken=6db12cd62dbec439 // WindowsPhoneSpeedyBlupi.Misc using System; +using System.Diagnostics; using Microsoft.Xna.Framework; using WindowsPhoneSpeedyBlupi; using static WindowsPhoneSpeedyBlupi.Def; @@ -133,7 +134,7 @@ namespace WindowsPhoneSpeedyBlupi case 6: return KeyboardPress.Space; case 7: return KeyboardPress.Escape; case 8: return KeyboardPress.Pause; - default: throw new Exception("Unsupported number for KeyboardPress: " + i); + default: Debug.WriteLine("Unsupported number for KeyboardPress: " + i); return KeyboardPress.None; } } public static int keyboardPressToInt(KeyboardPress kp) diff --git a/Pixmap.cs b/Pixmap.cs index 85c5cbf..74d33cb 100644 --- a/Pixmap.cs +++ b/Pixmap.cs @@ -1,6 +1,7 @@ // WindowsPhoneSpeedyBlupi, Version=1.0.0.5, Culture=neutral, PublicKeyToken=6db12cd62dbec439 // WindowsPhoneSpeedyBlupi.Pixmap using System; +using System.Diagnostics; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using WindowsPhoneSpeedyBlupi; @@ -63,20 +64,23 @@ namespace WindowsPhoneSpeedyBlupi get { TinyRect result = default(TinyRect); - double num = graphics.GraphicsDevice.Viewport.Width; - double num2 = graphics.GraphicsDevice.Viewport.Height; - if (num != 0.0 && num2 != 0.0) + double screenWidth = graphics.GraphicsDevice.Viewport.Width; + double screenHeight = graphics.GraphicsDevice.Viewport.Height; + if(Def.PLATFORM == Def.Platform.Android && screenHeight > 480) { + screenWidth = screenHeight * (640f / 480f); + } + if (screenWidth != 0.0 && screenHeight != 0.0) { double num3; double num4; - if (num / num2 < 1.3333333333333333) + if (screenWidth / screenHeight < 1.3333333333333333) { num3 = 640.0; - num4 = 640.0 * (num2 / num); + num4 = 640.0 * (screenHeight / screenWidth); } else { - num3 = 480.0 * (num / num2); + num3 = 480.0 * (screenWidth / screenHeight); num4 = 480.0; } result.Left = 0; @@ -242,13 +246,17 @@ namespace WindowsPhoneSpeedyBlupi private void UpdateGeometry() { - double num = graphics.GraphicsDevice.Viewport.Width; - double num2 = graphics.GraphicsDevice.Viewport.Height; - double val = num / 640.0; - double val2 = num2 / 480.0; + double screenWidth = graphics.GraphicsDevice.Viewport.Width; + double screenHeight = graphics.GraphicsDevice.Viewport.Height; + if (Def.PLATFORM == Def.Platform.Android && screenHeight > 480) + { + screenWidth = screenHeight * (640f / 480f); + } + double val = screenWidth / 640.0; + double val2 = screenHeight / 480.0; zoom = Math.Min(val, val2); - originX = (num - 640.0 * zoom) / 2.0; - originY = (num2 - 480.0 * zoom) / 2.0; + originX = (screenWidth - 640.0 * zoom) / 2.0; + originY = (screenHeight - 480.0 * zoom) / 2.0; } public void BackgroundCache(string name) @@ -269,11 +277,15 @@ namespace WindowsPhoneSpeedyBlupi public void DrawBackground() { - double num = graphics.GraphicsDevice.Viewport.Width; - double num2 = graphics.GraphicsDevice.Viewport.Height; + double screenWidth = graphics.GraphicsDevice.Viewport.Width; + double screenHeight = graphics.GraphicsDevice.Viewport.Height; + if (Def.PLATFORM == Def.Platform.Android && screenHeight > 480) + { + screenWidth = screenHeight * (640f / 480f); + } Texture2D bitmap = GetBitmap(3); Rectangle srcRectangle = GetSrcRectangle(bitmap, 10, 10, 10, 10, 0, 0); - Rectangle destinationRectangle = new Rectangle(0, 0, (int)num, (int)num2); + Rectangle destinationRectangle = new Rectangle(0, 0, (int)screenWidth, (int)screenHeight); spriteBatch.Begin(SpriteSortMode.BackToFront, BlendState.AlphaBlend); spriteBatch.Draw(bitmap, destinationRectangle, srcRectangle, Color.White); spriteBatch.End(); diff --git a/Worlds.cs b/Worlds.cs index 941e919..09aa315 100644 --- a/Worlds.cs +++ b/Worlds.cs @@ -42,16 +42,17 @@ namespace WindowsPhoneSpeedyBlupi text = streamReader.ReadToEnd(); stream.Close(); } - catch + catch (Exception e) { + Debug.Write(e.Message); Debug.Write("Fatal error. Loading world failed: " + worldFilename + "\n"); - Environment.Exit(1); + //Environment.Exit(1); } if (text == null) { return null; } - return text.Split('\n'); + return text.Split("\n"); } private static string GetWorldFilename(int gamer, int rank)