Skip to content

Commit

Permalink
ZVISION: Implement code for pan from keyboard and mouse
Browse files Browse the repository at this point in the history
  • Loading branch information
Marisa-Chan committed Nov 12, 2014
1 parent e57c358 commit 1f0bf5e
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 12 deletions.
46 changes: 38 additions & 8 deletions engines/zvision/core/events.cpp
Expand Up @@ -189,10 +189,26 @@ void ZVision::processEvents() {
_console->onFrame();
}
break;

case Common::KEYCODE_LEFT:
case Common::KEYCODE_RIGHT:
if (_renderManager->getRenderTable()->getRenderState() == RenderTable::PANORAMA)
_kbdVelocity = (_event.kbd.keycode == Common::KEYCODE_LEFT ?
-_scriptManager->getStateValue(StateKey_KbdRotateSpeed) :
_scriptManager->getStateValue(StateKey_KbdRotateSpeed)) * 2;
case Common::KEYCODE_q:
if (_event.kbd.hasFlags(Common::KBD_CTRL))
quitGame();
break;

case Common::KEYCODE_UP:
case Common::KEYCODE_DOWN:
if (_renderManager->getRenderTable()->getRenderState() == RenderTable::TILT)
_kbdVelocity = (_event.kbd.keycode == Common::KEYCODE_UP ?
-_scriptManager->getStateValue(StateKey_KbdRotateSpeed) :
_scriptManager->getStateValue(StateKey_KbdRotateSpeed)) * 2;
break;

default:
break;
}
Expand All @@ -208,6 +224,20 @@ void ZVision::processEvents() {
break;
case Common::EVENT_KEYUP:
_scriptManager->addEvent(_event);
switch (_event.kbd.keycode) {
case Common::KEYCODE_LEFT:
case Common::KEYCODE_RIGHT:
if (_renderManager->getRenderTable()->getRenderState() == RenderTable::PANORAMA)
_kbdVelocity = 0;
break;
case Common::KEYCODE_UP:
case Common::KEYCODE_DOWN:
if (_renderManager->getRenderTable()->getRenderState() == RenderTable::TILT)
_kbdVelocity = 0;
break;
default:
break;
}
break;
default:
break;
Expand Down Expand Up @@ -261,7 +291,7 @@ void ZVision::onMouseMove(const Common::Point &pos) {
int16 mspeed = _scriptManager->getStateValue(StateKey_RotateSpeed) >> 4;
if (mspeed <= 0)
mspeed = 400 >> 4;
_velocity = (((pos.x - (ROTATION_SCREEN_EDGE_OFFSET + _workingWindow.left)) << 7) / ROTATION_SCREEN_EDGE_OFFSET * mspeed) >> 7;
_mouseVelocity = (((pos.x - (ROTATION_SCREEN_EDGE_OFFSET + _workingWindow.left)) << 7) / ROTATION_SCREEN_EDGE_OFFSET * mspeed) >> 7;

_cursorManager->changeCursor(CursorIndex_Left);
cursorWasChanged = true;
Expand All @@ -270,20 +300,20 @@ void ZVision::onMouseMove(const Common::Point &pos) {
int16 mspeed = _scriptManager->getStateValue(StateKey_RotateSpeed) >> 4;
if (mspeed <= 0)
mspeed = 400 >> 4;
_velocity = (((pos.x - (_workingWindow.right - ROTATION_SCREEN_EDGE_OFFSET)) << 7) / ROTATION_SCREEN_EDGE_OFFSET * mspeed) >> 7;
_mouseVelocity = (((pos.x - (_workingWindow.right - ROTATION_SCREEN_EDGE_OFFSET)) << 7) / ROTATION_SCREEN_EDGE_OFFSET * mspeed) >> 7;

_cursorManager->changeCursor(CursorIndex_Right);
cursorWasChanged = true;
} else {
_velocity = 0;
_mouseVelocity = 0;
}
} else if (renderState == RenderTable::TILT) {
if (pos.y >= _workingWindow.top && pos.y < _workingWindow.top + ROTATION_SCREEN_EDGE_OFFSET) {

int16 mspeed = _scriptManager->getStateValue(StateKey_RotateSpeed) >> 4;
if (mspeed <= 0)
mspeed = 400 >> 4;
_velocity = (((pos.y - (_workingWindow.top + ROTATION_SCREEN_EDGE_OFFSET)) << 7) / ROTATION_SCREEN_EDGE_OFFSET * mspeed) >> 7;
_mouseVelocity = (((pos.y - (_workingWindow.top + ROTATION_SCREEN_EDGE_OFFSET)) << 7) / ROTATION_SCREEN_EDGE_OFFSET * mspeed) >> 7;

_cursorManager->changeCursor(CursorIndex_UpArr);
cursorWasChanged = true;
Expand All @@ -292,18 +322,18 @@ void ZVision::onMouseMove(const Common::Point &pos) {
int16 mspeed = _scriptManager->getStateValue(StateKey_RotateSpeed) >> 4;
if (mspeed <= 0)
mspeed = 400 >> 4;
_velocity = (((pos.y - (_workingWindow.bottom - ROTATION_SCREEN_EDGE_OFFSET)) << 7) / ROTATION_SCREEN_EDGE_OFFSET * mspeed) >> 7;
_mouseVelocity = (((pos.y - (_workingWindow.bottom - ROTATION_SCREEN_EDGE_OFFSET)) << 7) / ROTATION_SCREEN_EDGE_OFFSET * mspeed) >> 7;

_cursorManager->changeCursor(CursorIndex_DownArr);
cursorWasChanged = true;
} else {
_velocity = 0;
_mouseVelocity = 0;
}
} else {
_velocity = 0;
_mouseVelocity = 0;
}
} else {
_velocity = 0;
_mouseVelocity = 0;
}

if (!cursorWasChanged) {
Expand Down
12 changes: 9 additions & 3 deletions engines/zvision/zvision.cpp
Expand Up @@ -97,7 +97,8 @@ ZVision::ZVision(OSystem *syst, const ZVisionGameDescription *gameDesc)
_midiManager(nullptr),
_aud_id(0),
_rendDelay(2),
_velocity(0) {
_kbdVelocity(0),
_mouseVelocity(0) {

debug(1, "ZVision::ZVision");

Expand Down Expand Up @@ -365,12 +366,17 @@ bool ZVision::canRender() {
}

void ZVision::updateRotation() {
int16 _velocity = _mouseVelocity + _kbdVelocity;

if (_halveDelay)
_velocity /= 2;

if (_velocity) {
RenderTable::RenderState renderState = _renderManager->getRenderTable()->getRenderState();
if (renderState == RenderTable::PANORAMA) {
int16 st_pos = _scriptManager->getStateValue(StateKey_ViewPos);

int16 new_pos = st_pos + _velocity * (1 - 2 * 0);
int16 new_pos = st_pos + (_renderManager->getRenderTable()->getPanoramaReverse() ? -_velocity : _velocity);

int16 zero_point = _renderManager->getRenderTable()->getPanoramaZeroPoint();
if (st_pos >= zero_point && new_pos < zero_point)
Expand All @@ -389,7 +395,7 @@ void ZVision::updateRotation() {
} else if (renderState == RenderTable::TILT) {
int16 st_pos = _scriptManager->getStateValue(StateKey_ViewPos);

int16 new_pos = st_pos + _velocity * (1 - 2 * 0);
int16 new_pos = st_pos + _velocity;

int16 scr_height = _renderManager->getBkgSize().y;
int16 tilt_gap = _renderManager->getRenderTable()->getTiltGap();
Expand Down
3 changes: 2 additions & 1 deletion engines/zvision/zvision.h
Expand Up @@ -122,7 +122,8 @@ class ZVision : public Engine {
const Common::Rect _workingWindow_ZNM;

int _rendDelay;
int16 _velocity;
int16 _mouseVelocity;
int16 _kbdVelocity;
bool _halveDelay;

uint8 _cheatBuff[KEYBUF_SIZE];
Expand Down

0 comments on commit 1f0bf5e

Please sign in to comment.