Commit 5c0236c4 authored by Gerhard Stein's avatar Gerhard Stein

updated level-manager in Keen Galaxy. now it works!

parent 2d0c1817
......@@ -29,6 +29,7 @@ m_Tilemaps(g_pGfxEngine->getTileMaps()),
m_animtiletimer(0),
m_Background(false)
{
m_Level = 0;
resetScrolls();
memset(m_objectlayer, 0, sizeof(m_objectlayer));
}
......@@ -40,6 +41,12 @@ void CMap::setScrollSurface( SDL_Surface *surface )
{ mp_scrollsurface = surface; }
void CMap::setLevel(Uint16 Level)
{ m_Level = Level; }
Uint16 CMap::getLevel()
{ return m_Level; }
/**
* \brief Create an empty data plane used for the map data
* \param blocksize size in bytes of the datablock that has to be created
......
......@@ -32,6 +32,9 @@ public:
void setTileMap( CTilemap &Tilemap );
void setScrollSurface( SDL_Surface *surface );
void setLevel(Uint16 Level);
Uint16 getLevel();
bool createEmptyDataPlane(size_t plane, size_t blocksize);
bool gotoPos( int x, int y );
......@@ -112,6 +115,7 @@ private:
CPlane m_Plane[3];
bool m_Background; // This variable holds, whether we have a background to draw or not.
Uint16 m_Level;
};
#endif /* CMAP_H_ */
......@@ -54,7 +54,6 @@ void CLevelPlay::process()
{
(*obj)->draw();
}
}
CLevelPlay::~CLevelPlay() {
......
......@@ -128,6 +128,7 @@ bool CMapLoaderGalaxy::loadMap(CMap &Map, Uint8 level)
// Get the MAPHEAD Location from within the Exe File
Map.gotoPos(0,0);
Map.setLevel(level);
size_t offset = getMapheadOffset();
byte *Maphead = m_ExeFile.getRawData() + offset;
......@@ -257,9 +258,9 @@ void CMapLoaderGalaxy::spawnFoes(CMap &Map)
word width = Map.m_width;
word height = Map.m_height;
std::ofstream file("foe.txt");
/*std::ofstream file("foe.txt");
data_ptr = start_data;
/*for(size_t y=0 ; y<height ; y++)
for(size_t y=0 ; y<height ; y++)
{
for(size_t x=0 ; x<width ; x++)
{
......@@ -271,6 +272,13 @@ void CMapLoaderGalaxy::spawnFoes(CMap &Map)
}
file.close();*/
// If objects are in the buffer clean them up
while(!m_ObjectPtr.empty())
{
delete m_ObjectPtr.back();
m_ObjectPtr.pop_back();
}
// he we go to the adding objects
data_ptr = start_data;
for(size_t y=0 ; y<height ; y++)
......@@ -297,9 +305,10 @@ void CMapLoaderGalaxy::addFoe(CMap &Map, word foe, size_t x, size_t y)
switch(foe)
{
case 1:
case 2:
// This is the player on map
p_newfoe = new galaxy::CPlayerLevel(&Map, x, y, m_ObjectPtr);
p_newfoe = new galaxy::CPlayerLevel(&Map, x, y, m_ObjectPtr, (foe==1) ? RIGHT : LEFT );
// Add the Camera into the game scene and attach it to this player
camera = new CCamera(&Map,x,y);
......
......@@ -93,14 +93,22 @@ void CPlayGameGalaxy::process()
Uint16 Data;
EventContainer.ReadData(Data);
EventContainer.pop_Event();
m_WorldMap.setActive(false);
// Start a new level!
m_LevelPlay.loadLevel(Data-0xC000);
m_LevelPlay.setActive(true);
//EventContainer.add(EXIT_LEVEL, Data);
if(Data > 0xC000)
{
m_WorldMap.setActive(false);
m_LevelPlay.loadLevel(Data-0xC000);
m_LevelPlay.setActive(true);
}
}
else if( EventContainer.occurredEvent( EXIT_LEVEL ) )
{
Uint16 Data;
m_LevelPlay.setActive(false);
m_WorldMap.setActive(true);
}
}
......
......@@ -22,7 +22,16 @@ bool CWorldMap::isActive()
{ return m_active; }
void CWorldMap::setActive(bool value)
{ m_active = value; }
{
m_active = value;
if(m_active)
{
m_Map.drawAll();
m_Map.setScrollSurface(g_pVideoDriver->getScrollSurface());
// Set Scrollbuffer
g_pVideoDriver->setScrollBuffer(&m_Map.m_scrollx_buf, &m_Map.m_scrolly_buf);
}
}
void CWorldMap::init()
{
......
......@@ -19,18 +19,19 @@ const Uint16 STANDBASEFRAMERIGHT = 6;
const Uint16 FALLINGFRAMELEFT = 19;
const Uint16 FALLINGFRAMERIGHT = 11;
const Uint16 MAX_JUMPHEIGHT = (10<<CSF);
CPlayerLevel::CPlayerLevel(CMap *pmap, Uint32 x, Uint32 y,
std::vector<CObject*>& ObjectPtrs) :
CObject(pmap, x, y, OBJ_PLAYER),
m_basesprite(STANDBASEFRAMELEFT),
m_looking_dir(LEFT),
std::vector<CObject*>& ObjectPtrs, direction_t facedir) :
CObject(pmap, x, y, OBJ_NONE),
m_basesprite( (facedir==LEFT) ? STANDBASEFRAMELEFT : STANDBASEFRAMERIGHT ),
m_looking_dir(facedir),
m_animation(0),
m_animation_time(1),
m_animation_ticker(0),
m_ObjectPtrs(ObjectPtrs)
{
jumping = false;
// TODO Auto-generated constructor stub
state = STANDING;
sprite = m_basesprite;
CSprite &rSprite = g_pGfxEngine->getSprite(sprite);
......@@ -51,11 +52,13 @@ void CPlayerLevel::process()
performCollisionsSameBox();
processWalking();
processMoving();
processJumping();
processFalling();
processJumping();
processExiting();
}
void CPlayerLevel::processFalling()
......@@ -65,11 +68,11 @@ void CPlayerLevel::processFalling()
// If yinertia is high, set falling to true
if( yinertia > 64 )
{
state = FALLING;
falling = true;
jumping = false;
}
if( !blockedd && (falling || jumping) )
if( !blockedd && (falling || state == JUMPING) )
{
if(m_looking_dir == LEFT)
m_basesprite = FALLINGFRAMELEFT;
......@@ -82,9 +85,14 @@ void CPlayerLevel::processFalling()
if( yinertia > 32 )
sprite++;
}
if( blockedd )
{
state = STANDING;
}
}
void CPlayerLevel::processWalking()
void CPlayerLevel::processMoving()
{
size_t movespeed = 50;
bool walking=false;
......@@ -93,27 +101,29 @@ void CPlayerLevel::processWalking()
if(g_pInput->getHoldedCommand(IC_LEFT) && !blockedl)
{
moveLeft(movespeed);
walking = true;
if(state == STANDING)
state=WALKING;
m_looking_dir = LEFT;
}
else if(g_pInput->getHoldedCommand(IC_RIGHT) && !blockedr)
{
moveRight(movespeed);
walking = true;
if(state == STANDING)
state=WALKING;
m_looking_dir = RIGHT;
}
performWalkingAnimation(walking);
if( state==WALKING or state==STANDING )
performWalkingAnimation(walking);
}
void CPlayerLevel::processJumping()
{
if(g_pInput->getPressedCommand(IC_JUMP) && !falling && !jumping)
if(g_pInput->getPressedCommand(IC_JUMP) /*&& (state==STANDING or state==WALKING)*/ )
{
yinertia = -150;
jumping = true;
yinertia = -128;
state = JUMPING;
}
}
void CPlayerLevel::performWalkingAnimation(bool walking)
......@@ -125,13 +135,24 @@ void CPlayerLevel::performWalkingAnimation(bool walking)
sprite = m_basesprite;
if(walking)
if( state == WALKING )
{
m_animation_time = 5;
sprite += (m_animation%4)+1;
}
}
// Processes the exiting of the player. Here all cases are held
void CPlayerLevel::processExiting()
{
CEventContainer& EventContainer = g_pBehaviorEngine->m_EventList;
Uint32 x = getXMidPos();
if( ((mp_Map->m_width-2)<<CSF) < x || (2<<CSF) > x )
{
EventContainer.add( EXIT_LEVEL, mp_Map->getLevel() );
}
}
CPlayerLevel::~CPlayerLevel() {
// TODO Auto-generated destructor stub
......
......@@ -16,14 +16,15 @@ namespace galaxy {
class CPlayerLevel : public CObject {
public:
CPlayerLevel(CMap *pmap, Uint32 x, Uint32 y,
std::vector<CObject*>& ObjectPtrs);
std::vector<CObject*>& ObjectPtrs, direction_t facedir);
void process();
void processFalling();
void processWalking();
void processMoving();
void processJumping();
void performWalkingAnimation(bool walking);
void processExiting();
virtual ~CPlayerLevel();
......@@ -36,7 +37,9 @@ private:
Uint8 m_animation_ticker;
std::vector<CObject*>& m_ObjectPtrs;
bool jumping;
enum {
STANDING, WALKING, JUMPING, FALLING
} state;
};
......
......@@ -144,7 +144,7 @@ void CPlayerWM::finishLevel(Uint16 object)
{
// if a door or other blocker was found remove it
int x, y;
Uint16 door = (object - 0xC000) + 0xD000;
Uint16 door = object + 0xD000;
while(mp_Map->findTile(door, &x, &y, 2))
{
// Open blocks in case there are
......@@ -153,7 +153,7 @@ void CPlayerWM::finishLevel(Uint16 object)
mp_Map->redrawAt( x, y);
}
Uint16 flag_dest = (object - 0xC000) + 0xF000;
Uint16 flag_dest = object + 0xF000;
if(mp_Map->findTile(flag_dest, &x, &y, 2))
{
// spawn the flag
......
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