2014-12-15 12:36:04 +00:00
|
|
|
#include "trigger.hh"
|
|
|
|
|
2015-02-06 17:00:14 +00:00
|
|
|
Trigger::Trigger(glm::vec3 position, float distance, bool isBigger, Object* object, std::string luaScript, lua_State* L, int objectToChange, std::string scriptPath) {
|
2014-12-15 13:59:03 +00:00
|
|
|
this->position=position;
|
|
|
|
this->distance=distance;
|
|
|
|
this->isBigger=isBigger;
|
|
|
|
this->object=object;
|
2015-02-06 17:00:14 +00:00
|
|
|
this->luaScript= scriptPath + luaScript + ".lua";
|
2015-01-09 15:51:28 +00:00
|
|
|
this->L = L;
|
|
|
|
if(L == nullptr){
|
|
|
|
printf("L is NULL in trigger!\n");
|
|
|
|
}
|
2015-01-13 12:52:22 +00:00
|
|
|
this->objectToChange = objectToChange;
|
2014-12-15 12:36:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Trigger::Trigger(){
|
|
|
|
}
|
|
|
|
|
|
|
|
Trigger::~Trigger(){
|
|
|
|
}
|
2014-12-15 13:59:03 +00:00
|
|
|
|
|
|
|
void Trigger::triggerUpdate(){
|
2015-01-09 15:51:28 +00:00
|
|
|
if (isBigger && (glm::distance(object->getPosition(), position) > distance)) {
|
2015-01-13 16:21:15 +00:00
|
|
|
luaL_dofile(L, luaScript.c_str());
|
|
|
|
luabridge::getGlobal(L, "trigger")(objectToChange);
|
2015-01-09 15:51:28 +00:00
|
|
|
}
|
|
|
|
else if (!isBigger && (glm::distance(object->getPosition(), position) < distance)) {
|
2015-01-13 16:21:15 +00:00
|
|
|
luaL_dofile(L, luaScript.c_str());
|
|
|
|
luabridge::getGlobal(L, "trigger")(objectToChange);
|
2015-01-09 15:51:28 +00:00
|
|
|
}
|
2014-12-16 11:40:30 +00:00
|
|
|
}
|
2015-01-13 17:18:13 +00:00
|
|
|
|
|
|
|
bool Trigger::deleteNotification(int deletedObjectIndex){
|
|
|
|
if (deletedObjectIndex < objectToChange){
|
|
|
|
objectToChange-=1;
|
|
|
|
}
|
|
|
|
if (deletedObjectIndex == objectToChange){
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|