diff --git a/src/level.rs b/src/level.rs index 2b9251a..67b2497 100644 --- a/src/level.rs +++ b/src/level.rs @@ -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)]