Permalink
Browse files

make sure the camera will never look at the edge of the map (ie, the

0,0-max width/height border). This fixes several errors in getting cells
which are outside the boundaries (as we do not show them anymore). It
also will have a positive effect later on when smoothing out terrain and
such. For now the border is always 'rock' (tile 64 in tileset, for now
of course). Fixes #12
  • Loading branch information...
stefanhendriks committed Sep 7, 2013
1 parent 3e08a96 commit 3c6d2831ed2620aac1dc3add67c332bf6eb4e71a
Showing with 13 additions and 6 deletions.
  1. +9 −3 map.cpp
  2. +4 −3 map.h
View
12 map.cpp
@@ -16,9 +16,15 @@ Map::Map() {
int i = (y * MAP_MAX_WIDTH) + x;
cells[i].x = x;
cells[i].y = y;
cells[i].tile = (flipCoin() ? 0 : 64);
if (x == 0 || y == 0 || x >= max_width || y >= max_height) {
cells[i].tile = 64;
} else {
cells[i].tile = (flipCoin() ? 0 : 64);
}
cells[i].occupied = false;
cells[i].shrouded = true;
}
}
@@ -62,9 +68,9 @@ void MapCamera::updateState() {
}
void MapCamera::makeSureCoordinatesDoNotExceedMapLimits() {
if (y < 0) y = 0;
if (y < min_y()) y = min_y();
if (y > max_y()) y = max_y();
if (x < 0) x = 0;
if (x < min_x()) x = min_x();
if (x > max_x()) x = max_x();
}
View
7 map.h
@@ -153,7 +153,6 @@ class MapCamera {
float move_x_velocity;
float move_y_velocity;
int getWidth() { return max_cells_width_on_screen; }
int getHeight() { return max_cells_height_on_screen; }
@@ -165,8 +164,10 @@ class MapCamera {
void moveRight() { move_x_velocity += CAMERA_VELOCITY_ACCELERATION; }
void stopMoving() { move_x_velocity = move_y_velocity = 0.0F; }
int max_y() { return (map_y_boundary - max_cells_height_on_screen) * 32; }
int max_x() { return (map_x_boundary - max_cells_width_on_screen) * 32; }
int min_x() { return TILE_SIZE; }
int min_y() { return TILE_SIZE; }
int max_y() { return ((map_y_boundary - max_cells_height_on_screen) * TILE_SIZE) - 1; }
int max_x() { return ((map_x_boundary - max_cells_width_on_screen) * TILE_SIZE) - 1; }
int determineShroudEdge(Map* map, Cell* c);
};

0 comments on commit 3c6d283

Please sign in to comment.