Both the Android and Desktop versions were synchronized

This commit is contained in:
Robert Vokac 2024-12-21 16:53:13 +01:00
parent e640eaee2f
commit 76115df37d
12 changed files with 29 additions and 128 deletions

2
.gitignore vendored
View File

@ -241,3 +241,5 @@ ModelManifest.xml
# FAKE - F# Make
.fake/
rv.keystore
*.bak

View File

@ -1,25 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Devices.Sensors;
namespace WindowsPhoneSpeedyBlupi
{
public class AccelerometerAndroidImpl : IAccelerometer
{
public event EventHandler<AccelerometerEventArgs> CurrentValueChanged;
private Accelerometer accelerometer = new Accelerometer();
public void Start()
{
accelerometer.Start();
}
public void Stop()
{
accelerometer.Stop();
}
}
}

View File

@ -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 : IAccelerometer
{
public event EventHandler<AccelerometerEventArgs> CurrentValueChanged;
public void Start()
{
//throw new AccelerometerFailedException();
}
public void Stop()
{
//throw new AccelerometerFailedException();
}
}
}

View File

@ -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;
}
}
}

View File

@ -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 IAccelerometer Create() { return new AccelerometerDummyImpl(); }
}
}

View File

@ -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
{
}
}

14
Def.cs
View File

@ -3,10 +3,22 @@
namespace WindowsPhoneSpeedyBlupi
{
{
public static class Def
{
public const bool DETAILED_DEBUGGING = false;
public const Platform PLATFORM = Platform.Android;
public enum Platform
{
Desktop,
Android,
iOS,
Web
}
public enum Phase
{
None,

View File

@ -979,6 +979,7 @@ namespace WindowsPhoneSpeedyBlupi
this.graphics.ToggleFullScreen();
}
public bool IsFullScreen() { return this.graphics.IsFullScreen; }
public GraphicsDeviceManager getGraphics()
{
return graphics;

View File

@ -1,15 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace WindowsPhoneSpeedyBlupi
{
public interface IAccelerometer
{
void Start();
void Stop();
event EventHandler<AccelerometerEventArgs> CurrentValueChanged;
}
}

View File

@ -287,44 +287,42 @@ 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 (screenRatio < 1.3333333333333333 && false)
if (Def.PLATFORM == Platform.Android &&screenRatio < 1.3333333333333333)
{
for (int i = 0; i < touchesOrClicks.Count; i++)
{
//if (touchOrClick.X == -1) continue;
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;
}
Debug.WriteLine("new X" + touchOrClick.X);
Debug.WriteLine("new Y" + touchOrClick.Y);
if(Def.DETAILED_DEBUGGING) Debug.WriteLine("new X" + touchOrClick.X);
if(Def.DETAILED_DEBUGGING) Debug.WriteLine("new Y" + touchOrClick.Y);
}
}

View File

@ -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: return KeyboardPress.None; //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)

View File

@ -66,7 +66,7 @@ namespace WindowsPhoneSpeedyBlupi
TinyRect result = default(TinyRect);
double screenWidth = graphics.GraphicsDevice.Viewport.Width;
double screenHeight = graphics.GraphicsDevice.Viewport.Height;
if(screenHeight > 480) {
if(Def.PLATFORM == Def.Platform.Android && screenHeight > 480) {
screenWidth = screenHeight * (640f / 480f);
}
if (screenWidth != 0.0 && screenHeight != 0.0)
@ -248,12 +248,10 @@ namespace WindowsPhoneSpeedyBlupi
{
double screenWidth = graphics.GraphicsDevice.Viewport.Width;
double screenHeight = graphics.GraphicsDevice.Viewport.Height;
if (screenHeight > 480)
if (Def.PLATFORM == Def.Platform.Android && screenHeight > 480)
{
screenWidth = screenHeight * (640f / 480f);
}
Debug.WriteLine("graphics.GraphicsDevice.Viewport.Width=" + graphics.GraphicsDevice.Viewport.Width);
Debug.WriteLine("graphics.GraphicsDevice.Viewport.Height=" + graphics.GraphicsDevice.Viewport.Height);
double val = screenWidth / 640.0;
double val2 = screenHeight / 480.0;
zoom = Math.Min(val, val2);
@ -281,7 +279,7 @@ namespace WindowsPhoneSpeedyBlupi
{
double screenWidth = graphics.GraphicsDevice.Viewport.Width;
double screenHeight = graphics.GraphicsDevice.Viewport.Height;
if (screenHeight > 480)
if (Def.PLATFORM == Def.Platform.Android && screenHeight > 480)
{
screenWidth = screenHeight * (640f / 480f);
}