Fixed some obvious bugs.
authorsaiam
Sun, 30 Nov 2008 13:17:37 +0000
changeset 142 00672d0682ac
parent 141 73109c5652d3
child 143 45565385d972
Fixed some obvious bugs.
src/proto2/Terrain.cc
src/proto2/Terrain.hh
--- 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);
--- 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.