Browse Source

FpsCounter now returns an int (rounded up)

rename gameTime -> time in Player

GitOrigin-RevId: 0270c026e6
master
Colin McMillen 4 years ago
parent
commit
80b6e2ac5c
  1. 4
      Jumpy.Shared/FpsCounter.cs
  2. 2
      Jumpy.Shared/JumpyGame.cs
  3. 14
      Jumpy.Shared/Player.cs

4
Jumpy.Shared/FpsCounter.cs

@ -6,8 +6,8 @@ namespace Jumpy {
private int[] frameTimes = new int[60];
private int idx = 0;
public double Fps {
get => fps;
public int Fps {
get => (int) Math.Ceiling(fps);
}
public void Update() {

2
Jumpy.Shared/JumpyGame.cs

@ -94,7 +94,7 @@ namespace Jumpy {
0, 0, GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height);
spriteBatch.Draw(renderTarget, drawRect, Color.White);
string fpsText = $"{GraphicsDevice.Viewport.Width}x{GraphicsDevice.Viewport.Height}, " +
$"{fpsCounter.Fps:F1} FPS";
$"{fpsCounter.Fps} FPS";
spriteBatch.DrawString(font, fpsText, new Vector2(10, 10), Color.White);
spriteBatch.End();

14
Jumpy.Shared/Player.cs

@ -29,7 +29,7 @@ namespace Jumpy {
this.texture = texture;
}
public void Update(GameTime gameTime, GamePadState gamePad) {
public void Update(GameTime time, GamePadState gamePad) {
if (gamePad.Buttons.A == ButtonState.Pressed && airState == AirState.Ground) {
pose = Pose.Jumping;
airState = AirState.Jumping;
@ -47,11 +47,11 @@ namespace Jumpy {
if (gamePad.DPad.Left == ButtonState.Pressed || leftStick.X < -0.5) {
facing = Facing.Left;
pose = Pose.Walking;
position.X -= (int) (moveSpeed * (float)gameTime.ElapsedGameTime.TotalSeconds);
position.X -= (int) (moveSpeed * (float) time.ElapsedGameTime.TotalSeconds);
} else if (gamePad.DPad.Right == ButtonState.Pressed || leftStick.X > 0.5) {
facing = Facing.Right;
pose = Pose.Walking;
position.X += (int) (moveSpeed * (float)gameTime.ElapsedGameTime.TotalSeconds);
position.X += (int) (moveSpeed * (float) time.ElapsedGameTime.TotalSeconds);
} else if (gamePad.DPad.Down == ButtonState.Pressed || leftStick.Y < -0.5) {
pose = Pose.Crouching;
} else if (gamePad.DPad.Up == ButtonState.Pressed || leftStick.Y > 0.5) {
@ -61,16 +61,16 @@ namespace Jumpy {
}
if (jumpTime > 0) {
jumpTime -= gameTime.ElapsedGameTime.TotalSeconds;
jumpTime -= time.ElapsedGameTime.TotalSeconds;
}
if (swordSwingTime > 0) {
swordSwingTime -= gameTime.ElapsedGameTime.TotalSeconds;
swordSwingTime -= time.ElapsedGameTime.TotalSeconds;
pose = Pose.SwordSwing;
}
if (airState == AirState.Jumping) {
position.Y += (int) (ySpeed * gameTime.ElapsedGameTime.TotalSeconds);
ySpeed += gravity * (float) gameTime.ElapsedGameTime.TotalSeconds;
position.Y += (int) (ySpeed * time.ElapsedGameTime.TotalSeconds);
ySpeed += gravity * (float) time.ElapsedGameTime.TotalSeconds;
if (position.Y > groundLevel) {
position.Y = groundLevel;
ySpeed = 0;

Loading…
Cancel
Save