Fixed the accelerometer related code, but accelerometer now does not work and has a dummy implementation. This must be fixed and implemented for Android and iOS

This commit is contained in:
Your Name 2024-11-23 23:14:39 +01:00
parent baa67de290
commit cdda21a0cc
6 changed files with 92 additions and 6 deletions

15
Accelerometer.cs Normal file
View File

@ -0,0 +1,15 @@
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<AccelerometerEventArgs> CurrentValueChanged;
}
}

23
AccelerometerDummyImpl.cs Normal file
View File

@ -0,0 +1,23 @@
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<AccelerometerEventArgs> CurrentValueChanged;
public void Start()
{
//throw new AccelerometerFailedException();
}
public void Stop()
{
//throw new AccelerometerFailedException();
}
}
}

23
AccelerometerEventArgs.cs Normal file
View File

@ -0,0 +1,23 @@
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;
}
}
}

13
AccelerometerFactory.cs Normal file
View File

@ -0,0 +1,13 @@
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(); }
}
}

View File

@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace WindowsPhoneSpeedyBlupi
{
public class AccelerometerFailedException : Exception
{
}
}

View File

@ -4,7 +4,6 @@ using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework.Input;
using Microsoft.Devices.Sensors;
using Microsoft.Xna.Framework.Input.Touch;
using WindowsPhoneSpeedyBlupi;
@ -214,8 +213,8 @@ namespace WindowsPhoneSpeedyBlupi
this.sound = sound;
this.gameData = gameData;
pressedGlyphs = new List<Def.ButtonGlygh>();
accelSensor = new Accelerometer();
((SensorBase<AccelerometerReading>)(object)accelSensor).CurrentValueChanged += HandleAccelSensorCurrentValueChanged;
accelSensor = AccelerometerFactory.Create();
accelSensor.CurrentValueChanged += HandleAccelSensorCurrentValueChanged;
accelSlider = new Slider
{
TopLeftCorner = new TinyPoint
@ -856,13 +855,14 @@ namespace WindowsPhoneSpeedyBlupi
accelStarted = false;
}
}
private void HandleAccelSensorCurrentValueChanged(object sender, SensorReadingEventArgs<AccelerometerReading> e)
private void HandleAccelSensorCurrentValueChanged(object sender, AccelerometerEventArgs 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)
AccelerometerReading sensorReading = e.SensorReading;
float y = ((AccelerometerReading)(ref sensorReading)).Acceleration.Y;
float y = e.Y;
float num = (1f - (float)gameData.AccelSensitivity) * 0.06f + 0.04f;
float num2 = (accelLastState ? (num * 0.6f) : num);
if (y > num2)