Fixed triggers. Now deletes a truly random object.
This commit is contained in:
parent
9497e99b58
commit
bab84f01c1
21
level.cc
21
level.cc
@ -298,12 +298,12 @@ void Level::load() {
|
||||
}
|
||||
}
|
||||
errorCheck(xmlTrigger->FirstChildElement("functionPointer")->QueryIntText(&functionPointer_int));
|
||||
void (*functionPointer)() = NULL;
|
||||
void (*functionPointer)(Level*) = NULL;
|
||||
switch(functionPointer_int) {
|
||||
case 0:
|
||||
functionPointer = &trigger_function_0;
|
||||
break;
|
||||
case 1:
|
||||
/*case 1:
|
||||
functionPointer = &trigger_function_1;
|
||||
break;
|
||||
case 2:
|
||||
@ -314,12 +314,12 @@ void Level::load() {
|
||||
break;
|
||||
case 4:
|
||||
functionPointer = &trigger_function_4;
|
||||
break;
|
||||
break;*/
|
||||
default:
|
||||
printf("Trigger function could not be found.\n");
|
||||
}
|
||||
if (object != 0) {
|
||||
Trigger trigger = Trigger(position, distance, isBigger, object, functionPointer);
|
||||
Trigger trigger = Trigger(position, distance, isBigger, object, functionPointer, this);
|
||||
triggers.push_back(trigger);
|
||||
}
|
||||
else {
|
||||
@ -417,15 +417,22 @@ void Level::setSkydomeSize(float size) {
|
||||
skydomeSize = size;
|
||||
}
|
||||
|
||||
void Level::trigger_function_0() {
|
||||
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;
|
||||
}
|
||||
|
||||
void Level::trigger_function_1() {
|
||||
std::vector<Object*>* Level::getObjects() {
|
||||
return &objects;
|
||||
}
|
||||
|
||||
/*void Level::trigger_function_1() {
|
||||
}
|
||||
|
||||
void Level::trigger_function_2() {
|
||||
@ -435,4 +442,4 @@ void Level::trigger_function_3() {
|
||||
}
|
||||
|
||||
void Level::trigger_function_4() {
|
||||
}
|
||||
}*/
|
||||
|
7
level.hh
7
level.hh
@ -29,11 +29,12 @@ class Level {
|
||||
glm::vec3 getCameraPosition();
|
||||
glm::vec4 getFogColour();
|
||||
void setSkydomeSize(float size);
|
||||
static void trigger_function_0();
|
||||
static void trigger_function_1();
|
||||
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();
|
||||
static void trigger_function_4();*/
|
||||
private:
|
||||
void errorCheck(tinyxml2::XMLError error);
|
||||
std::string levelNum;
|
||||
|
@ -1,11 +1,12 @@
|
||||
#include "trigger.hh"
|
||||
|
||||
Trigger::Trigger(glm::vec3 position, float distance, bool isBigger, Object* object, void (*functionPointer)()) {
|
||||
Trigger::Trigger(glm::vec3 position, float distance, bool isBigger, Object* object, void (*functionPointer)(Level*), Level* level) {
|
||||
this->position=position;
|
||||
this->distance=distance;
|
||||
this->isBigger=isBigger;
|
||||
this->object=object;
|
||||
this->functionPointer = functionPointer;
|
||||
this->functionPointer = functionPointer;
|
||||
this->level = level;
|
||||
}
|
||||
|
||||
Trigger::Trigger(){
|
||||
@ -16,9 +17,9 @@ Trigger::~Trigger(){
|
||||
|
||||
void Trigger::triggerUpdate(){
|
||||
if (isBigger && (glm::distance(object->getPosition(), position) > distance)) {
|
||||
(*functionPointer)();
|
||||
(*functionPointer)(level);
|
||||
}
|
||||
else if (!isBigger && (glm::distance(object->getPosition(), position) < distance)) {
|
||||
(*functionPointer)();
|
||||
(*functionPointer)(level);
|
||||
}
|
||||
}
|
||||
|
@ -4,9 +4,11 @@
|
||||
#include <vector>
|
||||
#include "object.hh"
|
||||
|
||||
class Level;
|
||||
|
||||
class Trigger {
|
||||
public:
|
||||
Trigger(glm::vec3 position, float distance, bool isBigger, Object* object, void (*functionPointer)());
|
||||
Trigger(glm::vec3 position, float distance, bool isBigger, Object* object, void (*functionPointer)(Level*), Level* level);
|
||||
Trigger();
|
||||
~Trigger();
|
||||
void triggerUpdate();
|
||||
@ -15,7 +17,8 @@ class Trigger {
|
||||
float distance;
|
||||
bool isBigger;
|
||||
Object* object;
|
||||
void (*functionPointer)();
|
||||
void (*functionPointer)(Level*);
|
||||
Level* level;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user