* Moved walking code to Game::walkHero().

* Implemented WalkOn GPL command.
* Temporarily remaped StayOn and WalkOnPlay to WalkOn (for testing).

svn-id: r42735
This commit is contained in:
Denis Kasak 2009-07-25 04:36:43 +00:00
parent 22c372137f
commit 20baaf93f5
4 changed files with 53 additions and 36 deletions

View File

@ -171,43 +171,46 @@ void Game::loop() {
int y = _vm->_mouse->getPosY();
if (_vm->_mouse->lButtonPressed() && _currentRoom._walkingMap.isWalkable(x, y)) {
// Fetch dragon's animation ID
// FIXME: Need to add proper walking (this only warps the dragon to position)
int animID = getObject(kDragonObject)->_anims[0];
Animation *anim = _vm->_anims->getAnimation(animID);
// Calculate scaling factors
double scaleX = _currentRoom._pers0 + _currentRoom._persStep * y;
double scaleY = scaleX;
// Set the Z coordinate for the dragon's animation
anim->setZ(y+1);
// Fetch current frame
Drawable *frame = anim->getFrame();
// Fetch base height of the frame
uint height = frame->getHeight();
// We naturally want the dragon to position its feet to the location of the
// click but sprites are drawn from their top-left corner so we subtract
// the current height of the dragon's sprite
y -= (int)(scaleY * height);
anim->setRelative(x, y);
// Set the per-animation scaling factor
anim->setScaleFactors(scaleX, scaleY);
// Play the animation
_vm->_anims->play(animID);
debugC(4, kDraciLogicDebugLevel, "Walk to x: %d y: %d", x, y);
walkHero(x, y);
}
}
}
void Game::walkHero(int x, int y) {
// Fetch dragon's animation ID
// FIXME: Need to add proper walking (this only warps the dragon to position)
int animID = getObject(kDragonObject)->_anims[0];
Animation *anim = _vm->_anims->getAnimation(animID);
// Calculate scaling factors
double scaleX = _currentRoom._pers0 + _currentRoom._persStep * y;
double scaleY = scaleX;
// Set the Z coordinate for the dragon's animation
anim->setZ(y+1);
// Fetch current frame
Drawable *frame = anim->getFrame();
// Fetch base height of the frame
uint height = frame->getHeight();
// We naturally want the dragon to position its feet to the location of the
// click but sprites are drawn from their top-left corner so we subtract
// the current height of the dragon's sprite
y -= (int)(scaleY * height);
anim->setRelative(x, y);
// Set the per-animation scaling factor
anim->setScaleFactors(scaleX, scaleY);
// Play the animation
_vm->_anims->play(animID);
debugC(4, kDraciLogicDebugLevel, "Walk to x: %d y: %d", x, y);
}
void Game::loadRoom(int roomNum) {
BAFile *f;

View File

@ -187,6 +187,8 @@ public:
return n;
}
void walkHero(int x, int y);
void loadRoom(int roomNum);
int loadAnimation(uint animNum, uint z);
void loadOverlays();

View File

@ -58,9 +58,9 @@ void Script::setupCommandList() {
{ 9, 3, "ResetDialogue", 0, { 0 }, NULL },
{ 9, 4, "ResetDialogueFrom", 0, { 0 }, NULL },
{ 9, 5, "ResetBlock", 1, { 3 }, NULL },
{ 10, 1, "WalkOn", 3, { 1, 1, 3 }, NULL },
{ 10, 2, "StayOn", 3, { 1, 1, 3 }, NULL },
{ 10, 3, "WalkOnPlay", 3, { 1, 1, 3 }, NULL },
{ 10, 1, "WalkOn", 3, { 1, 1, 3 }, &Script::walkOn },
{ 10, 2, "StayOn", 3, { 1, 1, 3 }, &Script::walkOn }, // HACK: not a proper implementation
{ 10, 3, "WalkOnPlay", 3, { 1, 1, 3 }, &Script::walkOn }, // HACK: not a proper implementation
{ 11, 1, "LoadPalette", 1, { 2 }, NULL },
{ 12, 1, "SetPalette", 0, { 0 }, NULL },
{ 12, 2, "BlackPalette", 0, { 0 }, NULL },
@ -402,6 +402,17 @@ void Script::execUse(Common::Queue<int> &params) {
run(obj->_program, obj->_use);
}
void Script::walkOn(Common::Queue<int> &params) {
if (_vm->_game->getLoopStatus() == kStatusInventory) {
return;
}
int x = params.pop();
int y = params.pop();
params.pop(); // facing direction, not used yet
_vm->_game->walkHero(x, y);
}
/**
* @brief Evaluates mathematical expressions
* @param reader Stream reader set to the beginning of the expression

View File

@ -111,6 +111,7 @@ private:
void execInit(Common::Queue<int> &params);
void execLook(Common::Queue<int> &params);
void execUse(Common::Queue<int> &params);
void walkOn(Common::Queue<int> &params);
int operAnd(int op1, int op2);
int operOr(int op1, int op2);