Przeglądaj źródła

Changed collision getter for a independant one.

Florian DORMONT 10 lat temu
rodzic
commit
ca656a4ef6
2 zmienionych plików z 13 dodań i 6 usunięć
  1. 2 1
      include/Map.h
  2. 11 5
      src/Map.cpp

+ 2 - 1
include/Map.h

@@ -21,7 +21,8 @@ namespace WalrusRPG
         ~Map();
         void render(Camera &camera, unsigned dt) const;
         void update(unsigned dt);
-        bool entity_collide(Entity &entity) const;
+        bool is_tile_solid(unsigned x, unsigned y) const;
+        bool is_pixel_solid(unsigned x, unsigned y) const;
         unsigned get_width() const;
         unsigned get_height() const;
     };

+ 11 - 5
src/Map.cpp

@@ -86,18 +86,24 @@ void MAP::render(WalrusRPG::Camera &camera, unsigned dt) const
     }
 }
 
-bool MAP::entity_collide(Entity &entity) const
+bool MAP::is_tile_solid(unsigned x, unsigned y) const
 {
-    UNUSED(entity);
-    return false;
+    if (x >= width || y >= height)
+        return true;
+    return this->layer0[y * width + x] != 0;
+}
+
+bool MAP::is_pixel_solid(unsigned x, unsigned y) const
+{
+    return is_tile_solid(x / 24, y / 24);
 }
 
 unsigned MAP::get_width() const
 {
-	return this->width;
+    return this->width;
 }
 
 unsigned MAP::get_height() const
 {
-	return this->width;
+    return this->width;
 }