diff --git a/src/Input/Keyboard.cs b/src/Input/Keyboard.cs
index 43ef24b3..b1acdc78 100644
--- a/src/Input/Keyboard.cs
+++ b/src/Input/Keyboard.cs
@@ -7,7 +7,7 @@ namespace MoonWorks.Input
{
public class Keyboard
{
- private ButtonState[] Keys { get; }
+ private Button[] Keys { get; }
private int numKeys;
private static readonly char[] TextInputCharacters = new char[]
@@ -36,10 +36,10 @@ namespace MoonWorks.Input
{
SDL.SDL_GetKeyboardState(out numKeys);
- Keys = new ButtonState[numKeys];
+ Keys = new Button[numKeys];
foreach (KeyCode keycode in Enum.GetValues(typeof(KeyCode)))
{
- Keys[(int) keycode] = new ButtonState();
+ Keys[(int) keycode] = new Button();
}
}
@@ -50,7 +50,7 @@ namespace MoonWorks.Input
foreach (int keycode in Enum.GetValues(typeof(KeyCode)))
{
var keyDown = Marshal.ReadByte(keyboardState, keycode);
- Keys[keycode] = Keys[keycode].Update(Conversions.ByteToBool(keyDown));
+ Keys[keycode].Update(Conversions.ByteToBool(keyDown));
if (Conversions.ByteToBool(keyDown))
{
@@ -86,9 +86,14 @@ namespace MoonWorks.Input
return Keys[(int) keycode].IsReleased;
}
- public ButtonState ButtonState(KeyCode keycode)
+ public Button Button(KeyCode keycode)
{
return Keys[(int) keycode];
}
+
+ public ButtonState ButtonState(KeyCode keycode)
+ {
+ return Keys[(int) keycode].State;
+ }
}
}
diff --git a/src/Math/MathHelper.cs b/src/Math/MathHelper.cs
index da01c7d3..0431d80b 100644
--- a/src/Math/MathHelper.cs
+++ b/src/Math/MathHelper.cs
@@ -331,16 +331,36 @@ namespace MoonWorks.Math
return angle;
}
+ ///
+ /// Rescales a value within a given range to a new range.
+ ///
public static float Normalize(float value, short min, short max, short newMin, short newMax)
{
return ((value - min) * (newMax - newMin)) / (max - min) + newMin;
}
+ ///
+ /// Rescales a value within a given range to a new range.
+ ///
public static float Normalize(float value, float min, float max, float newMin, float newMax)
{
return ((value - min) * (newMax - newMin)) / (max - min) + newMin;
}
+ ///
+ /// Step from start towards end by change.
+ ///
+ /// Start value.
+ /// End value.
+ /// Change value.
+ /// The final delta.
+ public static float Approach(float start, float end, float change)
+ {
+ return (start < end ?
+ System.Math.Min(start + change, end) :
+ System.Math.Max(start - change, end)) - start;
+ }
+
#endregion
#region Internal Static Methods