Commit 7cb59dcc authored by Gerhard Stein's avatar Gerhard Stein

Camera is now an object of the holder(less pointers and less) and we are able...

Camera is now an object of the holder(less pointers and less) and we are able to freeze it easily when needed. In this case the cliff climbing make the camera freeze. We will use that feature for other things later.
parent d6deb4ce
......@@ -7,9 +7,6 @@
* This camera class is used for the scrolling during the "gameplay".
* The old values of that used that class are now a structure part of CVideoDriver
* This class will be another object that will following the player
* It has the feature to attach to any object in the game scenario and follow it.
* It also can detached and moved manually. That might be used for
* the active Level viewer feature.
*/
......@@ -19,35 +16,14 @@
#include "sdl/CInput.h"
#include "spritedefines.h"
CCamera::CCamera(CMap *pmap, Uint32 x, Uint32 y):
CCamera::CCamera(CMap *pmap, Uint32 x, Uint32 y, CObject &attacher) :
CObject(pmap, x, y, OBJ_NONE),
mp_AttachedObject(NULL)
m_AttachedObject(attacher)
{
g_pLogFile->ftextOut("Starting the camera system...<br>");
sprite = BLANKSPRITE;
solid = false;
}
/**
* This function will attach the camera to the object and scroll
* automatically with it
*/
void CCamera::attachToObject(CObject &attacher)
{ mp_AttachedObject = &attacher; }
/**
* This function will dettach the camera from a object.
* If this happens, the camera can be scrolled manually.
*/
bool CCamera::detach()
{
if(!mp_AttachedObject)
return false;
else
{
mp_AttachedObject = NULL;
return true;
}
m_attached = true;
m_freeze = false;
}
/**
......@@ -57,7 +33,10 @@ bool CCamera::detach()
*/
void CCamera::process()
{
if(mp_AttachedObject == NULL)
if(m_freeze)
return;
if(!m_attached)
{ // This means, that there is no attached object. Let the camera scroll freely!
size_t movespeed = 100;
......@@ -72,15 +51,15 @@ void CCamera::process()
}
else
{
if(mp_AttachedObject->getXPosition() > getXPosition())
moveRight(mp_AttachedObject->getXPosition() - getXPosition() );
else if(mp_AttachedObject->getXPosition() < getXPosition())
moveLeft(getXPosition() - mp_AttachedObject->getXPosition());
if(m_AttachedObject.getXPosition() > getXPosition())
moveRight(m_AttachedObject.getXPosition() - getXPosition() );
else if(m_AttachedObject.getXPosition() < getXPosition())
moveLeft(getXPosition() - m_AttachedObject.getXPosition());
if(mp_AttachedObject->getYPosition() > getYPosition())
moveDown(mp_AttachedObject->getYPosition() - getYPosition());
else if(mp_AttachedObject->getYPosition() < getYPosition())
moveUp(getYPosition() - mp_AttachedObject->getYPosition());
if(m_AttachedObject.getYPosition() > getYPosition())
moveDown(m_AttachedObject.getYPosition() - getYPosition());
else if(m_AttachedObject.getYPosition() < getYPosition())
moveUp(getYPosition() - m_AttachedObject.getYPosition());
}
......@@ -140,41 +119,8 @@ void CCamera::process()
mp_Map->scrollDown();
while(scroll_y > mp_Map->m_maxscrolly)
mp_Map->scrollUp();
}
/**
* Move the camera left also checking the bounds
*/
/*void CCamera::moveLeft()
{
mp_Map->scrollLeft();
}*/
/**
* Move the camera right also checking the bounds
*/
/*void CCamera::moveRight()
{
mp_Map->scrollRight();
}*/
/**
* Move the camera up also checking the bounds
*/
/*void CCamera::moveUp()
{
mp_Map->scrollUp();
}*/
/**
* Move the camera down also checking the bounds
*/
/*void CCamera::moveDown()
{
mp_Map->scrollDown();
}*/
CCamera::~CCamera()
{
// TODO Auto-generated destructor stub
......
......@@ -12,7 +12,7 @@
* the active Level viewer feature.
*/
#include "../common/CObject.h"
#include "common/CObject.h"
#ifndef CCAMERA_H_
#define CCAMERA_H_
......@@ -20,22 +20,20 @@
class CCamera : public CObject
{
public:
CCamera(CMap *pmap, Uint32 x, Uint32 y);
CCamera(CMap *pmap, Uint32 x, Uint32 y, CObject &attacher);
void attachToObject(CObject &attacher);
bool detach();
void process();
/*void moveLeft();
void moveRight();
void moveUp();
void moveDown();*/
virtual ~CCamera();
bool m_attached;
bool m_freeze;
private:
CObject *mp_AttachedObject;
CObject &m_AttachedObject;
};
#endif /* CCAMERA_H_ */
......@@ -341,21 +341,12 @@ void CMapLoaderGalaxy::addFoe(CMap &Map, word foe, size_t x, size_t y)
case 2:
// This is the player on map
p_newfoe = new galaxy::CPlayerLevel(&Map, x, y, m_ObjectPtr, (foe==1) ? RIGHT : LEFT, m_Inventory);
// Add the Camera into the game scene and attach it to this player
camera = new CCamera(&Map,x,y);
camera->attachToObject(*p_newfoe);
m_ObjectPtr.push_back(camera);
break;
case 3:
// This is the player on map
p_newfoe = new galaxy::CPlayerWM(&Map, x, y, m_ObjectPtr, m_Inventory);
// Add the Camera into the game scene and attach it to this player
camera = new CCamera(&Map,x,y);
camera->attachToObject(*p_newfoe);
m_ObjectPtr.push_back(camera);
p_newfoe = new galaxy::CPlayerWM(&Map, x, y, m_ObjectPtr, m_Inventory);
break;
case 33:
......
......@@ -35,7 +35,8 @@ m_animation(0),
m_animation_time(1),
m_animation_ticker(0),
m_ObjectPtrs(ObjectPtrs),
m_cliff_hanging(false)
m_cliff_hanging(false),
m_camera(pmap,x,y,*this)
{
m_index = 0;
m_timer = 0;
......@@ -113,6 +114,8 @@ void CPlayerLevel::process()
if( !getActionNumber(A_KEEN_POGO) )
xinertia = 0;
m_camera.process();
}
void CPlayerLevel::processInput()
......@@ -286,10 +289,8 @@ void CPlayerLevel::processFiring()
if(m_Inventory.m_bullets > 0)
m_Inventory.m_bullets--;
}
}
if( m_playcontrol[PA_FIRE] == 0 )
m_pfiring = false;
......@@ -312,6 +313,7 @@ void CPlayerLevel::processMoving()
{
m_cliff_hanging = false;
setAction(A_KEEN_STAND);
m_camera.m_freeze = false;
setActionSprite();
calcBouncingBoxes();
moveDown(16*dy);
......@@ -322,6 +324,7 @@ void CPlayerLevel::processMoving()
if(m_playcontrol[PA_Y] < 0)
{
setAction(A_KEEN_CLIMB);
m_camera.m_freeze = true;
}
else if(m_playcontrol[PA_Y] > 0)
{
......
......@@ -11,6 +11,7 @@
#include "common/CObject.h"
#include "common/Playerdefines.h"
#include "engine/CEvent.h"
#include "engine/CCamera.h"
#include "engine/galaxy/CInventory.h"
namespace galaxy {
......@@ -86,6 +87,7 @@ private:
int m_timer;
bool m_pogotoggle;
CCamera m_camera;
};
}
......
......@@ -26,7 +26,8 @@ m_looking_dir(LEFT),
m_animation(0),
m_animation_time(1),
m_animation_ticker(0),
m_ObjectPtrs(ObjectPtrs)
m_ObjectPtrs(ObjectPtrs),
m_camera(pmap,x,y,*this)
{
sprite = m_basesprite;
performCollisions();
......@@ -54,6 +55,8 @@ void CPlayerWM::process()
finishLevel(ev->levelObject);
EventContainer.pop_Event();
}
m_camera.process();
}
/*
......
......@@ -9,6 +9,7 @@
#define CPLAYERWM_H_
#include "common/CObject.h"
#include "engine/CCamera.h"
#include "engine/CEvent.h"
#include "engine/galaxy/CInventory.h"
......@@ -40,7 +41,7 @@ private:
Uint8 m_animation_time;
Uint8 m_animation_ticker;
std::vector<CObject*>& m_ObjectPtrs;
CCamera m_camera;
};
}
......
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