]> code.bitgloo.com Git - clyne/gamedev2.git/commitdiff
Started working on reading collision maps for worlds
authorAndy Belle-Isle <drumsetmonkey@gmail.com>
Sun, 6 Oct 2019 08:07:50 +0000 (04:07 -0400)
committerAndy Belle-Isle <drumsetmonkey@gmail.com>
Sun, 6 Oct 2019 08:07:50 +0000 (04:07 -0400)
src/texture.cpp
src/texture.hpp
src/world.cpp
src/world.hpp

index 2870b9f78e4c4216c4e4f29a53ea56501122ee38..b013bef5c6d85af7768860f5efd363527e2e3f9d 100644 (file)
@@ -21,6 +21,8 @@
 
 #include "texture.hpp"
 
+#include <soil/SOIL.h>
+
 #include <unordered_map>
 #include <iostream>
 
index 3daebbd17afef816338e8a4a0853602d53b2f49e..b03d6495e65af2f4947a25a49a19c540ab9ae2ec 100644 (file)
@@ -20,8 +20,6 @@
 #ifndef TEXTURE_HPP_
 #define TEXTURE_HPP_
 
-#include <soil/SOIL.h>
-
 #include <sol/sol.hpp>
 
 #include <GL/glew.h>
index 7b82d326ef48b8fc883379ecd3de60aee34a7406..8c15ccca6633d88773fce6af740c7f37f3313ad8 100644 (file)
@@ -55,7 +55,6 @@ World::World(sol::object param)
     // If a generate function is defined, call it
     if (generate != sol::nil)
         generate(this);
-    std::cout << "flamingo" << std::endl;
 }
 
 // TODO
@@ -121,12 +120,22 @@ unsigned int World::setSeed(unsigned int s)
 /* PHYSICS */
 double World::getHeight(double x, double y, double z)
 {
-    (void)x;
     (void)y;
-    (void)z;
-
-    double Y = 10.0f;
-    return Y;
+    double Y = 0.0f;
+    for (auto &l : solidLayers) {
+        if (z == l.drawLayer) {
+            int wx = x*unitSize;
+
+            int h = 0.0;
+            for (auto b : l.hitbox[wx]) {
+                if (b)
+                    Y = h;
+                h++;
+            }
+            return Y;
+        }
+    }
+    return 0;
 }
 
 /*********
index a6d2f1d6fc2acb0e616eb2d983cf83559daa5971..fe4e400a1e4928a6d5d5354591655a043119fddc 100644 (file)
@@ -26,6 +26,8 @@
 #include <entityx/entityx.h>
 #include <sol/sol.hpp>
 
+#include <soil/SOIL.h>
+
 #include "texture.hpp"
 #include "events/render.hpp"
 
@@ -80,12 +82,32 @@ public:
 
 class SolidLayer : public Layer
 {
+    friend class World;
 private:
-    // hitbox something something
+    std::vector<std::vector<bool>> hitbox;
 public:
     SolidLayer(float z, sol::table tab) : Layer(z, tab) {
         if (tab["hitbox"] != nullptr) {
-            std::cout << "hitbox: " << std::string(tab["hitbox"]) << std::endl;
+            int width, height;
+            unsigned char* box = 
+                SOIL_load_image(std::string(tab["hitbox"]).c_str(),
+                                &width, &height, 0,
+                                SOIL_LOAD_RGBA);
+
+            for (int w = 0; w < width; w++) {
+                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
+                    if (c[3]) {
+                        hitbox[w][h] = true;
+                    }
+                    else
+                        hitbox[w][h] = false;
+                }
+            }
+
+            SOIL_free_image_data(box);
         }
     }
 };