Display player speed in km/h

This commit is contained in:
crumblingstatue 2023-04-04 20:18:27 +02:00
parent 9b4d0c8cf7
commit 05c516e210
3 changed files with 26 additions and 4 deletions

View file

@ -13,7 +13,7 @@ use crate::{
game::{for_each_tile_on_screen, Biome, GameState},
graphics::{self, NATIVE_RESOLUTION},
input::Input,
math::{wp_to_tp, WorldPos, TILE_SIZE},
math::{px_per_frame_to_km_h, wp_to_tp, WorldPos, TILE_SIZE},
res::Res,
world::Tile,
};
@ -264,8 +264,16 @@ fn debug_panel_ui(
"Player offset from center: {}",
LengthDisp(tp.x as i64 - wp_to_tp(WorldPos::CENTER) as i64)
));
ui.label(format!("Hspeed: {}", game.player.hspeed));
ui.label(format!("Vspeed: {}", game.player.vspeed));
ui.label(format!(
"Hspeed: {} ({} km/h)",
game.player.hspeed,
px_per_frame_to_km_h(game.player.hspeed)
));
ui.label(format!(
"Vspeed: {} ({} km/h)",
game.player.vspeed,
px_per_frame_to_km_h(game.player.vspeed)
));
ui.label("Gravity");
ui.add(egui::DragValue::new(&mut game.gravity));
}

View file

@ -5,6 +5,8 @@ use sfml::{
};
use sfml_xt::graphics::RenderWindowExt;
use crate::math::FPS_TARGET;
pub struct ScreenRes {
pub w: i16,
pub h: i16,
@ -44,7 +46,7 @@ pub fn make_window() -> RenderWindow {
Style::CLOSE,
&ContextSettings::default(),
);
rw.set_framerate_limit(60);
rw.set_framerate_limit(FPS_TARGET.into());
rw.center();
rw
}

View file

@ -9,6 +9,18 @@ pub struct WorldPos {
}
pub const TILE_SIZE: u8 = 32;
/// Pixels per meter. One meter = one tile, so this is the same as `TILE_SIZE`.
pub const PX_PER_M: u8 = TILE_SIZE;
pub const FPS_TARGET: u8 = 60;
pub fn px_per_frame_to_m_per_s(px_per_frame: f32) -> f32 {
let m_per_frame = px_per_frame / PX_PER_M as f32;
m_per_frame * FPS_TARGET as f32
}
pub fn px_per_frame_to_km_h(px_per_frame: f32) -> f32 {
px_per_frame_to_m_per_s(px_per_frame) * 3.6
}
impl WorldPos {
pub fn tile_pos(&self) -> TilePos {