diff --git a/src/app.rs b/src/app.rs index a7d8795..701464e 100644 --- a/src/app.rs +++ b/src/app.rs @@ -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)); } diff --git a/src/graphics.rs b/src/graphics.rs index 897a056..e7160df 100644 --- a/src/graphics.rs +++ b/src/graphics.rs @@ -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 } diff --git a/src/math.rs b/src/math.rs index 8a131e1..c7b958c 100644 --- a/src/math.rs +++ b/src/math.rs @@ -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 {