mirror of
https://github.com/Noratrieb/game-wip-dontplay.git
synced 2026-01-16 20:35:02 +01:00
Make collision work horizontally
This commit is contained in:
parent
f07bd9c713
commit
413875909e
2 changed files with 26 additions and 2 deletions
26
src/app.rs
26
src/app.rs
|
|
@ -76,11 +76,12 @@ impl App {
|
||||||
} else {
|
} else {
|
||||||
4.0
|
4.0
|
||||||
};
|
};
|
||||||
|
self.game.player.hspeed = 0.;
|
||||||
if self.input.down(Key::Left) {
|
if self.input.down(Key::Left) {
|
||||||
self.game.player.col_en.move_x(-spd, |_, _| false);
|
self.game.player.hspeed = -spd;
|
||||||
}
|
}
|
||||||
if self.input.down(Key::Right) {
|
if self.input.down(Key::Right) {
|
||||||
self.game.player.col_en.move_x(spd, |_, _| false);
|
self.game.player.hspeed = spd;
|
||||||
}
|
}
|
||||||
if self.input.pressed(Key::Up) {
|
if self.input.pressed(Key::Up) {
|
||||||
self.game.player.vspeed = -14.0;
|
self.game.player.vspeed = -14.0;
|
||||||
|
|
@ -107,6 +108,27 @@ impl App {
|
||||||
});
|
});
|
||||||
col
|
col
|
||||||
});
|
});
|
||||||
|
self.game
|
||||||
|
.player
|
||||||
|
.col_en
|
||||||
|
.move_x(self.game.player.hspeed, |player_en, off| {
|
||||||
|
let mut col = false;
|
||||||
|
for_each_tile_on_screen(self.game.camera_offset, |tp, _sp| {
|
||||||
|
let tid = self.game.world.tile_at_mut(tp).id;
|
||||||
|
if tid == Tile::AIR {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
let tsize = TILE_SIZE as i32;
|
||||||
|
let x = tp.x as i32 * TILE_SIZE as i32;
|
||||||
|
let y = tp.y as i32 * TILE_SIZE as i32;
|
||||||
|
let en = s2dc::Entity::from_rect_corners(x, y, x + tsize, y + tsize);
|
||||||
|
if player_en.would_collide(&en, off) {
|
||||||
|
col = true;
|
||||||
|
self.game.player.hspeed = 0.;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
col
|
||||||
|
});
|
||||||
self.game.player.vspeed += 1.0;
|
self.game.player.vspeed += 1.0;
|
||||||
let (x, y, _w, _h) = self.game.player.col_en.en.xywh();
|
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.x = (x - NATIVE_RESOLUTION.w as i32 / 2) as u32;
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ use crate::{
|
||||||
pub struct Player {
|
pub struct Player {
|
||||||
pub col_en: MobileEntity,
|
pub col_en: MobileEntity,
|
||||||
pub vspeed: f32,
|
pub vspeed: f32,
|
||||||
|
pub hspeed: f32,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Player {
|
impl Player {
|
||||||
|
|
@ -15,6 +16,7 @@ impl Player {
|
||||||
Self {
|
Self {
|
||||||
col_en: MobileEntity::from_pos_and_bb(vec2(pos.x as i32, pos.y as i32), vec2(15, 24)),
|
col_en: MobileEntity::from_pos_and_bb(vec2(pos.x as i32, pos.y as i32), vec2(15, 24)),
|
||||||
vspeed: 0.0,
|
vspeed: 0.0,
|
||||||
|
hspeed: 0.0,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pub fn center_tp(&self) -> TilePos {
|
pub fn center_tp(&self) -> TilePos {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue