diff options
-rw-r--r-- | engines/mads/game.cpp | 116 | ||||
-rw-r--r-- | engines/mads/game.h | 2 | ||||
-rw-r--r-- | engines/mads/scene.cpp | 2 |
3 files changed, 120 insertions, 0 deletions
diff --git a/engines/mads/game.cpp b/engines/mads/game.cpp index 5ffe3ec9e6..607b7a44a6 100644 --- a/engines/mads/game.cpp +++ b/engines/mads/game.cpp @@ -705,4 +705,120 @@ void Game::camSetSpeed() { } } +void Game::camUpdate() { + bool any_pan = camPan(&_camX, &_scene._posAdjust.x, &_player._playerPos.x, 320, _scene._sceneInfo->_width); + any_pan |= camPan(&_camY, &_scene._posAdjust.y, &_player._playerPos.y, 156, _scene._sceneInfo->_height); + + if (any_pan) { + _scene.setCamera(_scene._posAdjust); + _screenObjects._forceRescan = true; + } +} + +bool Game::camPan(Camera *camera, int16 *picture_view, int16 *player_loc, int display_size, int picture_size) { + if (!camera) + return false; + + bool panningFl = false; + if (camera->_panAllowedFl) { + camera->_currentFrameFl = false; + + uint32 timer; + if ((abs((int32) (camera->_timer - _player._priorTimer)) < camera->_rate) && (_player._ticksAmount == camera->_rate)) + timer = _player._priorTimer; + else + timer = camera->_timer; + + if (camera->_activeFl && (_scene._frameStartTime < timer)) + return (panningFl); + + camera->_timer = _scene._frameStartTime + camera->_rate; + + if (camera->_manualFl) { + if (camera->_activeFl) { + int diff = camera->_target - *picture_view; + int direction = 0; + if (diff < 0) + direction = -1; + else if (diff > 0) + direction = 1; + + int magnitude = MIN(abs(diff), camera->_speed); + + if (magnitude == 0) + camera->_activeFl = false; + else { + int panAmount; + if (direction < 0) + panAmount = -magnitude; + else + panAmount = magnitude; + + *picture_view += panAmount; + + panningFl = true; + camera->_currentFrameFl = true; + } + } + } else { + if (!camera->_activeFl) { + int lowEdge = *picture_view + camera->_startTolerance; + int highEdge = *picture_view - camera->_startTolerance + display_size - 1; + + if ((*player_loc < lowEdge) && (picture_view > 0)) { + camera->_activeFl = true; + camera->_direction = -1; + } + + if ((*player_loc > highEdge) && (*picture_view < (picture_size - display_size))) { + camera->_activeFl = true; + camera->_direction = 1; + } + } + + int newTarget = *player_loc - (display_size >> 1); + + if (camera->_direction < 0) + newTarget -= camera->_distOffCenter; + else + newTarget += camera->_distOffCenter; + + newTarget = MAX(0, newTarget); + newTarget = MIN(newTarget, (picture_size - display_size)); + + camera->_target = newTarget; + + int diff = newTarget - *picture_view; + int magnitude = abs(diff); + + int direction = 0; + if (diff < 0) + direction = -1; + else if (diff > 0) + direction = 1; + + if (camera->_activeFl && (magnitude <= camera->_endTolerance)) + camera->_activeFl = false; + + if (camera->_activeFl) { + magnitude = MIN(magnitude, camera->_speed); + + int panAmount; + if (direction < 0) + panAmount = -magnitude; + else + panAmount = magnitude; + + if (panAmount) { + *picture_view += panAmount; + panningFl = true; + camera->_currentFrameFl = true; + } + } + } + } + + return (panningFl); +} + } // End of namespace MADS diff --git a/engines/mads/game.h b/engines/mads/game.h index fa6444a834..0579d94b32 100644 --- a/engines/mads/game.h +++ b/engines/mads/game.h @@ -264,6 +264,8 @@ public: void camPanTo(Camera *camera, int target); void camInitDefault(); void camSetSpeed(); + void camUpdate(); + bool camPan(Camera *camera, int16 *picture_view, int16 *player_loc, int display_size, int picture_size); }; diff --git a/engines/mads/scene.cpp b/engines/mads/scene.cpp index 335f772bbb..da62a6335e 100644 --- a/engines/mads/scene.cpp +++ b/engines/mads/scene.cpp @@ -390,6 +390,7 @@ void Scene::doFrame() { !_vm->_game->_fx); } + _vm->_game->camUpdate(); if (_action._selectedAction && player._stepEnabled && !player._needToWalk && !_vm->_game->_trigger && !player._trigger) { _action.startAction(); @@ -789,6 +790,7 @@ void Scene::setDynamicAnim(int id, int anim_id, int segment) { void Scene::setCamera(Common::Point pos) { _posAdjust = pos; + warning("setCamera: Incomplete function"); } void Scene::drawToBackground(int spriteId, int frameId, Common::Point pos, int depth, int scale) { |