Skip to content

Commit 7b57b84

Browse files
Fix falling physics
1 parent cd7d147 commit 7b57b84

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

src/components/player.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,9 @@ impl Player {
6666

6767
if self.pos_y < 0. {
6868
self.going_boom = false;
69+
6970
self.pos_y = 0.;
71+
self.velocity = 0.;
7072
}
7173
}
7274

src/game.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,13 +222,15 @@ impl Game {
222222

223223
pub fn inner_update(&mut self, ctx: &mut Context) -> GameResult<Option<crate::Screen>> {
224224
let ferris_pos_x = self.player.pos_x;
225-
let mut ferris_is_falling_down: bool = true;
225+
let ferris_pos_y = self.player.pos_y;
226+
227+
let mut ferris_is_falling_down = true;
226228

227229
for tile in &mut self.ground {
228230
let tile_start = tile.pos_x;
229231
let tile_end = tile.pos_x + 64.;
230232

231-
if ferris_pos_x >= tile_start && ferris_pos_x <= tile_end {
233+
if ferris_pos_x >= tile_start && ferris_pos_x <= tile_end && ferris_pos_y + (-HEIGHT / 2.0) - 64. >= (-HEIGHT / 2.0) - 64. || ferris_pos_y == 0. {
232234
ferris_is_falling_down = false;
233235

234236
break;

0 commit comments

Comments
 (0)