Basic gamepad with force feedback impl

This commit is contained in:
2021-04-24 02:47:17 +02:00
parent db9c3cceea
commit 9f66f9d8fb
109 changed files with 205 additions and 196 deletions
+65
View File
@@ -0,0 +1,65 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;
namespace EvilSatellites
{
public class VibrationManager
{
private PlayerIndex playerIndex;
List<Vibration> vibrations = new List<Vibration>();
public VibrationManager(PlayerIndex playerIndex)
{
this.playerIndex = playerIndex;
}
public void AddVibration(float leftMotor, float rightMotor, float durationMS)
{
vibrations.Add(new Vibration(leftMotor, rightMotor, durationMS));
}
public void Update(float msElapsed)
{
List<Vibration> toDelete = new List<Vibration>();
foreach (Vibration vibration in vibrations)
{
vibration.MSLeft -= msElapsed;
if (vibration.MSLeft < 0.0f)
{
toDelete.Add(vibration);
}
}
foreach (Vibration vibration in toDelete)
{
vibrations.Remove(vibration);
}
float leftMotor;
float rightMotor;
GetVibration(out leftMotor, out rightMotor);
GamePad.SetVibration(playerIndex, leftMotor, rightMotor);
}
public void GetVibration(out float leftMotor, out float rightMotor)
{
leftMotor = 0.0f;
rightMotor = 0.0f;
foreach (Vibration vibration in vibrations)
{
leftMotor = Math.Max(leftMotor, vibration.LeftMotor);
rightMotor = Math.Max(rightMotor, vibration.RightMotor);
}
}
}
}