# HG changeset patch # User saiam # Date 1228051057 0 # Node ID 00672d0682ac0931321d7cdef322606f6d199e1c # Parent 73109c5652d388bf27ee602d918f592fc5683413 Fixed some obvious bugs. diff -r 73109c5652d3 -r 00672d0682ac src/proto2/Terrain.cc --- a/src/proto2/Terrain.cc Sun Nov 30 12:58:10 2008 +0000 +++ b/src/proto2/Terrain.cc Sun Nov 30 13:17:37 2008 +0000 @@ -15,7 +15,7 @@ bool Terrain::collides(const Vector &point) const { Vector coor = getPixelLocation(point); - return !(terrain[coor.x][coor.y] == EMPTY); + return (getType(coor.x, coor.y) != EMPTY); } bool Terrain::collides(const Vector &begin, const Vector &end) const { @@ -46,11 +46,11 @@ // Go trough the line for (uint16_t x = b.x; x <= e.x; x++) { if (steep) { // X and Y coordinates must be switched if steep - if (terrain[y][x] != EMPTY) { // Collision! + if (getType(y,x) != EMPTY) { // Collision! return true; } } else { - if (terrain[x][y] != EMPTY) { // Collision! + if (getType(x,y) != EMPTY) { // Collision! return true; } } @@ -75,6 +75,13 @@ (int)round(point.y/scal.y)); } +TerrainType Terrain::getType(uint16_t x, uint16_t y) { + if ((x < 0) || (y < 0) ||(x >= MAP_WIDTH) || (y >= MAP_HEIGHT)) { + return ROCK; + } + return terrain[x][y]; +} + void Terrain::generatePixelBuffer() { // These could be somewhere else const CL_Color colorEmpty(86, 41, 0); diff -r 73109c5652d3 -r 00672d0682ac src/proto2/Terrain.hh --- a/src/proto2/Terrain.hh Sun Nov 30 12:58:10 2008 +0000 +++ b/src/proto2/Terrain.hh Sun Nov 30 13:17:37 2008 +0000 @@ -40,6 +40,16 @@ */ Vector getPixelLocation(Vector point); + + /** + * Return the type of terrain at given position. + * + * @param x X coordinate + * @param y Y coordinate + * @return Terrain type + */ + TerrainType getType(uint16_t x, uint16_t y); + public: /** * Constructor.