prevent player from leaving the field
This commit is contained in:
parent
e4018d9cce
commit
210d590e38
@ -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)]
|
||||
|
Loading…
Reference in New Issue
Block a user