-lSDL2_image -lSOIL -lfreetype
CXXFLAGS = -ggdb -std=c++17 -Wall -Wextra -Werror -pedantic \
- -Wno-class-memaccess -Wno-implicit-fallthrough -m64
+ -Wno-class-memaccess -Wno-implicit-fallthrough -m64 -O1
CXXINCS = -Isrc -I$(LIBDIR)/LuaJIT/src -I$(LIBDIR)/entityx \
-I$(LIBDIR)/LuaBridge/Source -I$(LIBDIR)/sol2/include \
end
},
Position = {
- x = 15,
- y = 75
+ 15.0, 10.0
},
Velocity = {
x = 0.0,
y = 0.0
},
+ Hitbox = {
+ bounds = {
+ {x = -0.5, y = -0.8},
+ {x = 0.5, y = -0.8},
+ {x = -0.5, y = 0.8},
+ {x = 0.5, y = 0.8},
+ }
+ },
Physics = 0,
Name = "bord",
- hellotrue = true,
- hellofalse = false,
Render = {
texture = "Assets/player.png",
- visible = true
+ visible = true,
+ bounds = {
+ {x = -0.5, y = -0.8},
+ {x = 0.5, y = -0.8},
+ {x = -0.5, y = 0.8},
+ {x = 0.5, y = 0.8},
+ }
},
Light = {
r = 1.0,
strength = 1.0
},
Idle = function(self)
- --if (self.visibleTick >= 20) then
- -- self.Render.visible = not self.Render.visible
- -- self.visibleTick = 0
- --end
- --self.visibleTick = self.visibleTick + 1
end,
visibleTick = 0
}
dofile("Scripts/world.lua")
playerSpawn = game.spawn(player);
---game.spawn(ball);
+game.spawn(ball);
-------------------
-- SERIALIZING --
#include <entityx/entityx.h>
#include <sol/sol.hpp>
+#include <script/vectors.hpp>
+
template<typename T>
class Component : public entityx::Component<T>
{
Position FromLua(sol::object ref)
{
- if (ref.get_type() == sol::type::table) {
- sol::table tab = ref;
- if (tab["x"] != nullptr)
- this->x = tab["x"];
- if (tab["y"] != nullptr)
- this->y = tab["y"];
- } else {
- throw std::string("Position table not formatted properly");
- }
+ glm::vec2 vec = Script::to<glm::vec2>(ref);
+ this->x = vec.x;
+ this->y = vec.y;
+
return *this;
}
sol::table ScriptSystem::spawn(sol::object param)
{
- sol::table* toRet; // "Entitiy" table to be returned
+ sol::table* toRet = NULL; // "Entitiy" table to be returned
if (param.get_type() == sol::type::table) {
sol::table tab = param; // Cast the generic parameter to a table
--- /dev/null
+/*
+ * Copyright (C) 2019 Belle-Isle, Andrew <drumsetmonkey@gmail.com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "vectors.hpp"
+
+#include <glm/glm.hpp>
+
+#include <iostream>
+
+namespace Script
+{
+ template<class T>
+ T to(sol::object obj)
+ {
+ (void)obj;
+ T fake;
+ return fake;
+ }
+
+ template<>
+ glm::vec2 to<glm::vec2>(sol::object obj)
+ {
+ glm::vec2 toReturn;
+
+ if (obj.get_type() == sol::type::table) {
+ sol::table table = obj;
+ // X
+ if (table["x"] == sol::type::number) {
+ toReturn.x = table["x"];
+ } else if (table[1] == sol::type::number) {
+ toReturn.x = table[1];
+ }
+ // Y
+ if (table["y"] == sol::type::number) {
+ toReturn.y = table["y"];
+ } else if (table[2] == sol::type::number) {
+ toReturn.y = table[2];
+ }
+ } else {
+ std::cerr << "Vectors must be in table form" << std::endl;
+ }
+
+ return toReturn;
+ }
+
+ template<>
+ glm::vec3 to<glm::vec3>(sol::object obj)
+ {
+ glm::vec3 toReturn;
+
+ if (obj.get_type() == sol::type::table) {
+ sol::table table = obj;
+ glm::vec2 base = to<glm::vec2>(table);
+ toReturn.x = base.x;
+ toReturn.y = base.y;
+
+ // Z
+ if (table["z"] == sol::type::number) {
+ toReturn.z = table["z"];
+ } else if (table[3] == sol::type::number) {
+ toReturn.z = table[3];
+ }
+ } else {
+ std::cerr << "Vectors must be in table form" << std::endl;
+ }
+
+ return toReturn;
+ }
+
+ template<>
+ glm::vec4 to<glm::vec4>(sol::object obj)
+ {
+ glm::vec4 toReturn;
+
+ if (obj.get_type() == sol::type::table) {
+ sol::table table = obj;
+ glm::vec3 base = to<glm::vec3>(table);
+ toReturn.x = base.x;
+ toReturn.y = base.y;
+ toReturn.z = base.z;
+
+ // W
+ if (table["w"] == sol::type::number) {
+ toReturn.w = table["w"];
+ } else if (table[4] == sol::type::number) {
+ toReturn.w = table[4];
+ }
+ } else {
+ std::cerr << "Vectors must be in table form" << std::endl;
+ }
+
+ return toReturn;
+ }
+}
--- /dev/null
+/**
+ * @file vectors.hpp
+ *
+ * Copyright (C) 2019 Belle-Isle, Andrew <drumsetmonkey@gmail.com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef SCRIPT_VECTORS_HPP_
+#define SCRIPT_VECTORS_HPP_
+
+#include <sol/sol.hpp>
+
+namespace Script
+{
+ template<class T>
+ T to(sol::object obj);
+}
+
+#endif//SCRIPT_VECTORS_HPP_
Y = h;
h++;
}
- std::cout << l.drawLayer << "," << wx << "," << Y << std::endl;
return (Y/unitSize);
}
}
&width, &height, &channels,
SOIL_LOAD_RGBA);
- for (int w = 0; w < width*4; w+=4) {
+ for (int w = 0; w < width*channels; w+=channels) {
hitbox.push_back(std::vector<bool>(height));
for (int h = 0; h < height; h++) {
- unsigned char* c = &box[(w) + (width*h*4)];
- // we want to read the alpha
- if (c[3]) {
- hitbox[w/4][height-h] = true;
+ unsigned char* c = &box[(w) + (width*h*channels)];
+ // we want to read the last channel (alpha)
+ if (c[channels-1]) {
+ hitbox[w/channels][height-h] = true;
}
else
- hitbox[w/4][height-h] = false;
+ hitbox[w/channels][height-h] = false;
}
}