1
0
mirror of https://github.com/blupi-games/planetblupi synced 2024-12-30 10:15:36 +01:00

Add smooth scrolling for the playing and build area

It fixes the issue #28.
This commit is contained in:
Mathieu Schroeter 2017-10-30 18:14:31 +01:00
parent 64a0bf6512
commit 546f5a86ba
4 changed files with 158 additions and 60 deletions

View File

@ -455,7 +455,7 @@ CDecor::FixShifting (Sint32 & nbx, Sint32 & nby, Point & iCel, Point & iPos)
if (m_shiftOffset.x < 0) // décalage à droite ? if (m_shiftOffset.x < 0) // décalage à droite ?
nbx += 2; nbx += 2;
if (m_shiftOffset.y < 0) // décalage en bas ? if (m_shiftOffset.y < 0) // décalage en bas ?
nby += 2; nby += 3;
if (m_shiftOffset.x > 0) // décalage à gauche ? if (m_shiftOffset.x > 0) // décalage à gauche ?
{ {
nbx += 2; nbx += 2;
@ -995,6 +995,8 @@ CDecor::BuildGround (Rect clip)
nby += 2; nby += 2;
} }
this->FixShifting (nbx, nby, iCel, iPos);
// Construit les sols. // Construit les sols.
mCel = iCel; mCel = iCel;
mPos = iPos; mPos = iPos;
@ -1135,6 +1137,8 @@ CDecor::Build (Rect clip, Point posMouse)
nby += 2; nby += 2;
} }
this->FixShifting (nbx, nby, iCel, iPos);
// Construit les sols. // Construit les sols.
mCel = iCel; mCel = iCel;
mPos = iPos; mPos = iPos;
@ -1252,6 +1256,8 @@ CDecor::Build (Rect clip, Point posMouse)
// Construit les objets et les blupi. // Construit les objets et les blupi.
BuildPutBlupi (); // m_rankBlupi[x][y] <- rangs des blupi BuildPutBlupi (); // m_rankBlupi[x][y] <- rangs des blupi
this->FixShifting (nbx, nby, iCel, iPos);
mCel = iCel; mCel = iCel;
mPos = iPos; mPos = iPos;
for (j = 0; j < nby + 3; j++) for (j = 0; j < nby + 3; j++)

View File

@ -383,6 +383,13 @@ enum MouseSprites {
SPRITE_END = 14, SPRITE_END = 14,
}; };
enum ShiftDirection {
DIRECTION_UP = (1 << 0),
DIRECTION_DOWN = (1 << 1),
DIRECTION_LEFT = (1 << 2),
DIRECTION_RIGHT = (1 << 3),
};
// clang-format off // clang-format off
#define EV_OFFSET 0x0400 #define EV_OFFSET 0x0400

View File

@ -1612,6 +1612,8 @@ CEvent::CEvent ()
m_Lang = m_Languages.begin (); m_Lang = m_Languages.begin ();
m_updateBlinking = 0; m_updateBlinking = 0;
this->shiftDirection = 0;
} }
// Destructeur. // Destructeur.
@ -3482,86 +3484,162 @@ CEvent::DecorShift (Sint32 dx, Sint32 dy)
void void
CEvent::DecorAutoShift () CEvent::DecorAutoShift ()
{ {
Sint32 max; Sint32 max, maxLimit = 4, xMoveFactor = 1, yMoveFactor = 1, vectorFactor = 1;
Point offset; Point offset;
Uint32 dir;
bool byKeyboard = !!this->shiftDirection;
if (byKeyboard)
{
dir = this->shiftDirection;
xMoveFactor = 2;
yMoveFactor = 3;
vectorFactor = 2;
if (m_scrollSpeed == 1)
maxLimit = 5; // 4..2..1
}
else
{
switch (m_mouseSprite)
{
case SPRITE_ARROWL:
dir = DIRECTION_LEFT;
break;
case SPRITE_ARROWR:
dir = DIRECTION_RIGHT;
break;
case SPRITE_ARROWU:
dir = DIRECTION_UP;
break;
case SPRITE_ARROWD:
dir = DIRECTION_DOWN;
break;
case SPRITE_ARROWUL:
dir = DIRECTION_UP | DIRECTION_LEFT;
break;
case SPRITE_ARROWUR:
dir = DIRECTION_UP | DIRECTION_RIGHT;
break;
case SPRITE_ARROWDL:
dir = DIRECTION_DOWN | DIRECTION_LEFT;
break;
case SPRITE_ARROWDR:
dir = DIRECTION_DOWN | DIRECTION_RIGHT;
break;
default:
break;
}
}
m_bShift = false; m_bShift = false;
if (!m_bFullScreen || m_bDemoRec || m_bDemoPlay || m_scrollSpeed == 0) if (m_bDemoRec || m_bDemoPlay)
return; return;
max = 4 - m_scrollSpeed; // max <- 3..1 if (!byKeyboard && (!m_bFullScreen || m_scrollSpeed == 0))
return;
max = maxLimit - m_scrollSpeed; // max <- 3..1
if (m_phase == EV_PHASE_PLAY || m_phase == EV_PHASE_BUILD) if (m_phase == EV_PHASE_PLAY || m_phase == EV_PHASE_BUILD)
{ {
if (m_shiftPhase == 0) // start shift ? if (m_shiftPhase == 0) // start shift ?
{ {
switch (m_mouseSprite) switch (dir)
{ {
default: case DIRECTION_LEFT:
m_shiftOffset.x = 0;
m_shiftOffset.y = 0;
m_shiftVector.x = 0;
m_shiftVector.y = 0;
break;
case SPRITE_ARROWL:
m_shiftOffset.x = +2; m_shiftOffset.x = +2;
m_shiftOffset.y = 0; m_shiftOffset.y = 0;
m_shiftVector.x = -1; m_shiftVector.x = -1;
m_shiftVector.y = +1; m_shiftVector.y = +1;
break; break;
case SPRITE_ARROWR: case DIRECTION_RIGHT:
m_shiftOffset.x = -2; m_shiftOffset.x = -2;
m_shiftOffset.y = 0; m_shiftOffset.y = 0;
m_shiftVector.x = +1; m_shiftVector.x = +1;
m_shiftVector.y = -1; m_shiftVector.y = -1;
break; break;
case SPRITE_ARROWU: case DIRECTION_UP:
m_shiftOffset.x = 0; m_shiftOffset.x = 0;
m_shiftOffset.y = +2; m_shiftOffset.y = +2;
m_shiftVector.x = -1; m_shiftVector.x = -1;
m_shiftVector.y = -1; m_shiftVector.y = -1;
if (vectorFactor > 1)
++vectorFactor;
break; break;
case SPRITE_ARROWD: case DIRECTION_DOWN:
m_shiftOffset.x = 0; m_shiftOffset.x = 0;
m_shiftOffset.y = -2; m_shiftOffset.y = -2;
m_shiftVector.x = +1; m_shiftVector.x = +1;
m_shiftVector.y = +1; m_shiftVector.y = +1;
if (vectorFactor > 1)
++vectorFactor;
break; break;
case SPRITE_ARROWUL: default:
m_shiftOffset.x = +1; if (dir == (DIRECTION_UP | DIRECTION_LEFT))
m_shiftOffset.y = +1; {
m_shiftVector.x = -1; m_shiftOffset.x = +1;
m_shiftVector.y = 0; m_shiftOffset.y = +1;
break; m_shiftVector.x = -1;
m_shiftVector.y = 0;
case SPRITE_ARROWUR: if (vectorFactor > 1)
m_shiftOffset.x = -1; ++vectorFactor;
m_shiftOffset.y = +1; }
m_shiftVector.x = 0; else if (dir == (DIRECTION_UP | DIRECTION_RIGHT))
m_shiftVector.y = -1; {
break; m_shiftOffset.x = -1;
m_shiftOffset.y = +1;
case SPRITE_ARROWDL: m_shiftVector.x = 0;
m_shiftOffset.x = +1; m_shiftVector.y = -1;
m_shiftOffset.y = -1; if (vectorFactor > 1)
m_shiftVector.x = 0; ++vectorFactor;
m_shiftVector.y = +1; }
break; else if (dir == (DIRECTION_DOWN | DIRECTION_LEFT))
{
case SPRITE_ARROWDR: m_shiftOffset.x = +1;
m_shiftOffset.x = -1; m_shiftOffset.y = -1;
m_shiftOffset.y = -1; m_shiftVector.x = 0;
m_shiftVector.x = +1; m_shiftVector.y = +1;
m_shiftVector.y = 0; if (vectorFactor > 1)
++vectorFactor;
}
else if (dir == (DIRECTION_DOWN | DIRECTION_RIGHT))
{
m_shiftOffset.x = -1;
m_shiftOffset.y = -1;
m_shiftVector.x = +1;
m_shiftVector.y = 0;
if (vectorFactor > 1)
++vectorFactor;
}
else
{
m_shiftOffset.x = 0;
m_shiftOffset.y = 0;
m_shiftVector.x = 0;
m_shiftVector.y = 0;
}
break; break;
} }
m_shiftOffset.x *= xMoveFactor;
m_shiftOffset.y *= yMoveFactor;
m_shiftVector.x *= vectorFactor;
m_shiftVector.y *= vectorFactor;
if (m_shiftVector.x != 0 || m_shiftVector.y != 0) if (m_shiftVector.x != 0 || m_shiftVector.y != 0)
m_shiftPhase = max; m_shiftPhase = max;
} }
@ -3577,8 +3655,9 @@ CEvent::DecorAutoShift ()
if (m_shiftPhase == 0) // last phase ? if (m_shiftPhase == 0) // last phase ?
{ {
offset.x = 0; this->shiftDirection = 0;
offset.y = 0; offset.x = 0;
offset.y = 0;
m_pDecor->SetShiftOffset (offset); m_pDecor->SetShiftOffset (offset);
DecorShift (m_shiftVector.x, m_shiftVector.y); DecorShift (m_shiftVector.x, m_shiftVector.y);
} }
@ -5347,23 +5426,28 @@ CEvent::TreatEventBase (const SDL_Event & event)
case SDLK_UP: case SDLK_UP:
case SDLK_DOWN: case SDLK_DOWN:
{ {
bool left, right, up, down;
const Uint8 * state = SDL_GetKeyboardState (nullptr); const Uint8 * state = SDL_GetKeyboardState (nullptr);
if (
event.key.keysym.sym == SDLK_LEFT || this->shiftDirection = 0;
(!m_bDemoRec && state[SDL_SCANCODE_LEFT]))
DecorShift (-2, 2); left = event.key.keysym.sym == SDLK_LEFT ||
if ( (!m_bDemoRec && state[SDL_SCANCODE_LEFT]);
event.key.keysym.sym == SDLK_RIGHT || right = event.key.keysym.sym == SDLK_RIGHT ||
(!m_bDemoRec && state[SDL_SCANCODE_RIGHT])) (!m_bDemoRec && state[SDL_SCANCODE_RIGHT]);
DecorShift (2, -2); up = event.key.keysym.sym == SDLK_UP ||
if ( (!m_bDemoRec && state[SDL_SCANCODE_UP]);
event.key.keysym.sym == SDLK_UP || down = event.key.keysym.sym == SDLK_DOWN ||
(!m_bDemoRec && state[SDL_SCANCODE_UP])) (!m_bDemoRec && state[SDL_SCANCODE_DOWN]);
DecorShift (-3, -3);
if ( if (left)
event.key.keysym.sym == SDLK_DOWN || this->shiftDirection |= DIRECTION_LEFT;
(!m_bDemoRec && state[SDL_SCANCODE_DOWN])) if (right)
DecorShift (3, 3); this->shiftDirection |= DIRECTION_RIGHT;
if (up)
this->shiftDirection |= DIRECTION_UP;
if (down)
this->shiftDirection |= DIRECTION_DOWN;
return true; return true;
} }
case SDLK_HOME: case SDLK_HOME:

View File

@ -268,6 +268,7 @@ protected:
Sint32 m_introTime; Sint32 m_introTime;
Sint32 m_updateBlinking; Sint32 m_updateBlinking;
std::string m_updateVersion; std::string m_updateVersion;
Uint32 shiftDirection;
}; };
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////