Jypeli 10
The simple game programming library
Vibration.cs
Siirry tämän tiedoston dokumentaatioon.
1using System;
2using System.Collections.Generic;
3using Microsoft.Xna.Framework;
4
6{
7 internal class Vibration : Destroyable, Updatable
8 {
9 public double LifetimeLeft { get; private set; }
10 public double leftMotor { get; private set; }
11 public double rightMotor { get; private set; }
12 public double leftAccel { get; set; }
13 public double rightAccel { get; set; }
14
15 public bool IsUpdated { get { return true; } }
16
17 public Vibration( double lmotor, double rmotor, double laccel, double raccel, double life )
18 {
19 leftMotor = lmotor;
20 rightMotor = rmotor;
21 leftAccel = laccel;
22 rightAccel = raccel;
23 LifetimeLeft = life;
24 }
25
26 public void Update( Time time )
27 {
28 if ( LifetimeLeft <= 0 )
29 {
30 Destroy();
31 return;
32 }
33
34 // Acceleration
35 leftMotor += time.SinceLastUpdate.TotalSeconds * leftAccel;
36 rightMotor += time.SinceLastUpdate.TotalSeconds * rightAccel;
37
38 // Lifetime progression
39 LifetimeLeft -= time.SinceLastUpdate.TotalSeconds;
40 }
41
42 public static void Execute( PlayerIndex p, IEnumerable<Vibration> vibrations )
43 {
44 // Total vibrations
45 double lmotort = 0;
46 double rmotort = 0;
47
48 foreach ( var v in vibrations )
49 {
50 lmotort += v.leftMotor;
51 rmotort += v.rightMotor;
52 }
53
54 // Clamp the results between 0 and 1
55 lmotort = AdvanceMath.MathHelper.Clamp( (float)lmotort, 0, 1 );
56 rmotort = AdvanceMath.MathHelper.Clamp( (float)rmotort, 0, 1 );
57
58 // Set the vibration
59 //XnaGamePad.SetVibration( p, (float)lmotort, (float)rmotort );
60 // MonoGame: no support yet
61 }
62
63 #region Destroyable Members
64
65 public bool IsDestroyed { get; private set; }
66
67 public event Action Destroyed;
68
69 public void Destroy()
70 {
71 if ( IsDestroyed ) return;
72 IsDestroyed = true;
73 if ( Destroyed != null )
74 Destroyed();
75 }
76
77 #endregion
78 }
79}
static Scalar Clamp(Scalar value, Scalar min, Scalar max)
Definition: MathHelper.cs:111
void Destroy()
Tuhoaa kappaleen
Definition: Vibration.cs:69
Vibration(double lmotor, double rmotor, double laccel, double raccel, double life)
Definition: Vibration.cs:17
static void Execute(PlayerIndex p, IEnumerable< Vibration > vibrations)
Definition: Vibration.cs:42
void Update(Time time)
Päivitysfunktio
Definition: Vibration.cs:26
Rajapinta olioille, jotka ovat tuhottavissa.
Definition: Destroyable.cs:9
Rajapinta päivittyville olioille.
Definition: Updatable.cs:7
Sisältää tiedon ajasta, joka on kulunut pelin alusta ja viime päivityksestä.
Definition: Time.cs:14
TimeSpan SinceLastUpdate
Aika joka on kulunut viime päivityksestä.
Definition: Time.cs:27