Tweak gravity

This commit is contained in:
crumblingstatue 2023-04-03 18:46:40 +02:00
parent 413875909e
commit 4c9fe26ec9
2 changed files with 11 additions and 2 deletions

View file

@ -86,7 +86,12 @@ impl App {
if self.input.pressed(Key::Up) {
self.game.player.vspeed = -14.0;
}
self.game.player.vspeed = self.game.player.vspeed.clamp(-80., 80.);
let terminal_velocity = 60.0;
self.game.player.vspeed = self
.game
.player
.vspeed
.clamp(-terminal_velocity, terminal_velocity);
self.game
.player
.col_en
@ -129,7 +134,7 @@ impl App {
});
col
});
self.game.player.vspeed += 1.0;
self.game.player.vspeed += self.game.gravity;
let (x, y, _w, _h) = self.game.player.col_en.en.xywh();
self.game.camera_offset.x = (x - NATIVE_RESOLUTION.w as i32 / 2) as u32;
self.game.camera_offset.y = (y - NATIVE_RESOLUTION.h as i32 / 2) as u32;
@ -217,6 +222,8 @@ fn debug_panel_ui(debug: &mut DebugState, game: &mut GameState, ctx: &egui::Cont
LengthDisp(tp.x as i64 - wp_to_tp(WorldPos::CENTER) as i64)
));
ui.label(format!("Vspeed: {}", game.player.vspeed));
ui.label("Gravity");
ui.add(egui::DragValue::new(&mut game.gravity));
}
ui.separator();
egui::ScrollArea::vertical().show(ui, |ui| {

View file

@ -15,6 +15,7 @@ pub struct GameState {
pub camera_offset: WorldPos,
pub world: World,
pub player: Player,
pub gravity: f32,
}
impl GameState {
pub(crate) fn draw_world(&mut self, rw: &mut RenderWindow, res: &Res) {
@ -66,6 +67,7 @@ impl Default for GameState {
camera_offset: spawn_point,
world: Default::default(),
player: Player::new_at(spawn_point),
gravity: 0.7,
}
}
}