aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndy Belle-Isle <drumsetmonkey@gmail.com>2019-10-07 15:06:24 -0400
committerAndy Belle-Isle <drumsetmonkey@gmail.com>2019-10-07 15:06:24 -0400
commit9cef5e64ddd1ef20369b25cc19b1980084ebaefe (patch)
tree3ec2a1f80dc7eed34d2859016e568d04c44565e1
parent17ae15b41c5ec912c36956dbc38e5a95af0ac648 (diff)
Added image based hitbox detection
-rw-r--r--Assets/world/world1/layers/0/hitbox.pngbin3972 -> 4795 bytes
-rw-r--r--Assets/world/world1/layers/0/texture.pngbin4573 -> 6142 bytes
-rw-r--r--Scripts/init.lua2
-rw-r--r--src/world.cpp5
-rw-r--r--src/world.hpp14
5 files changed, 11 insertions, 10 deletions
diff --git a/Assets/world/world1/layers/0/hitbox.png b/Assets/world/world1/layers/0/hitbox.png
index 0a9a37e..881b13e 100644
--- a/Assets/world/world1/layers/0/hitbox.png
+++ b/Assets/world/world1/layers/0/hitbox.png
Binary files differ
diff --git a/Assets/world/world1/layers/0/texture.png b/Assets/world/world1/layers/0/texture.png
index 149273f..429107e 100644
--- a/Assets/world/world1/layers/0/texture.png
+++ b/Assets/world/world1/layers/0/texture.png
Binary files differ
diff --git a/Scripts/init.lua b/Scripts/init.lua
index ec9e350..1693d0c 100644
--- a/Scripts/init.lua
+++ b/Scripts/init.lua
@@ -86,7 +86,7 @@ ball = {
dofile("Scripts/world.lua")
playerSpawn = game.spawn(player);
-game.spawn(ball);
+--game.spawn(ball);
-------------------
-- SERIALIZING --
diff --git a/src/world.cpp b/src/world.cpp
index 8c15ccc..a3923fa 100644
--- a/src/world.cpp
+++ b/src/world.cpp
@@ -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;
diff --git a/src/world.hpp b/src/world.hpp
index fe4e400..6776e2c 100644
--- a/src/world.hpp
+++ b/src/world.hpp
@@ -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;
}
}