#include "Door.h"
+#include "Scene.h"
Door::Door(std::string modelpath, std::string texturepath) : Level(modelpath, texturepath),
angle(0), axis(vec3(0, 1, 0)), duration(0), speed(0), time(0)
void Door::trigger()
{
- //TODO add event
+ if (!timeresistant)
+ {
+ mainScene->addEvent(this, 3);
+ }
+
if (speed == 0)
{
if (time == 0)
void Door::reverseTrigger()
{
-
+ if (speed == 0)
+ {
+ if (time == 0)
+ {
+ speed = -1;
+ }
+ else
+ {
+ speed = 1;
+ }
+ }
+ else
+ {
+ speed = -speed;
+ }
}
-//TODO overwrite update
void Door::update(float deltaT)
{
time = time + speed * deltaT;
void Lever::trigger()
{
- turned = !turned;
-
- if (!timeresistant)
+ if (!isinanimation())
{
- mainScene->addEvent(this, 2);
- }
+ turned = !turned;
- if (turned)
- {
- this->startanimation((uint)0, 1.0f);
- for (auto i = recipients.cbegin(); i != recipients.cend(); ++i)
+ if (!timeresistant)
{
- (*i)->trigger();
+ mainScene->addEvent(this, 2);
}
- Message::info("Sesam öffne dich!");
- }
- else
- {
- this->startanimation((uint)0, -1.0f);
- for (auto i = recipients.cbegin(); i != recipients.cend(); ++i)
+ if (turned)
{
- (*i)->trigger();
+ this->startanimation((uint)0, 1.0f);
+ for (auto i = recipients.cbegin(); i != recipients.cend(); ++i)
+ {
+ (*i)->trigger();
+ }
+
+ Message::info("Sesam öffne dich!");
}
+ else
+ {
+ this->startanimation((uint)0, -1.0f);
+ for (auto i = recipients.cbegin(); i != recipients.cend(); ++i)
+ {
+ (*i)->trigger();
+ }
- Message::info("Sesam schließe dich!");
+ Message::info("Sesam schließe dich!");
+ }
}
}
void Lever::reverseTrigger()
{
turned = !turned;
+
+ if (turned)
+ {
+ this->startanimation((uint)0, -1.0f);
+ }
+ else
+ {
+ this->startanimation((uint)0, 1.0f);
+ }
}
\ No newline at end of file
{
case 0:
//forward Animation ended
- e.object->startanimation((uint) 0, -1.0f);
+ e.object->startanimation((uint) 0, 1.0f);
e.object->setanimationtime(e.time - currenttime);
break;
case 1:
//reverse Animation ended
- e.object->startanimation((uint) 0, 1.0f);
+ e.object->startanimation((uint) 0, -1.0f);
e.object->setanimationtime(e.time - currenttime);
break;
l->reverseTrigger();
}
break;
+
+ case 3:
+ //Door triggered
+ if (Door* l = dynamic_cast<Door*> (e.object))
+ {
+ l->reverseTrigger();
+ }
+ break;
}
}
\ No newline at end of file
{
if (animationSpeed >= 0)
{
- AnimationTime = _time;
+ AnimationTime = model->animationduration - _time;
}
else
{
- AnimationTime = model->animationduration - _time;
+ AnimationTime = _time;
}
}
AnimationTime = 0;
animationSpeed = 0;
- if (!timeresistant)
+ if (!timeresistant && deltaT > 0)
{
mainScene->addEvent(this, 1);
}
AnimationTime = model->animationduration - 0.01f;
animationSpeed = 0;
- if (!timeresistant)
+ if (!timeresistant && deltaT > 0)
{
mainScene->addEvent(this, 0);
}
}
}
}
+}
+
+bool SceneObject::isinanimation()
+{
+ return animationSpeed != 0;
}
\ No newline at end of file
virtual void startanimation(uint index, float speed);
virtual void setanimationtime(float time);
virtual void setAnimationLoop(bool loop);
+ bool isinanimation();
bool timeresistant = false;
bool ignore;