mirror of
https://github.com/Noratrieb/game-wip-dontplay.git
synced 2026-01-15 04:05:02 +01:00
Fix infinite jumps
This commit is contained in:
parent
6df84ed6e3
commit
be1bc9ca9e
2 changed files with 10 additions and 1 deletions
|
|
@ -83,8 +83,9 @@ impl App {
|
|||
if self.input.down(Key::D) {
|
||||
self.game.player.hspeed = spd;
|
||||
}
|
||||
if self.input.pressed(Key::W) {
|
||||
if self.input.down(Key::W) && self.game.player.can_jump() {
|
||||
self.game.player.vspeed = -10.0;
|
||||
self.game.player.jumps_left = 0;
|
||||
}
|
||||
let terminal_velocity = 60.0;
|
||||
self.game.player.vspeed = self
|
||||
|
|
@ -108,6 +109,9 @@ impl App {
|
|||
let en = s2dc::Entity::from_rect_corners(x, y, x + tsize, y + tsize);
|
||||
if player_en.would_collide(&en, off) {
|
||||
col = true;
|
||||
if self.game.player.vspeed > 0. {
|
||||
self.game.player.jumps_left = 1;
|
||||
}
|
||||
self.game.player.vspeed = 0.;
|
||||
}
|
||||
});
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ pub struct Player {
|
|||
pub col_en: MobileEntity,
|
||||
pub vspeed: f32,
|
||||
pub hspeed: f32,
|
||||
pub jumps_left: u8,
|
||||
}
|
||||
|
||||
impl Player {
|
||||
|
|
@ -17,6 +18,7 @@ impl Player {
|
|||
col_en: MobileEntity::from_pos_and_bb(vec2(pos.x as i32, pos.y as i32), vec2(15, 24)),
|
||||
vspeed: 0.0,
|
||||
hspeed: 0.0,
|
||||
jumps_left: 0,
|
||||
}
|
||||
}
|
||||
pub fn center_tp(&self) -> TilePos {
|
||||
|
|
@ -25,4 +27,7 @@ impl Player {
|
|||
y: (self.col_en.en.pos.y / TILE_SIZE as i32) as TilePosScalar,
|
||||
}
|
||||
}
|
||||
pub fn can_jump(&self) -> bool {
|
||||
self.jumps_left > 0
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue