FpsCounter now returns an int (rounded up)
rename gameTime -> time in Player GitOrigin-RevId: 0270c026e62acbc934127ec881a770de219e2fa1
This commit is contained in:
parent
59764cbbbd
commit
80b6e2ac5c
@ -6,8 +6,8 @@ namespace Jumpy {
|
|||||||
private int[] frameTimes = new int[60];
|
private int[] frameTimes = new int[60];
|
||||||
private int idx = 0;
|
private int idx = 0;
|
||||||
|
|
||||||
public double Fps {
|
public int Fps {
|
||||||
get => fps;
|
get => (int) Math.Ceiling(fps);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Update() {
|
public void Update() {
|
||||||
|
@ -94,7 +94,7 @@ namespace Jumpy {
|
|||||||
0, 0, GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height);
|
0, 0, GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height);
|
||||||
spriteBatch.Draw(renderTarget, drawRect, Color.White);
|
spriteBatch.Draw(renderTarget, drawRect, Color.White);
|
||||||
string fpsText = $"{GraphicsDevice.Viewport.Width}x{GraphicsDevice.Viewport.Height}, " +
|
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.DrawString(font, fpsText, new Vector2(10, 10), Color.White);
|
||||||
spriteBatch.End();
|
spriteBatch.End();
|
||||||
|
|
||||||
|
@ -29,7 +29,7 @@ namespace Jumpy {
|
|||||||
this.texture = texture;
|
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) {
|
if (gamePad.Buttons.A == ButtonState.Pressed && airState == AirState.Ground) {
|
||||||
pose = Pose.Jumping;
|
pose = Pose.Jumping;
|
||||||
airState = AirState.Jumping;
|
airState = AirState.Jumping;
|
||||||
@ -47,11 +47,11 @@ namespace Jumpy {
|
|||||||
if (gamePad.DPad.Left == ButtonState.Pressed || leftStick.X < -0.5) {
|
if (gamePad.DPad.Left == ButtonState.Pressed || leftStick.X < -0.5) {
|
||||||
facing = Facing.Left;
|
facing = Facing.Left;
|
||||||
pose = Pose.Walking;
|
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) {
|
} else if (gamePad.DPad.Right == ButtonState.Pressed || leftStick.X > 0.5) {
|
||||||
facing = Facing.Right;
|
facing = Facing.Right;
|
||||||
pose = Pose.Walking;
|
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) {
|
} else if (gamePad.DPad.Down == ButtonState.Pressed || leftStick.Y < -0.5) {
|
||||||
pose = Pose.Crouching;
|
pose = Pose.Crouching;
|
||||||
} else if (gamePad.DPad.Up == ButtonState.Pressed || leftStick.Y > 0.5) {
|
} else if (gamePad.DPad.Up == ButtonState.Pressed || leftStick.Y > 0.5) {
|
||||||
@ -61,16 +61,16 @@ namespace Jumpy {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (jumpTime > 0) {
|
if (jumpTime > 0) {
|
||||||
jumpTime -= gameTime.ElapsedGameTime.TotalSeconds;
|
jumpTime -= time.ElapsedGameTime.TotalSeconds;
|
||||||
}
|
}
|
||||||
if (swordSwingTime > 0) {
|
if (swordSwingTime > 0) {
|
||||||
swordSwingTime -= gameTime.ElapsedGameTime.TotalSeconds;
|
swordSwingTime -= time.ElapsedGameTime.TotalSeconds;
|
||||||
pose = Pose.SwordSwing;
|
pose = Pose.SwordSwing;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (airState == AirState.Jumping) {
|
if (airState == AirState.Jumping) {
|
||||||
position.Y += (int) (ySpeed * gameTime.ElapsedGameTime.TotalSeconds);
|
position.Y += (int) (ySpeed * time.ElapsedGameTime.TotalSeconds);
|
||||||
ySpeed += gravity * (float) gameTime.ElapsedGameTime.TotalSeconds;
|
ySpeed += gravity * (float) time.ElapsedGameTime.TotalSeconds;
|
||||||
if (position.Y > groundLevel) {
|
if (position.Y > groundLevel) {
|
||||||
position.Y = groundLevel;
|
position.Y = groundLevel;
|
||||||
ySpeed = 0;
|
ySpeed = 0;
|
||||||
|
Loading…
Reference in New Issue
Block a user