Added helper functions for dragon animations

svn-id: r45677
This commit is contained in:
Robert Špalek 2009-11-05 00:21:54 +00:00
parent 1f49679db5
commit fc2e2e27fc
2 changed files with 100 additions and 0 deletions

View File

@ -493,4 +493,95 @@ bool WalkingState::continueWalking() {
return false; // finished
}
Movement WalkingState::animationForDirection(const Common::Point &here, const Common::Point &there) {
const int dx = there.x - here.x;
const int dy = there.y - here.y;
if (abs(dx) >= abs(dy)) {
return dx >= 0 ? kMoveRight : kMoveLeft;
} else {
return dy >= 0 ? kMoveUp : kMoveDown;
}
}
Movement WalkingState::transitionBetweenAnimations(Movement previous, Movement next) {
switch (next) {
case kMoveUp:
switch (previous) {
case kMoveLeft:
case kStopLeft:
case kSpeakLeft:
return kMoveLeftUp;
case kMoveRight:
case kStopRight:
case kSpeakRight:
return kMoveRightUp;
default:
return kMoveUndefined;
}
case kMoveDown:
switch (previous) {
case kMoveLeft:
case kStopLeft:
case kSpeakLeft:
return kMoveLeftDown;
case kMoveRight:
case kStopRight:
case kSpeakRight:
return kMoveRightDown;
default:
return kMoveUndefined;
}
case kMoveLeft:
switch (previous) {
case kMoveDown:
return kMoveDownLeft;
case kMoveUp:
return kMoveUpLeft;
case kMoveRight:
case kStopRight:
case kSpeakRight:
return kMoveRightLeft;
default:
return kMoveUndefined;
}
case kMoveRight:
switch (previous) {
case kMoveDown:
return kMoveDownRight;
case kMoveUp:
return kMoveUpRight;
case kMoveLeft:
case kStopLeft:
case kSpeakLeft:
return kMoveLeftRight;
default:
return kMoveUndefined;
}
case kStopLeft:
switch (previous) {
case kMoveUp:
return kMoveUpStopLeft;
case kMoveRight:
case kStopRight:
case kSpeakRight:
return kMoveRightLeft;
default:
return kMoveUndefined;
}
case kStopRight:
switch (previous) {
case kMoveUp:
return kMoveUpStopRight;
case kMoveLeft:
case kStopLeft:
case kSpeakLeft:
return kMoveLeftRight;
default:
return kMoveUndefined;
}
default:
return kMoveUndefined;
}
}
}

View File

@ -128,6 +128,15 @@ private:
const GPL2Program *_callback;
uint16 _callbackOffset;
// Return one of the 4 animations kMove{Down,Up,Right,Left}
// corresponding to the walking from here to there.
static Movement animationForDirection(const Common::Point &here, const Common::Point &there);
// Returns either animation that needs to be played between given two
// animations (e.g., kMoveRightDown after kMoveRight and before
// kMoveDown), or kMoveUndefined if none animation is to be played.
static Movement transitionBetweenAnimations(Movement previous, Movement next);
};
} // End of namespace Draci