Added code to center the camera when not moving.
This commit is contained in:
parent
4a9c99f4bc
commit
8e753d9525
|
@ -315,3 +315,4 @@ const int screenWidth = 800;
|
||||||
const int screenHeight = 600;
|
const int screenHeight = 600;
|
||||||
const int xViewBorder = 100;
|
const int xViewBorder = 100;
|
||||||
const int yViewBorder = 100;
|
const int yViewBorder = 100;
|
||||||
|
const float cameraMaxSpeed = 3.;
|
||||||
|
|
106
src/player.cpp
106
src/player.cpp
|
@ -80,6 +80,10 @@ void doPlayer()
|
||||||
engine.smy = 0;
|
engine.smy = 0;
|
||||||
|
|
||||||
int shapeToUse;
|
int shapeToUse;
|
||||||
|
float cd;
|
||||||
|
float cc;
|
||||||
|
bool xmoved = false;
|
||||||
|
bool ymoved = false;
|
||||||
|
|
||||||
if (player.shield > -100)
|
if (player.shield > -100)
|
||||||
{
|
{
|
||||||
|
@ -150,12 +154,14 @@ void doPlayer()
|
||||||
{
|
{
|
||||||
player.y -= player.speed;
|
player.y -= player.speed;
|
||||||
engine.ssy += 0.1;
|
engine.ssy += 0.1;
|
||||||
|
ymoved = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (engine.keyState[KEY_DOWN])
|
if (engine.keyState[KEY_DOWN])
|
||||||
{
|
{
|
||||||
player.y += player.speed;
|
player.y += player.speed;
|
||||||
engine.ssy -= 0.1;
|
engine.ssy -= 0.1;
|
||||||
|
ymoved = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (engine.keyState[KEY_LEFT])
|
if (engine.keyState[KEY_LEFT])
|
||||||
|
@ -163,6 +169,7 @@ void doPlayer()
|
||||||
player.x -= player.speed;
|
player.x -= player.speed;
|
||||||
engine.ssx += 0.1;
|
engine.ssx += 0.1;
|
||||||
player.face = 1;
|
player.face = 1;
|
||||||
|
xmoved = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (engine.keyState[KEY_RIGHT])
|
if (engine.keyState[KEY_RIGHT])
|
||||||
|
@ -170,6 +177,7 @@ void doPlayer()
|
||||||
player.x += player.speed;
|
player.x += player.speed;
|
||||||
engine.ssx -= 0.1;
|
engine.ssx -= 0.1;
|
||||||
player.face = 0;
|
player.face = 0;
|
||||||
|
xmoved = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (engine.keyState[KEY_ESCAPE])
|
if (engine.keyState[KEY_ESCAPE])
|
||||||
|
@ -193,25 +201,95 @@ void doPlayer()
|
||||||
|
|
||||||
if (engine.done == 0)
|
if (engine.done == 0)
|
||||||
{
|
{
|
||||||
if (player.x < xViewBorder)
|
if (xmoved)
|
||||||
{
|
{
|
||||||
engine.smx += xViewBorder - player.x;
|
if (player.x < xViewBorder)
|
||||||
player.x = xViewBorder;
|
{
|
||||||
|
engine.smx += xViewBorder - player.x;
|
||||||
|
player.x = xViewBorder;
|
||||||
|
}
|
||||||
|
else if (player.x > screen->w - xViewBorder)
|
||||||
|
{
|
||||||
|
engine.smx += (screen->w - xViewBorder) - player.x;
|
||||||
|
player.x = screen->w - xViewBorder;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if (player.x > screen->w - xViewBorder)
|
else
|
||||||
{
|
{
|
||||||
engine.smx += (screen->w - xViewBorder) - player.x;
|
cd = player.x - screen->w / 2;
|
||||||
player.x = screen->w - xViewBorder;
|
if (cd < 0)
|
||||||
|
{
|
||||||
|
cc = engine.ssx - cameraMaxSpeed;
|
||||||
|
if (cd < cc)
|
||||||
|
{
|
||||||
|
player.x -= cc;
|
||||||
|
engine.smx -= cc;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
player.x -= cd;
|
||||||
|
engine.smx -= cd;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (cd > 0)
|
||||||
|
{
|
||||||
|
cc = cameraMaxSpeed + engine.ssx;
|
||||||
|
if (cd > cc)
|
||||||
|
{
|
||||||
|
player.x -= cc;
|
||||||
|
engine.smx -= cc;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
player.x -= cd;
|
||||||
|
engine.smx -= cd;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (player.y < yViewBorder)
|
if (ymoved)
|
||||||
{
|
{
|
||||||
engine.smy += yViewBorder - player.y;
|
if (player.y < yViewBorder)
|
||||||
player.y = yViewBorder;
|
{
|
||||||
|
engine.smy += yViewBorder - player.y;
|
||||||
|
player.y = yViewBorder;
|
||||||
|
}
|
||||||
|
else if (player.y > screen->h - yViewBorder)
|
||||||
|
{
|
||||||
|
engine.smy += (screen->h - yViewBorder) - player.y;
|
||||||
|
player.y = screen->h - yViewBorder;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if (player.y > screen->h - yViewBorder)
|
else
|
||||||
{
|
{
|
||||||
engine.smy += (screen->h - yViewBorder) - player.y;
|
cd = player.y - screen->h / 2;
|
||||||
player.y = screen->h - yViewBorder;
|
if (cd < 0)
|
||||||
|
{
|
||||||
|
cc = engine.ssy - cameraMaxSpeed;
|
||||||
|
if (cd < cc)
|
||||||
|
{
|
||||||
|
player.y -= cc;
|
||||||
|
engine.smy -= cc;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
player.y -= cd;
|
||||||
|
engine.smy -= cd;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (cd > 0)
|
||||||
|
{
|
||||||
|
cc = cameraMaxSpeed + engine.ssy;
|
||||||
|
if (cd > cc)
|
||||||
|
{
|
||||||
|
player.y -= cc;
|
||||||
|
engine.smy -= cc;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
player.y -= cd;
|
||||||
|
engine.smy -= cd;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -257,8 +335,8 @@ void doPlayer()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
limitFloat(&engine.ssx, -3, 3);
|
limitFloat(&engine.ssx, -cameraMaxSpeed, cameraMaxSpeed);
|
||||||
limitFloat(&engine.ssy, -3, 3);
|
limitFloat(&engine.ssy, -cameraMaxSpeed, cameraMaxSpeed);
|
||||||
|
|
||||||
// Specific for the mission were you have to chase the Executive Transport
|
// Specific for the mission were you have to chase the Executive Transport
|
||||||
if ((currentGame.area == 18) && (enemy[WC_BOSS].shield > 0) && (player.shield > 0))
|
if ((currentGame.area == 18) && (enemy[WC_BOSS].shield > 0) && (player.shield > 0))
|
||||||
|
|
Loading…
Reference in New Issue