Browse Source

Add Clock class & use it from Player and SneakGame

GitOrigin-RevId: fe20c836ca
master
Colin McMillen 4 years ago
parent
commit
f5ca85264f
  1. 15
      Shared/Clock.cs
  2. 4
      Shared/Player.cs
  3. 1
      Shared/Shared.projitems
  4. 1
      Shared/SneakGame.cs

15
Shared/Clock.cs

@ -0,0 +1,15 @@
using System;
namespace SemiColinGames {
class Clock {
private static TimeSpan modelTime = new TimeSpan();
public static void AddModelTime(double seconds) {
modelTime += TimeSpan.FromSeconds(seconds);
}
public static TimeSpan ModelTime {
get { return modelTime; }
}
}
}

4
Shared/Player.cs

@ -22,7 +22,6 @@ namespace SemiColinGames {
private double swordSwingTime = 0;
private double jumpTime = 0;
private float ySpeed = 0;
private float totalModelTime = 0;
public Player(Texture2D texture) {
this.texture = texture;
@ -35,7 +34,6 @@ namespace SemiColinGames {
}
public void Update(float modelTime, History<Input> input, List<Rectangle> collisionTargets) {
totalModelTime += modelTime;
Point oldPosition = position;
Vector2 movement = HandleInput(modelTime, input);
position = new Point((int) (oldPosition.X + movement.X), (int) (oldPosition.Y + movement.Y));
@ -130,7 +128,7 @@ namespace SemiColinGames {
}
private int SpriteIndex(Pose pose) {
int frameNum = ((int) (totalModelTime * 1000) / 125) % 4;
int frameNum = (int) Clock.ModelTime.TotalMilliseconds / 125 % 4;
if (frameNum == 3) {
frameNum = 1;
}

1
Shared/Shared.projitems

@ -10,6 +10,7 @@
</PropertyGroup>
<ItemGroup>
<Compile Include="$(MSBuildThisFileDirectory)Camera.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Clock.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Input.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Debug.cs" />
<Compile Include="$(MSBuildThisFileDirectory)FpsCounter.cs" />

1
Shared/SneakGame.cs

@ -90,6 +90,7 @@ namespace SemiColinGames {
if (!paused) {
float modelTime = (float) gameTime.ElapsedGameTime.TotalSeconds;
Clock.AddModelTime(modelTime);
List<Rectangle> collisionTargets = world.CollisionTargets();
player.Update(modelTime, input, collisionTargets);
camera.Update(player.Position);

Loading…
Cancel
Save