]> git.leopard-lacewing.eu Git - cgue_weave.git/commitdiff
Events trigger only once
authorPeter Schaefer <schaeferpm@gmail.com>
Tue, 21 Jun 2016 09:28:48 +0000 (11:28 +0200)
committerPeter Schaefer <schaeferpm@gmail.com>
Tue, 21 Jun 2016 09:28:48 +0000 (11:28 +0200)
Weave/Game.cpp
Weave/Scene/Boar.cpp
Weave/Scene/Boar.h
Weave/Scene/EventBox.cpp
Weave/Scene/EventBox.h

index f245a553905b327ea4edac4262f3b471b45b94c1..1e965fd62caa6e140d7501111a853b4e2d405cd1 100644 (file)
@@ -84,7 +84,7 @@ Game::Game() : playing(true)
        lever2->timeresistant = true;\r
        lever2->setup(door1);\r
 \r
-       current_world->addObject(new Boar(translate(vec3(-5.f, 1.f, 3.f))));\r
+       current_world->addObject(new Boar(translate(vec3(-5.f, 1.f, 5.f))));\r
 \r
 \r
        //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"));\r
index e687c5d90649aa5309899356bd4dfbd1b0dca161..bc487854e33ea1ce4de2b7c445248221ff9d4e7f 100644 (file)
@@ -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;
        
 }
index 74c384515cbd11e6d8bf79bedd319ab74f33cd35..413bb3f593b1780b886de9648db67f674eb6202e 100644 (file)
@@ -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;
 };
 
index dd2b318f0ed1c1158ce75174d2d12f8c4aae0e06..f113782af18f232ba3636e95db63f0c34701fdaf 100644 (file)
@@ -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;
 }
index 10faef1094de8313e50bd16d636213287567fa35..814c8a646d3c09aeffb2513a4293073fd45ab7bb 100644 (file)
@@ -23,4 +23,7 @@ public:
 
 protected:
        eventBoxType eb_type;
+
+       bool activated = false;
+       bool nextFrame = true;
 };