From: Peter Schaefer Date: Tue, 21 Jun 2016 09:28:48 +0000 (+0200) Subject: Events trigger only once X-Git-Url: https://git.leopard-lacewing.eu/?a=commitdiff_plain;h=f60a0e55c5baa62ff06608127319e444dfeffc5c;p=cgue_weave.git Events trigger only once --- diff --git a/Weave/Game.cpp b/Weave/Game.cpp index f245a55..1e965fd 100644 --- a/Weave/Game.cpp +++ b/Weave/Game.cpp @@ -84,7 +84,7 @@ Game::Game() : playing(true) lever2->timeresistant = true; lever2->setup(door1); - current_world->addObject(new Boar(translate(vec3(-5.f, 1.f, 3.f)))); + current_world->addObject(new Boar(translate(vec3(-5.f, 1.f, 5.f)))); //current_world->addObject(new SceneObject(translate(vec3(-5.f, 3.f, 0.f)), vec4(3.0f, 3.f, 0.4f, 1.5f), "SkyBox", "model_SkyBox_2D.png")); diff --git a/Weave/Scene/Boar.cpp b/Weave/Scene/Boar.cpp index e687c5d..bc48785 100644 --- a/Weave/Scene/Boar.cpp +++ b/Weave/Scene/Boar.cpp @@ -16,16 +16,30 @@ Boar::~Boar() { } -//void Boar::update(float _deltaT) -//{ -// SceneObject::update(_deltaT); -//} +void Boar::update(float _deltaT) +{ + SceneObject::update(_deltaT); + + if (activated) + { + if (nextFrame) + activated = false; + else + nextFrame = true; + } +} void Boar::collides(SceneObject * _other, btPersistentManifold * _contactManifold, float _deltaT) { if (_other->collide_group != COL_MARVIN) return; + if (activated) + { + nextFrame = false; + return; + } + int numContacts = _contactManifold->getNumContacts(); //For each contact point in that manifold double pdist = (_contactManifold->getContactPoint(0).getDistance()); @@ -42,5 +56,7 @@ void Boar::collides(SceneObject * _other, btPersistentManifold * _contactManifol Message::info("Spiel Verloren!->" + std::to_string(pdist)); //Events::halt = true; _other->movable = false; + + activated = true; } diff --git a/Weave/Scene/Boar.h b/Weave/Scene/Boar.h index 74c3845..413bb3f 100644 --- a/Weave/Scene/Boar.h +++ b/Weave/Scene/Boar.h @@ -10,8 +10,12 @@ public: Boar(const mat4& modelMat); ~Boar(); -// virtual void update(float) override; + virtual void update(float) override; virtual void collides(SceneObject* other, btPersistentManifold* contactManifold, float deltaT = 1.f) override; + +protected: + bool activated = false; + bool nextFrame = true; }; diff --git a/Weave/Scene/EventBox.cpp b/Weave/Scene/EventBox.cpp index dd2b318..f113782 100644 --- a/Weave/Scene/EventBox.cpp +++ b/Weave/Scene/EventBox.cpp @@ -52,6 +52,13 @@ EventBox::~EventBox() void EventBox::update(float _deltaT) { + if (activated) + { + if (nextFrame) + activated = false; + else + nextFrame = true; + } } void EventBox::draw(drawTarget _target) const @@ -62,6 +69,12 @@ void EventBox::draw(drawTarget _target) const void EventBox::collides(SceneObject* _other, btPersistentManifold* _contactManifold, float _deltaT) { + if (activated) + { + nextFrame = false; + return; + } + switch (eb_type) { default: @@ -81,4 +94,6 @@ void EventBox::collides(SceneObject* _other, btPersistentManifold* _contactManif ((Lever*)_other)->trigger(); break; } + + activated = true; } diff --git a/Weave/Scene/EventBox.h b/Weave/Scene/EventBox.h index 10faef1..814c8a6 100644 --- a/Weave/Scene/EventBox.h +++ b/Weave/Scene/EventBox.h @@ -23,4 +23,7 @@ public: protected: eventBoxType eb_type; + + bool activated = false; + bool nextFrame = true; };