mirror of
https://github.com/italicsjenga/gba.git
synced 2024-12-23 19:01:30 +11:00
outline the two checks from the if
This commit is contained in:
parent
d51e2d3c1f
commit
38de4e8f5a
|
@ -141,56 +141,56 @@ extern "C" fn main() -> ! {
|
||||||
if keys.up() {
|
if keys.up() {
|
||||||
let new_p = Position { x: player.x, y: player.y - 1 };
|
let new_p = Position { x: player.x, y: player.y - 1 };
|
||||||
let new_r = Rect { x: new_p.x, y: new_p.y, w: 8, h: 8 };
|
let new_r = Rect { x: new_p.x, y: new_p.y, w: 8, h: 8 };
|
||||||
if new_r
|
let terrain_clear = new_r
|
||||||
.iter_tiles()
|
.iter_tiles()
|
||||||
.all(|(tx, ty)| allows_movement(world[ty as usize][tx as usize]))
|
.all(|(tx, ty)| allows_movement(world[ty as usize][tx as usize]));
|
||||||
&& enemies.iter().all(|enemy| {
|
let enemy_clear = enemies.iter().all(|enemy| {
|
||||||
let enemy_r = Rect { x: enemy.x, y: enemy.y, w: 8, h: 8 };
|
let enemy_r = Rect { x: enemy.x, y: enemy.y, w: 8, h: 8 };
|
||||||
!new_r.intersect(enemy_r)
|
!new_r.intersect(enemy_r)
|
||||||
})
|
});
|
||||||
{
|
if terrain_clear && enemy_clear {
|
||||||
*player = new_p;
|
*player = new_p;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if keys.down() {
|
if keys.down() {
|
||||||
let new_p = Position { x: player.x, y: player.y + 1 };
|
let new_p = Position { x: player.x, y: player.y + 1 };
|
||||||
let new_r = Rect { x: new_p.x, y: new_p.y, w: 8, h: 8 };
|
let new_r = Rect { x: new_p.x, y: new_p.y, w: 8, h: 8 };
|
||||||
if new_r
|
let terrain_clear = new_r
|
||||||
.iter_tiles()
|
.iter_tiles()
|
||||||
.all(|(tx, ty)| allows_movement(world[ty as usize][tx as usize]))
|
.all(|(tx, ty)| allows_movement(world[ty as usize][tx as usize]));
|
||||||
&& enemies.iter().all(|enemy| {
|
let enemy_clear = enemies.iter().all(|enemy| {
|
||||||
let enemy_r = Rect { x: enemy.x, y: enemy.y, w: 8, h: 8 };
|
let enemy_r = Rect { x: enemy.x, y: enemy.y, w: 8, h: 8 };
|
||||||
!new_r.intersect(enemy_r)
|
!new_r.intersect(enemy_r)
|
||||||
})
|
});
|
||||||
{
|
if terrain_clear && enemy_clear {
|
||||||
*player = new_p;
|
*player = new_p;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if keys.left() {
|
if keys.left() {
|
||||||
let new_p = Position { x: player.x - 1, y: player.y };
|
let new_p = Position { x: player.x - 1, y: player.y };
|
||||||
let new_r = Rect { x: new_p.x, y: new_p.y, w: 8, h: 8 };
|
let new_r = Rect { x: new_p.x, y: new_p.y, w: 8, h: 8 };
|
||||||
if new_r
|
let terrain_clear = new_r
|
||||||
.iter_tiles()
|
.iter_tiles()
|
||||||
.all(|(tx, ty)| allows_movement(world[ty as usize][tx as usize]))
|
.all(|(tx, ty)| allows_movement(world[ty as usize][tx as usize]));
|
||||||
&& enemies.iter().all(|enemy| {
|
let enemy_clear = enemies.iter().all(|enemy| {
|
||||||
let enemy_r = Rect { x: enemy.x, y: enemy.y, w: 8, h: 8 };
|
let enemy_r = Rect { x: enemy.x, y: enemy.y, w: 8, h: 8 };
|
||||||
!new_r.intersect(enemy_r)
|
!new_r.intersect(enemy_r)
|
||||||
})
|
});
|
||||||
{
|
if terrain_clear && enemy_clear {
|
||||||
*player = new_p;
|
*player = new_p;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if keys.right() {
|
if keys.right() {
|
||||||
let new_p = Position { x: player.x + 1, y: player.y };
|
let new_p = Position { x: player.x + 1, y: player.y };
|
||||||
let new_r = Rect { x: new_p.x, y: new_p.y, w: 8, h: 8 };
|
let new_r = Rect { x: new_p.x, y: new_p.y, w: 8, h: 8 };
|
||||||
if new_r
|
let terrain_clear = new_r
|
||||||
.iter_tiles()
|
.iter_tiles()
|
||||||
.all(|(tx, ty)| allows_movement(world[ty as usize][tx as usize]))
|
.all(|(tx, ty)| allows_movement(world[ty as usize][tx as usize]));
|
||||||
&& enemies.iter().all(|enemy| {
|
let enemy_clear = enemies.iter().all(|enemy| {
|
||||||
let enemy_r = Rect { x: enemy.x, y: enemy.y, w: 8, h: 8 };
|
let enemy_r = Rect { x: enemy.x, y: enemy.y, w: 8, h: 8 };
|
||||||
!new_r.intersect(enemy_r)
|
!new_r.intersect(enemy_r)
|
||||||
})
|
});
|
||||||
{
|
if terrain_clear && enemy_clear {
|
||||||
*player = new_p;
|
*player = new_p;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue