aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndy Belle-Isle <drumsetmonkey@gmail.com>2019-10-06 04:07:50 -0400
committerAndy Belle-Isle <drumsetmonkey@gmail.com>2019-10-06 04:07:50 -0400
commit17ae15b41c5ec912c36956dbc38e5a95af0ac648 (patch)
treeb1c3064f6c63e7dceb5e0cfcd04150628d72f49e
parent1a909087ddfdfe3b947c65b07287a08a40f119ce (diff)
Started working on reading collision maps for worlds
-rw-r--r--src/texture.cpp2
-rw-r--r--src/texture.hpp2
-rw-r--r--src/world.cpp21
-rw-r--r--src/world.hpp26
4 files changed, 41 insertions, 10 deletions
diff --git a/src/texture.cpp b/src/texture.cpp
index 2870b9f..b013bef 100644
--- a/src/texture.cpp
+++ b/src/texture.cpp
@@ -21,6 +21,8 @@
#include "texture.hpp"
+#include <soil/SOIL.h>
+
#include <unordered_map>
#include <iostream>
diff --git a/src/texture.hpp b/src/texture.hpp
index 3daebbd..b03d649 100644
--- a/src/texture.hpp
+++ b/src/texture.hpp
@@ -20,8 +20,6 @@
#ifndef TEXTURE_HPP_
#define TEXTURE_HPP_
-#include <soil/SOIL.h>
-
#include <sol/sol.hpp>
#include <GL/glew.h>
diff --git a/src/world.cpp b/src/world.cpp
index 7b82d32..8c15ccc 100644
--- a/src/world.cpp
+++ b/src/world.cpp
@@ -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;
}
/*********
diff --git a/src/world.hpp b/src/world.hpp
index a6d2f1d..fe4e400 100644
--- a/src/world.hpp
+++ b/src/world.hpp
@@ -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);
}
}
};