Moved trigger functions to trigger class.
This commit is contained in:
parent
bab84f01c1
commit
d91d5e2028
44
level.cc
44
level.cc
@ -298,28 +298,8 @@ void Level::load() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
errorCheck(xmlTrigger->FirstChildElement("functionPointer")->QueryIntText(&functionPointer_int));
|
errorCheck(xmlTrigger->FirstChildElement("functionPointer")->QueryIntText(&functionPointer_int));
|
||||||
void (*functionPointer)(Level*) = NULL;
|
|
||||||
switch(functionPointer_int) {
|
|
||||||
case 0:
|
|
||||||
functionPointer = &trigger_function_0;
|
|
||||||
break;
|
|
||||||
/*case 1:
|
|
||||||
functionPointer = &trigger_function_1;
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
functionPointer = &trigger_function_2;
|
|
||||||
break;
|
|
||||||
case 3:
|
|
||||||
functionPointer = &trigger_function_3;
|
|
||||||
break;
|
|
||||||
case 4:
|
|
||||||
functionPointer = &trigger_function_4;
|
|
||||||
break;*/
|
|
||||||
default:
|
|
||||||
printf("Trigger function could not be found.\n");
|
|
||||||
}
|
|
||||||
if (object != 0) {
|
if (object != 0) {
|
||||||
Trigger trigger = Trigger(position, distance, isBigger, object, functionPointer, this);
|
Trigger trigger = Trigger(position, distance, isBigger, object, functionPointer_int, this);
|
||||||
triggers.push_back(trigger);
|
triggers.push_back(trigger);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -417,29 +397,7 @@ void Level::setSkydomeSize(float size) {
|
|||||||
skydomeSize = size;
|
skydomeSize = size;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Level::trigger_function_0(Level* level) {
|
|
||||||
static bool triggered = false;
|
|
||||||
if (!triggered) {
|
|
||||||
printf("Trigger 0 triggered.\n");
|
|
||||||
int rand = std::rand() % level->getObjects()->size();
|
|
||||||
printf("%d, %d\n", rand, level->getObjects()->size());
|
|
||||||
level->getObjects()->erase(level->getObjects()->begin() + rand);
|
|
||||||
}
|
|
||||||
triggered = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::vector<Object*>* Level::getObjects() {
|
std::vector<Object*>* Level::getObjects() {
|
||||||
return &objects;
|
return &objects;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*void Level::trigger_function_1() {
|
|
||||||
}
|
|
||||||
|
|
||||||
void Level::trigger_function_2() {
|
|
||||||
}
|
|
||||||
|
|
||||||
void Level::trigger_function_3() {
|
|
||||||
}
|
|
||||||
|
|
||||||
void Level::trigger_function_4() {
|
|
||||||
}*/
|
|
||||||
|
5
level.hh
5
level.hh
@ -30,11 +30,6 @@ class Level {
|
|||||||
glm::vec4 getFogColour();
|
glm::vec4 getFogColour();
|
||||||
void setSkydomeSize(float size);
|
void setSkydomeSize(float size);
|
||||||
std::vector<Object*>* getObjects();
|
std::vector<Object*>* getObjects();
|
||||||
static void trigger_function_0(Level* level);
|
|
||||||
/*static void trigger_function_1();
|
|
||||||
static void trigger_function_2();
|
|
||||||
static void trigger_function_3();
|
|
||||||
static void trigger_function_4();*/
|
|
||||||
private:
|
private:
|
||||||
void errorCheck(tinyxml2::XMLError error);
|
void errorCheck(tinyxml2::XMLError error);
|
||||||
std::string levelNum;
|
std::string levelNum;
|
||||||
|
49
trigger.cc
49
trigger.cc
@ -1,11 +1,31 @@
|
|||||||
#include "trigger.hh"
|
#include "trigger.hh"
|
||||||
|
#include "level.hh"
|
||||||
|
|
||||||
Trigger::Trigger(glm::vec3 position, float distance, bool isBigger, Object* object, void (*functionPointer)(Level*), Level* level) {
|
Trigger::Trigger(glm::vec3 position, float distance, bool isBigger, Object* object, int functionPointer_int, Level* level) {
|
||||||
this->position=position;
|
this->position=position;
|
||||||
this->distance=distance;
|
this->distance=distance;
|
||||||
this->isBigger=isBigger;
|
this->isBigger=isBigger;
|
||||||
this->object=object;
|
this->object=object;
|
||||||
this->functionPointer = functionPointer;
|
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");
|
||||||
|
}
|
||||||
this->level = level;
|
this->level = level;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -17,9 +37,30 @@ Trigger::~Trigger(){
|
|||||||
|
|
||||||
void Trigger::triggerUpdate(){
|
void Trigger::triggerUpdate(){
|
||||||
if (isBigger && (glm::distance(object->getPosition(), position) > distance)) {
|
if (isBigger && (glm::distance(object->getPosition(), position) > distance)) {
|
||||||
(*functionPointer)(level);
|
(this->*functionPointer)(level);
|
||||||
}
|
}
|
||||||
else if (!isBigger && (glm::distance(object->getPosition(), position) < distance)) {
|
else if (!isBigger && (glm::distance(object->getPosition(), position) < distance)) {
|
||||||
(*functionPointer)(level);
|
(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);
|
||||||
|
}
|
||||||
|
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) {
|
||||||
|
}
|
||||||
|
@ -8,7 +8,7 @@ class Level;
|
|||||||
|
|
||||||
class Trigger {
|
class Trigger {
|
||||||
public:
|
public:
|
||||||
Trigger(glm::vec3 position, float distance, bool isBigger, Object* object, void (*functionPointer)(Level*), Level* level);
|
Trigger(glm::vec3 position, float distance, bool isBigger, Object* object, int functionPointer_int, Level* level);
|
||||||
Trigger();
|
Trigger();
|
||||||
~Trigger();
|
~Trigger();
|
||||||
void triggerUpdate();
|
void triggerUpdate();
|
||||||
@ -17,8 +17,13 @@ class Trigger {
|
|||||||
float distance;
|
float distance;
|
||||||
bool isBigger;
|
bool isBigger;
|
||||||
Object* object;
|
Object* object;
|
||||||
void (*functionPointer)(Level*);
|
void (Trigger::*functionPointer)(Level*);
|
||||||
Level* level;
|
Level* level;
|
||||||
|
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
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user