prevent player from leaving the field

This commit is contained in:
Joachim Lusiardi 2024-01-03 09:12:00 +01:00
parent e4018d9cce
commit 210d590e38
1 changed files with 7 additions and 0 deletions

View File

@ -164,6 +164,7 @@ impl Level {
let new_x: usize = (agent_pos.get_x() as i16 + dx) as usize;
let new_y: usize = (agent_pos.get_y() as i16 + dy) as usize;
// verify we cannot leave the playing field
if new_x >= LEVEL_WIDTH || new_y >= LEVEL_HEIGHT {
return false;
}
@ -178,6 +179,12 @@ impl Level {
let agent_pos = agent.get_immutable_position();
let new_x: usize = (agent_pos.get_x() as i16 + dx) as usize;
let new_y: usize = (agent_pos.get_y() as i16 + dy) as usize;
// verify we cannot leave the playing field
if new_x >= LEVEL_WIDTH || new_y >= LEVEL_HEIGHT {
return false;
}
self.structure[new_x][new_y] != StructureElement::Wall
}
#[cfg(test)]