From 80b6e2ac5c4c35a239dd892806ab271873bb760a Mon Sep 17 00:00:00 2001 From: Colin McMillen Date: Sun, 8 Dec 2019 23:02:22 -0500 Subject: [PATCH] FpsCounter now returns an int (rounded up) rename gameTime -> time in Player GitOrigin-RevId: 0270c026e62acbc934127ec881a770de219e2fa1 --- Jumpy.Shared/FpsCounter.cs | 4 ++-- Jumpy.Shared/JumpyGame.cs | 2 +- Jumpy.Shared/Player.cs | 14 +++++++------- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/Jumpy.Shared/FpsCounter.cs b/Jumpy.Shared/FpsCounter.cs index 0c9c98b..f811b2a 100644 --- a/Jumpy.Shared/FpsCounter.cs +++ b/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() { diff --git a/Jumpy.Shared/JumpyGame.cs b/Jumpy.Shared/JumpyGame.cs index d5333b3..a9be9c4 100644 --- a/Jumpy.Shared/JumpyGame.cs +++ b/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(); diff --git a/Jumpy.Shared/Player.cs b/Jumpy.Shared/Player.cs index f1bb54f..dd653ef 100644 --- a/Jumpy.Shared/Player.cs +++ b/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;