2014-12-15 12:36:04 +00:00
|
|
|
#include "trigger.hh"
|
2014-12-16 11:40:30 +00:00
|
|
|
#include "level.hh"
|
2014-12-15 12:36:04 +00:00
|
|
|
|
2014-12-16 11:40:30 +00:00
|
|
|
Trigger::Trigger(glm::vec3 position, float distance, bool isBigger, Object* object, int functionPointer_int, Level* level) {
|
2014-12-15 13:59:03 +00:00
|
|
|
this->position=position;
|
|
|
|
this->distance=distance;
|
|
|
|
this->isBigger=isBigger;
|
|
|
|
this->object=object;
|
2014-12-16 11:40:30 +00:00
|
|
|
void (*functionPointer)(Level*) = NULL;
|
|
|
|
switch(functionPointer_int) {
|
|
|
|
case 0:
|
|
|
|
this->functionPointer = &Trigger::trigger_function_0;
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
this->functionPointer = &Trigger::trigger_function_1;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
this->functionPointer = &Trigger::trigger_function_2;
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
this->functionPointer = &Trigger::trigger_function_3;
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
this->functionPointer = &Trigger::trigger_function_4;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
printf("Trigger function could not be found.\n");
|
|
|
|
}
|
2014-12-16 11:19:48 +00:00
|
|
|
this->level = level;
|
2014-12-15 12:36:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Trigger::Trigger(){
|
|
|
|
}
|
|
|
|
|
|
|
|
Trigger::~Trigger(){
|
|
|
|
}
|
2014-12-15 13:59:03 +00:00
|
|
|
|
|
|
|
void Trigger::triggerUpdate(){
|
2014-12-15 17:43:10 +00:00
|
|
|
if (isBigger && (glm::distance(object->getPosition(), position) > distance)) {
|
2014-12-16 11:40:30 +00:00
|
|
|
(this->*functionPointer)(level);
|
2014-12-15 17:43:10 +00:00
|
|
|
}
|
|
|
|
else if (!isBigger && (glm::distance(object->getPosition(), position) < distance)) {
|
2014-12-16 11:40:30 +00:00
|
|
|
(this->*functionPointer)(level);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Trigger::trigger_function_0(Level* level) {
|
|
|
|
static bool triggered = false;
|
|
|
|
if (!triggered) {
|
|
|
|
int rand = std::rand() % level->getObjects()->size();
|
|
|
|
level->getObjects()->erase(level->getObjects()->begin() + rand);
|
2014-12-15 17:43:10 +00:00
|
|
|
}
|
2014-12-16 11:40:30 +00:00
|
|
|
triggered = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
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) {
|
2014-12-15 13:59:03 +00:00
|
|
|
}
|