From f3fe1a328df7ca0db89ddb14b7d45c3f16cea7fa Mon Sep 17 00:00:00 2001 From: =?utf8?q?Tomas=20Wenstr=C3=B6m?= Date: Sat, 30 Jan 2021 16:10:53 +0100 Subject: [PATCH] Character is pushed up when within ground --- src/core/game.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) 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; -- 2.11.0