moved the triggered/not triggered information to lua

This commit is contained in:
Steffen Fündgens 2015-01-16 16:51:36 +01:00
parent 2c0d4424a2
commit ed6e257b69
4 changed files with 36 additions and 29 deletions

View File

@ -1,4 +1,8 @@
if(triggeredDeleteObject == nil) then
triggeredDeleteObject = false
end
function trigger(objectToChange) function trigger(objectToChange)
if(triggeredDeleteObject == false) then
if(not level) then if(not level) then
print("No level found in Lua!") print("No level found in Lua!")
return return
@ -8,4 +12,7 @@ function trigger(objectToChange)
return return
end end
level:deleteObject(objectToChange) level:deleteObject(objectToChange)
triggeredDeleteObject = true
print("deleteObject")
end
end end

View File

@ -1,4 +1,8 @@
if(triggeredDeleteRandomObject == nil) then
triggeredDeleteRandomObject = false
end
function trigger(objectToChange) function trigger(objectToChange)
if(triggeredDeleteRandomObject == false) then
if(not level) then if(not level) then
print("No level found in Lua!") print("No level found in Lua!")
return return
@ -10,5 +14,7 @@ function trigger(objectToChange)
a = level:getObjectCount() a = level:getObjectCount()
rand = math.random(0, a - 1) rand = math.random(0, a - 1)
level:deleteObject(rand) level:deleteObject(rand)
print("Triggered from Lua!") triggeredDeleteRandomObject = true
print("deleteRandomObject")
end
end end

View File

@ -11,7 +11,6 @@ Trigger::Trigger(glm::vec3 position, float distance, bool isBigger, Object* obje
printf("L is NULL in trigger!\n"); printf("L is NULL in trigger!\n");
} }
this->objectToChange = objectToChange; this->objectToChange = objectToChange;
triggered = false;
} }
Trigger::Trigger(){ Trigger::Trigger(){
@ -21,17 +20,13 @@ Trigger::~Trigger(){
} }
void Trigger::triggerUpdate(){ void Trigger::triggerUpdate(){
if (!triggered){
if (isBigger && (glm::distance(object->getPosition(), position) > distance)) { if (isBigger && (glm::distance(object->getPosition(), position) > distance)) {
luaL_dofile(L, luaScript.c_str()); luaL_dofile(L, luaScript.c_str());
luabridge::getGlobal(L, "trigger")(objectToChange); luabridge::getGlobal(L, "trigger")(objectToChange);
triggered = true;
} }
else if (!isBigger && (glm::distance(object->getPosition(), position) < distance)) { else if (!isBigger && (glm::distance(object->getPosition(), position) < distance)) {
luaL_dofile(L, luaScript.c_str()); luaL_dofile(L, luaScript.c_str());
luabridge::getGlobal(L, "trigger")(objectToChange); luabridge::getGlobal(L, "trigger")(objectToChange);
triggered = true;
}
} }
} }

View File

@ -25,7 +25,6 @@ class Trigger {
bool isBigger; bool isBigger;
Object* object; Object* object;
std::string luaScript; std::string luaScript;
bool triggered;
lua_State* L; lua_State* L;
int objectToChange; int objectToChange;
}; };