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

View File

@ -1,4 +1,8 @@
if(triggeredDeleteRandomObject == nil) then
triggeredDeleteRandomObject = false
end
function trigger(objectToChange)
if(triggeredDeleteRandomObject == false) then
if(not level) then
print("No level found in Lua!")
return
@ -10,5 +14,7 @@ function trigger(objectToChange)
a = level:getObjectCount()
rand = math.random(0, a - 1)
level:deleteObject(rand)
print("Triggered from Lua!")
triggeredDeleteRandomObject = true
print("deleteRandomObject")
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");
}
this->objectToChange = objectToChange;
triggered = false;
}
Trigger::Trigger(){
@ -21,17 +20,13 @@ Trigger::~Trigger(){
}
void Trigger::triggerUpdate(){
if (!triggered){
if (isBigger && (glm::distance(object->getPosition(), position) > distance)) {
luaL_dofile(L, luaScript.c_str());
luabridge::getGlobal(L, "trigger")(objectToChange);
triggered = true;
}
else if (!isBigger && (glm::distance(object->getPosition(), position) < distance)) {
luaL_dofile(L, luaScript.c_str());
luabridge::getGlobal(L, "trigger")(objectToChange);
triggered = true;
}
}
}

View File

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