mirror of
https://github.com/MaddyThorson/StrawberryBF.git
synced 2024-11-25 16:18:56 +08:00
Time static class
This commit is contained in:
parent
0519afb158
commit
35c29f3f74
|
@ -12,9 +12,6 @@ namespace Strawberry
|
|||
public class Game : SDLApp
|
||||
{
|
||||
public List<VirtualInput> VirtualInputs;
|
||||
public float DeltaTime { get; private set; }
|
||||
public float Time { get; private set; }
|
||||
public float PreviousTime { get; private set; }
|
||||
|
||||
private Scene scene;
|
||||
private Scene switchToScene;
|
||||
|
@ -26,7 +23,6 @@ namespace Strawberry
|
|||
{
|
||||
Game = this;
|
||||
VirtualInputs = new List<VirtualInput>();
|
||||
DeltaTime = 1 / 60f;
|
||||
|
||||
mTitle.Set(windowTitle);
|
||||
mWidth = width;
|
||||
|
@ -72,8 +68,8 @@ namespace Strawberry
|
|||
if (scene != null)
|
||||
scene.Update();
|
||||
|
||||
PreviousTime = Time;
|
||||
Time += DeltaTime;
|
||||
Time.PreviousElapsed = Time.Elapsed;
|
||||
Time.Elapsed += Time.Delta;
|
||||
}
|
||||
|
||||
public override void Draw()
|
||||
|
|
|
@ -56,16 +56,16 @@ namespace Strawberry
|
|||
|
||||
//Press
|
||||
if (last != IntValue && IntValue != 0)
|
||||
lastPress = Game.Time;
|
||||
Pressed = IntValue != 0 && lastPress > lastPressClear && Game.Time - lastPress <= pressBuffer;
|
||||
lastPress = Time.Elapsed;
|
||||
Pressed = IntValue != 0 && lastPress > lastPressClear && Time.Elapsed - lastPress <= pressBuffer;
|
||||
|
||||
//Repeat
|
||||
if (IntValue != 0 && repeatStart > 0 && Game.Time - lastPress >= repeatStart)
|
||||
if (IntValue != 0 && repeatStart > 0 && Time.Elapsed - lastPress >= repeatStart)
|
||||
{
|
||||
Repeating = true;
|
||||
|
||||
int a = (int)((Game.PreviousTime - lastPress) / repeatInterval);
|
||||
int b = (int)((Game.Time - lastPress) / repeatInterval);
|
||||
int a = (int)((Time.PreviousElapsed - lastPress) / repeatInterval);
|
||||
int b = (int)((Time.Elapsed - lastPress) / repeatInterval);
|
||||
if (a != b)
|
||||
Pressed = true;
|
||||
}
|
||||
|
@ -74,18 +74,18 @@ namespace Strawberry
|
|||
|
||||
//Release
|
||||
if (last != 0 && IntValue == 0)
|
||||
lastRelease = Game.Time;
|
||||
Released = IntValue == 0 && lastRelease > lastReleaseClear && Game.Time - lastRelease <= releaseBuffer;
|
||||
lastRelease = Time.Elapsed;
|
||||
Released = IntValue == 0 && lastRelease > lastReleaseClear && Time.Elapsed - lastRelease <= releaseBuffer;
|
||||
}
|
||||
|
||||
public void ClearPressBuffer()
|
||||
{
|
||||
lastPressClear = Game.Time;
|
||||
lastPressClear = Time.Elapsed;
|
||||
}
|
||||
|
||||
public void ClearReleaseBuffer()
|
||||
{
|
||||
lastReleaseClear = Game.Time;
|
||||
lastReleaseClear = Time.Elapsed;
|
||||
}
|
||||
|
||||
// Setup Calls
|
||||
|
|
|
@ -50,16 +50,16 @@ namespace Strawberry
|
|||
|
||||
//Press
|
||||
if (!last && Check)
|
||||
lastPress = Game.Time;
|
||||
Pressed = Check && lastPress > lastPressClear && Game.Time - lastPress <= pressBuffer;
|
||||
lastPress = Time.Elapsed;
|
||||
Pressed = Check && lastPress > lastPressClear && Time.Elapsed - lastPress <= pressBuffer;
|
||||
|
||||
//Repeat
|
||||
if (Check && repeatStart > 0 && Game.Time - lastPress >= repeatStart)
|
||||
if (Check && repeatStart > 0 && Time.Elapsed - lastPress >= repeatStart)
|
||||
{
|
||||
Repeating = true;
|
||||
|
||||
int a = (int)((Game.PreviousTime - lastPress) / repeatInterval);
|
||||
int b = (int)((Game.Time - lastPress) / repeatInterval);
|
||||
int a = (int)((Time.PreviousElapsed - lastPress) / repeatInterval);
|
||||
int b = (int)((Time.Elapsed - lastPress) / repeatInterval);
|
||||
if (a != b)
|
||||
Pressed = true;
|
||||
}
|
||||
|
@ -68,18 +68,18 @@ namespace Strawberry
|
|||
|
||||
//Release
|
||||
if (last && !Check)
|
||||
lastRelease = Game.Time;
|
||||
Released = !Check && lastRelease > lastReleaseClear && Game.Time - lastRelease <= releaseBuffer;
|
||||
lastRelease = Time.Elapsed;
|
||||
Released = !Check && lastRelease > lastReleaseClear && Time.Elapsed - lastRelease <= releaseBuffer;
|
||||
}
|
||||
|
||||
public void ClearPressBuffer()
|
||||
{
|
||||
lastPressClear = Game.Time;
|
||||
lastPressClear = Time.Elapsed;
|
||||
}
|
||||
|
||||
public void ClearReleaseBuffer()
|
||||
{
|
||||
lastReleaseClear = Game.Time;
|
||||
lastReleaseClear = Time.Elapsed;
|
||||
}
|
||||
|
||||
// Setup Calls
|
||||
|
|
9
src/Time.bf
Normal file
9
src/Time.bf
Normal file
|
@ -0,0 +1,9 @@
|
|||
namespace Strawberry
|
||||
{
|
||||
static public class Time
|
||||
{
|
||||
static public float Elapsed;
|
||||
static public float PreviousElapsed;
|
||||
static public float Delta = 1 / 60f;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user