diff --git a/Levels/scripts/deleteRandomObject.lua b/Levels/scripts/deleteRandomObject.lua index 628eff0..365e5b3 100644 --- a/Levels/scripts/deleteRandomObject.lua +++ b/Levels/scripts/deleteRandomObject.lua @@ -1,9 +1,8 @@ function trigger(objectToChange) - print("Hello from Lua!") - --if(not this_level) then + if(not this_level) then print("No level found!") return - --end + end a = this_level:getObjectCount() rand = math.random(0, a - 1) this_level:deleteObject(rand) diff --git a/level.cc b/level.cc index 115aa58..369b8b3 100644 --- a/level.cc +++ b/level.cc @@ -376,7 +376,7 @@ void Level::load() { } if (object != 0) { if (objectToChange != 0) { - Trigger trigger = Trigger(position, distance, isBigger, object, luaScript, L, objectToChange, this); + Trigger trigger = Trigger(position, distance, isBigger, object, luaScript, L, objectToChange); triggers.push_back(trigger); } else { @@ -484,7 +484,6 @@ std::vector* Level::getObjects() { void Level::deleteObject(int objectIndex){ objects.erase(objects.begin() + objectIndex); - printf("Deleting an object.\n"); } int Level::getObjectCount(){ diff --git a/trigger.cc b/trigger.cc index 3ddeaf8..aa5c3cc 100644 --- a/trigger.cc +++ b/trigger.cc @@ -1,17 +1,11 @@ #include "trigger.hh" -#include "level.hh" -Trigger::Trigger(glm::vec3 position, float distance, bool isBigger, Object* object, std::string luaScript, lua_State* L, int objectToChange, Level* level) { +Trigger::Trigger(glm::vec3 position, float distance, bool isBigger, Object* object, std::string luaScript, lua_State* L, int objectToChange) { this->position=position; this->distance=distance; this->isBigger=isBigger; this->object=object; - this->triggerLuaScript=("../Levels/scripts/" + luaScript + ".lua").c_str(); - printf("Hallo\n"); - printf(this->triggerLuaScript); - printf("Hallo\n"); - printf("\n"); - this->level = level; + this->luaScript="../Levels/scripts/" + luaScript + ".lua"; this->L = L; if(L == nullptr){ printf("L is NULL in trigger!\n"); @@ -29,41 +23,14 @@ Trigger::~Trigger(){ void Trigger::triggerUpdate(){ if (!triggered){ if (isBigger && (glm::distance(object->getPosition(), position) > distance)) { - printf(triggerLuaScript); - printf("\n"); - printf(triggerLuaScript); - printf("\nTriggering\n"); - //luaL_dofile(L, luaScript); - //luabridge::getGlobal(L, "trigger")(objectToChange); + luaL_dofile(L, luaScript.c_str()); + luabridge::getGlobal(L, "trigger")(objectToChange); triggered = true; } else if (!isBigger && (glm::distance(object->getPosition(), position) < distance)) { - printf(triggerLuaScript); - printf("\n"); - printf(triggerLuaScript); - printf("\nTriggering\n"); - //luaL_dofile(L, luaScript); - //luabridge::getGlobal(L, "trigger")(objectToChange); + luaL_dofile(L, luaScript.c_str()); + luabridge::getGlobal(L, "trigger")(objectToChange); triggered = true; } } } - -void Trigger::trigger_function_0(Level* level) { - if (!triggered) { - int rand = std::rand() % level->getObjects()->size(); - level->getObjects()->erase(level->getObjects()->begin() + rand); - } -} - -void Trigger::trigger_function_1(Level* level) { -} - -void Trigger::trigger_function_2(Level* level) { -} - -void Trigger::trigger_function_3(Level* level) { -} - -void Trigger::trigger_function_4(Level* level) { -} diff --git a/trigger.hh b/trigger.hh index aed4d64..0926c50 100644 --- a/trigger.hh +++ b/trigger.hh @@ -14,7 +14,7 @@ class Level; class Trigger { public: - Trigger(glm::vec3 position, float distance, bool isBigger, Object* object, std::string luaScript, lua_State* L, int objectToChange, Level* level); + Trigger(glm::vec3 position, float distance, bool isBigger, Object* object, std::string luaScript, lua_State* L, int objectToChange); Trigger(); ~Trigger(); void triggerUpdate(); @@ -23,16 +23,10 @@ class Trigger { float distance; bool isBigger; Object* object; - const char* triggerLuaScript; - Level* level; + std::string luaScript; bool triggered; lua_State* L; int objectToChange; - void trigger_function_0(Level* level); - void trigger_function_1(Level* level); - void trigger_function_2(Level* level); - void trigger_function_3(Level* level); - void trigger_function_4(Level* level); }; #endif