Commit 07bac5c0 authored by Gerstrong's avatar Gerstrong

Now camera moves when keen looks up or down (Galaxy)

parent d1958b4f
......@@ -19,6 +19,8 @@ CCamera::CCamera(CMap *pmap, Uint32 x, Uint32 y, CObject *p_attacher) :
CObject(pmap, x, y, OBJ_NONE),
mp_AttachedObject(p_attacher)
{
m_relcam.x = 0;
m_relcam.y = 0;
sprite = BLANKSPRITE;
solid = false;
m_attached = true;
......@@ -71,27 +73,33 @@ void CCamera::process(const bool force)
m_moving = false;
const Uint32 attached_x = mp_AttachedObject->getXPosition() + m_relcam.x;
const Uint32 attached_y = mp_AttachedObject->getYPosition() + m_relcam.y;
const Uint32 local_x = getXPosition();
const Uint32 local_y = getYPosition();
// Make the camera move and tell if it's scrolling through the m_moving variable
if(mp_AttachedObject->getXPosition() > getXPosition())
if( attached_x > local_x )
{
moveRight(mp_AttachedObject->getXPosition() - getXPosition());
moveRight( attached_x - local_x );
m_moving |= true;
}
else if(mp_AttachedObject->getXPosition() < getXPosition())
else if( attached_x < local_x )
{
moveLeft(getXPosition() - mp_AttachedObject->getXPosition());
moveLeft( local_x - attached_x );
m_moving |= true;
}
if(mp_AttachedObject->getYPosition() > getYPosition())
if( attached_y > local_y )
{
moveDown(mp_AttachedObject->getYPosition() - getYPosition());
moveDown( attached_y - local_y );
m_moving |= true;
}
else if(mp_AttachedObject->getYPosition() < getYPosition())
else if( attached_y < local_y )
{
moveUp(getYPosition() - mp_AttachedObject->getYPosition());
moveUp( local_y - attached_y );
m_moving |= true;
}
}
......
......@@ -62,6 +62,14 @@ public:
bool m_freeze;
bool m_moving;
/**
*
*/
struct
{
int x, y;
}m_relcam;
private:
CObject *mp_AttachedObject;
};
......
......@@ -496,6 +496,7 @@ bool CPlayerLevel::canFallThroughTile()
const int MAX_SCROLL_VIEW = (8<<CSF);
void CPlayerLevel::processLookingUp()
{
......@@ -512,6 +513,9 @@ void CPlayerLevel::processLookingUp()
return;
}
if( m_camera.m_relcam.y > -MAX_SCROLL_VIEW )
m_camera.m_relcam.y -= (2<<STC);
if( m_playcontrol[PA_Y]<0 )
return;
......@@ -673,6 +677,10 @@ void CPlayerLevel::processPressDucking()
setAction(A_KEEN_FALL);
g_pSound->playSound( SOUND_KEEN_FALL );
}
if( m_camera.m_relcam.y < MAX_SCROLL_VIEW )
m_camera.m_relcam.y += (2<<STC);
return;
}
......@@ -1196,6 +1204,9 @@ void CPlayerLevel::processStanding()
{
/// Keen is standing
// Center the view after Keen looked up or down
centerView();
// He could walk
if( m_playcontrol[PA_X]<0 )
{
......@@ -1309,6 +1320,9 @@ void CPlayerLevel::processRunning()
{
// Most of the walking routine is done by the action script itself
// Center the view after Keen looked up or down
centerView();
// He could stand again, if player doesn't move the dpad
if( m_playcontrol[PA_X] == 0 )
{
......@@ -1506,6 +1520,24 @@ void CPlayerLevel::processFalling()
void CPlayerLevel::centerView()
{
// If keen looked up or down, this will return the camera to initial position
if( m_camera.m_relcam.y < 0 )
{
m_camera.m_relcam.y += (4<<STC);
if( m_camera.m_relcam.y > 0 )
m_camera.m_relcam.y = 0;
}
else if( m_camera.m_relcam.y > 0 )
{
m_camera.m_relcam.y -= (4<<STC);
if( m_camera.m_relcam.y < 0 )
m_camera.m_relcam.y = 0;
}
}
void CPlayerLevel::process()
......
......@@ -67,6 +67,10 @@ public:
void getAnotherLife(const int &lc_x, const int &lc_y);
/**
* \brief This will center Keens view after he looked up or down.
*/
void centerView();
/**
* \description This is the main process cycle
......@@ -244,6 +248,8 @@ private:
stCheat& m_Cheatmode;
void (CPlayerLevel::*mp_processState)();
};
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment