From: Tomas Wenström Date: Sat, 30 Jan 2021 15:10:53 +0000 (+0100) Subject: Character is pushed up when within ground X-Git-Url: http://git.dolda2000.com/gitweb/?a=commitdiff_plain;h=f3fe1a328df7ca0db89ddb14b7d45c3f16cea7fa;p=kaka%2Frust-sdl-test.git Character is pushed up when within ground --- diff --git a/src/core/game.rs b/src/core/game.rs index e8893de..36e6ed5 100644 --- a/src/core/game.rs +++ b/src/core/game.rs @@ -165,11 +165,12 @@ impl Object for Character { let x = (self.pos.x / lvl.grid.cell_size as f64).min(lvl.grid.width as f64 - 1.0).max(0.0) as usize; let y = (self.pos.y / lvl.grid.cell_size as f64).min(lvl.grid.height as f64 - 1.0).max(0.0) as usize; + self.vel += lvl.gravity; if lvl.grid.cells[x][y] { - self.vel += lvl.gravity; if self.vel.y > 0.0 && !(ctrl.mov.down() && ctrl.jump.is_pressed) { self.vel.y = 0.0; self.vel.x *= 0.9; + self.pos.y -= 1.0; } if !ctrl.mov.down() { @@ -177,8 +178,6 @@ impl Object for Character { self.vel.y = -5.0; } } - } else { - self.vel += lvl.gravity; } self.pos += self.vel;