The player appears to go off-screen anywhere on the left edge (column 0) or top edge (row 0) of the dungeon. I’ve tried debugging, but haven’t been able to figure out a fix. I even happens when running the game from the sample code.
Does it do that when you run the downloadable source code version? I’ve not been able to exit the map to the north/top or west/left on the build I have here.
I’d double check that your Map’s in_bounds
implementations are correct (they changed a little after the first beta). Map
should implement:
impl Map {
pub fn in_bounds(&self, point : Point) -> bool {
point.x >= 0 && point.x < SCREEN_WIDTH && point.y >= 0 && point.y < SCREEN_HEIGHT
}
fn valid_exit(&self, loc: Point, delta: Point) -> Option<usize> {
let destination = loc + delta;
if self.in_bounds(destination) {
if self.can_enter_tile(destination) {
let idx = self.point2d_to_index(destination);
Some(idx)
} else {
None
}
} else {
None
}
}
It should also implement the Algorithm2D
trait:
impl Algorithm2D for Map {
fn dimensions(&self) -> Point {
Point::new(SCREEN_WIDTH, SCREEN_HEIGHT)
}
fn in_bounds(&self, point: Point) -> bool {
self.in_bounds(point)
}
}
The movement system checks can_enter_tile
, which should check both in_bounds
and tile contents from the Map
.
Let me know if you have any luck - I hope that helps!
It looks like I had missed the Algorithm2D implementation of in_bounds. It works after adding that. The downloadable source I had from 12/31 didn’t have that function, but the latest does. I guess that’s part of the risk of following along with beta books.
Thank you for responding. I’m enjoying the book.