no longer walking through walls

This commit is contained in:
Peter Hart 2020-03-15 16:55:45 -04:00
parent 6705af3611
commit ea5041d85a

View File

@ -95,10 +95,15 @@ struct Player {}
fn try_move_player(delta_x: i32, delta_y: i32, ecs: &mut World) { fn try_move_player(delta_x: i32, delta_y: i32, ecs: &mut World) {
let mut positions = ecs.write_storage::<Position>(); let mut positions = ecs.write_storage::<Position>();
let mut players = ecs.write_storage::<Player>(); let mut players = ecs.write_storage::<Player>();
let map = ecs.fetch::<Vec<TileType>>();
for (_player, pos) in (&mut players, &mut positions).join() { for (_player, pos) in (&mut players, &mut positions).join() {
pos.x = min(79 , max(0, pos.x + delta_x)); let x = min(79 , max(0, pos.x + delta_x));
pos.y = min(49, max(0, pos.y + delta_y)); let y = min(49, max(0, pos.y + delta_y));
if map[xy_idx(x,y)] != TileType::Wall {
pos.x = x;
pos.y = y;
}
} }
} }