FpsCounter now returns an int (rounded up)

rename gameTime -> time in Player

GitOrigin-RevId: 0270c026e62acbc934127ec881a770de219e2fa1
This commit is contained in:
Colin McMillen 2019-12-08 23:02:22 -05:00
parent 59764cbbbd
commit 80b6e2ac5c
3 changed files with 10 additions and 10 deletions

View File

@ -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() {

View File

@ -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();

View File

@ -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;