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 xViewBorder = 100;
|
||||
const int yViewBorder = 100;
|
||||
const float cameraMaxSpeed = 3.;
|
||||
|
|
|
@ -80,6 +80,10 @@ void doPlayer()
|
|||
engine.smy = 0;
|
||||
|
||||
int shapeToUse;
|
||||
float cd;
|
||||
float cc;
|
||||
bool xmoved = false;
|
||||
bool ymoved = false;
|
||||
|
||||
if (player.shield > -100)
|
||||
{
|
||||
|
@ -150,12 +154,14 @@ void doPlayer()
|
|||
{
|
||||
player.y -= player.speed;
|
||||
engine.ssy += 0.1;
|
||||
ymoved = true;
|
||||
}
|
||||
|
||||
if (engine.keyState[KEY_DOWN])
|
||||
{
|
||||
player.y += player.speed;
|
||||
engine.ssy -= 0.1;
|
||||
ymoved = true;
|
||||
}
|
||||
|
||||
if (engine.keyState[KEY_LEFT])
|
||||
|
@ -163,6 +169,7 @@ void doPlayer()
|
|||
player.x -= player.speed;
|
||||
engine.ssx += 0.1;
|
||||
player.face = 1;
|
||||
xmoved = true;
|
||||
}
|
||||
|
||||
if (engine.keyState[KEY_RIGHT])
|
||||
|
@ -170,6 +177,7 @@ void doPlayer()
|
|||
player.x += player.speed;
|
||||
engine.ssx -= 0.1;
|
||||
player.face = 0;
|
||||
xmoved = true;
|
||||
}
|
||||
|
||||
if (engine.keyState[KEY_ESCAPE])
|
||||
|
@ -192,6 +200,8 @@ void doPlayer()
|
|||
player.face = 0;
|
||||
|
||||
if (engine.done == 0)
|
||||
{
|
||||
if (xmoved)
|
||||
{
|
||||
if (player.x < xViewBorder)
|
||||
{
|
||||
|
@ -203,6 +213,41 @@ void doPlayer()
|
|||
engine.smx += (screen->w - xViewBorder) - player.x;
|
||||
player.x = screen->w - xViewBorder;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
cd = player.x - screen->w / 2;
|
||||
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 (ymoved)
|
||||
{
|
||||
if (player.y < yViewBorder)
|
||||
{
|
||||
engine.smy += yViewBorder - player.y;
|
||||
|
@ -214,6 +259,39 @@ void doPlayer()
|
|||
player.y = screen->h - yViewBorder;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
cd = player.y - screen->h / 2;
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (player.shield > engine.lowShield)
|
||||
addEngine(&player);
|
||||
|
@ -257,8 +335,8 @@ void doPlayer()
|
|||
}
|
||||
}
|
||||
|
||||
limitFloat(&engine.ssx, -3, 3);
|
||||
limitFloat(&engine.ssy, -3, 3);
|
||||
limitFloat(&engine.ssx, -cameraMaxSpeed, cameraMaxSpeed);
|
||||
limitFloat(&engine.ssy, -cameraMaxSpeed, cameraMaxSpeed);
|
||||
|
||||
// Specific for the mission were you have to chase the Executive Transport
|
||||
if ((currentGame.area == 18) && (enemy[WC_BOSS].shield > 0) && (player.shield > 0))
|
||||
|
|
Loading…
Reference in New Issue