summaryrefslogtreecommitdiffstats
path: root/src/model/Entity.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/model/Entity.hpp')
-rw-r--r--src/model/Entity.hpp54
1 files changed, 22 insertions, 32 deletions
diff --git a/src/model/Entity.hpp b/src/model/Entity.hpp
index fa4477d..1ff444a 100644
--- a/src/model/Entity.hpp
+++ b/src/model/Entity.hpp
@@ -46,8 +46,8 @@ private:
Position pos;
Direction direction;
- unsigned transition = 0;
- unsigned step = 0;
+ uint64_t transitionStart = 0;
+ uint64_t transitionEnd = 0;
Position translate(Direction dir, float amount) const {
Position p = pos;
@@ -81,9 +81,14 @@ public:
return name;
}
- Position getPosition() const {
- if (transition)
- return translate(direction, (float)step / transition);
+ Position getPosition(uint64_t time) const {
+ if (hasTransition())
+ if (time <= transitionStart)
+ return pos;
+ else if (time >= transitionEnd)
+ return translate(direction, 1);
+ else
+ return translate(direction, float(time-transitionStart)/float(transitionEnd-transitionStart));
else
return pos;
}
@@ -92,43 +97,28 @@ public:
return direction;
}
- void moveTo(float newX, float newY) {
- pos.x = newX;
- pos.y = newY;
+ void moveTo(Position newPos) {
+ pos = newPos;
+ transitionStart = transitionEnd = 0;
}
- void move(Direction dir, unsigned steps = 0) {
- if (transition)
+ void move(Direction dir, uint64_t start, uint64_t end) {
+ if (hasTransition())
return;
direction = dir;
- if (steps)
- transition = steps;
- else
- pos = translate(direction, 1);
+ transitionStart = start;
+ transitionEnd = end;
}
- bool hasTransition() const {
- return transition;
+ void finishTransition() {
+ if (hasTransition())
+ moveTo(translate(direction, 1));
}
- unsigned advance(unsigned ticks) {
- if (!transition)
- return ticks;
-
- step += ticks;
-
- if (step >= transition) {
- ticks = step - transition;
- transition = step = 0;
- pos = translate(direction, 1);
-
- return ticks;
- }
- else {
- return 0;
- }
+ bool hasTransition() const {
+ return transitionEnd;
}
};