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 vibrations = new List(); 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 toDelete = new List(); 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); } } } }