]> code.bitgloo.com Git - clyne/gamedev2.git/commitdiff
Added image based hitbox detection
authorAndy Belle-Isle <drumsetmonkey@gmail.com>
Mon, 7 Oct 2019 19:06:24 +0000 (15:06 -0400)
committerAndy Belle-Isle <drumsetmonkey@gmail.com>
Mon, 7 Oct 2019 19:06:24 +0000 (15:06 -0400)
Assets/world/world1/layers/0/hitbox.png
Assets/world/world1/layers/0/texture.png
Scripts/init.lua
src/world.cpp
src/world.hpp

index 0a9a37e8d2ccd31f3428e47d63d8a1cf45e35e46..881b13ea81b9e4239995238f3a6c402bb327ba98 100644 (file)
Binary files a/Assets/world/world1/layers/0/hitbox.png and b/Assets/world/world1/layers/0/hitbox.png differ
index 149273f21cadd69083c0a5dd759a708da706f465..429107e7d50f7d8afd65776fd855d020b7d96e75 100644 (file)
Binary files a/Assets/world/world1/layers/0/texture.png and b/Assets/world/world1/layers/0/texture.png differ
index ec9e35071460ba81a74c5432e03c9289711387f8..1693d0c41cb00f09b56a4c05bdaabf11b1be0d19 100644 (file)
@@ -86,7 +86,7 @@ ball = {
 dofile("Scripts/world.lua")
 
 playerSpawn = game.spawn(player);
-game.spawn(ball);
+--game.spawn(ball);
 
 -------------------
 --  SERIALIZING  --
index 8c15ccca6633d88773fce6af740c7f37f3313ad8..a3923fa8c4d8e06d14b4f960daaba8b38886c617 100644 (file)
@@ -128,11 +128,12 @@ double World::getHeight(double x, double y, double z)
 
             int h = 0.0;
             for (auto b : l.hitbox[wx]) {
-                if (b)
+                if (b == true)
                     Y = h;
                 h++;
             }
-            return Y;
+            std::cout << l.drawLayer << "," << wx << "," << Y << std::endl;
+            return (Y/unitSize);
         }
     }
     return 0;
index fe4e400a1e4928a6d5d5354591655a043119fddc..6776e2cb34fa86592236039d641484063ad827a1 100644 (file)
@@ -88,22 +88,22 @@ private:
 public:
     SolidLayer(float z, sol::table tab) : Layer(z, tab) {
         if (tab["hitbox"] != nullptr) {
-            int width, height;
+            int width, height, channels;
             unsigned char* box = 
                 SOIL_load_image(std::string(tab["hitbox"]).c_str(),
-                                &width, &height, 0,
+                                &width, &height, &channels,
                                 SOIL_LOAD_RGBA);
 
-            for (int w = 0; w < width; w++) {
+            for (int w = 0; w < width*4; w+=4) {
                 hitbox.push_back(std::vector<bool>(height));
                 for (int h = 0; h < height; h++) {
-                    unsigned char* c = &box[(h) + (height*w*4)];
-                    // we want to read the red channel
+                    unsigned char* c = &box[(w) + (width*h*4)];
+                    // we want to read the alpha
                     if (c[3]) {
-                        hitbox[w][h] = true;
+                        hitbox[w/4][height-h] = true;
                     }
                     else
-                        hitbox[w][h] = false;
+                        hitbox[w/4][height-h] = false;
                 }
             }