Commit 1f79324c authored by Gerstrong's avatar Gerstrong

Created base class for the Mapplay management.

parent f66d1f28
......@@ -67,6 +67,9 @@ void CInventory::drawHUD()
void CInventory::drawStatus()
{
if(g_pGfxEngine->applyingEffects())
return;
mp_StatusScreen->draw();
}
......
......@@ -12,21 +12,15 @@
#include "sdl/music/CMusic.h"
#include "CLogFile.h"
#include "CMapPlayGalaxy.h"
namespace galaxy {
CLevelPlay::CLevelPlay(CExeFile &ExeFile,
CInventory &Inventory) :
m_active(false),
m_ExeFile(ExeFile),
m_Inventory(Inventory),
mp_option(g_pBehaviorEngine->m_option)
CMapPlayGalaxy(ExeFile, Inventory)
{ }
bool CLevelPlay::isActive()
{ return m_active; }
void CLevelPlay::setActive(bool value)
{ m_active = value; }
bool CLevelPlay::loadLevel(const Uint16 level)
{
......@@ -47,73 +41,4 @@ bool CLevelPlay::loadLevel(const Uint16 level)
return true;
}
/**
* return the name of the opened level
*/
std::string CLevelPlay::getLevelName()
{
return m_Map.getLevelName();
}
void CLevelPlay::process()
{
// Animate the tiles of the map
m_Map.animateAllTiles();
for(size_t i=0 ; i<m_ObjectPtr.size() ; i++)
{
CObject* p_Object = m_ObjectPtr[i];
if(p_Object->exists)
{
p_Object->process();
// Check collision between objects
/*for( std::vector<CObject*>::iterator theOtherObj=m_ObjectPtr.begin() ;
theOtherObj != m_ObjectPtr.end() ; theOtherObj++ )*/
for(size_t j=0 ; j<m_ObjectPtr.size() ; j++)
{
CObject *theOtherObj = m_ObjectPtr[j];
if( theOtherObj != p_Object )
p_Object->getTouchedBy(*theOtherObj);
}
}
}
g_pVideoDriver->blitScrollSurface();
std::vector<CObject*>::iterator obj;
// Draw all the sprites but no player
for( obj=m_ObjectPtr.begin() ;
obj!=m_ObjectPtr.end() ; obj++ )
{
if((*obj)->honorPriority && (*obj)->m_type != OBJ_PLAYER)
(*obj)->draw();
}
// Now only draw the player sprite. So everything expect maked tiles are below his layer
for( obj=m_ObjectPtr.begin() ;
obj!=m_ObjectPtr.end() ; obj++ )
{
if((*obj)->m_type == OBJ_PLAYER)
(*obj)->draw();
}
// Draw masked tiles here!
m_Map.drawForegroundTiles();
for( obj=m_ObjectPtr.begin() ;
obj!=m_ObjectPtr.end() ; obj++ )
{
if(!(*obj)->honorPriority)
(*obj)->draw();
}
if(mp_option[OPT_HUD].value )
m_Inventory.drawHUD();
}
}
......@@ -10,33 +10,15 @@
#ifndef CLEVELPLAY_H_
#define CLEVELPLAY_H_
#include "common/CObject.h"
#include "fileio/CExeFile.h"
#include "engine/galaxy/CInventory.h"
#include "common/CBehaviorEngine.h"
#include <vector>
#include "CMapPlayGalaxy.h"
namespace galaxy {
class CLevelPlay {
class CLevelPlay : public CMapPlayGalaxy {
public:
CLevelPlay(CExeFile &ExeFile, CInventory &Inventory);
bool isActive();
void setActive(bool value);
bool loadLevel(const Uint16 level);
std::string getLevelName();
void process();
private:
std::vector<CObject*> m_ObjectPtr;
bool m_active;
CMap m_Map;
CExeFile &m_ExeFile;
CInventory &m_Inventory;
stOption *mp_option;
};
}
......
/*
* CMapPlayGalaxy.cpp
*
* Created on: 25.03.2011
* Author: gerstrong
*/
#include "CMapPlayGalaxy.h"
CMapPlayGalaxy::CMapPlayGalaxy(CExeFile &ExeFile, CInventory &Inventory) :
m_active(false),
m_ExeFile(ExeFile),
m_Inventory(Inventory),
mp_option(g_pBehaviorEngine->m_option)
{}
bool CMapPlayGalaxy::isActive()
{ return m_active; }
/*void CMapPlayGalaxy::setActive(const bool value)
{ m_active = value; }*/
void CMapPlayGalaxy::setActive(bool value)
{
m_active = value;
if(m_active)
{
m_Map.drawAll();
// Set Scrollbuffer
g_pVideoDriver->setScrollBuffer(&m_Map.m_scrollx_buf, &m_Map.m_scrolly_buf);
}
}
/**
* return the name of the opened level
*/
std::string CMapPlayGalaxy::getLevelName()
{
return m_Map.getLevelName();
}
void CMapPlayGalaxy::process()
{
// Animate the tiles of the map
m_Map.animateAllTiles();
for(size_t i=0 ; i<m_ObjectPtr.size() ; i++)
{
CObject* p_Object = m_ObjectPtr[i];
if(p_Object->exists)
{
p_Object->process();
// Check collision between objects
/*for( std::vector<CObject*>::iterator theOtherObj=m_ObjectPtr.begin() ;
theOtherObj != m_ObjectPtr.end() ; theOtherObj++ )*/
for(size_t j=0 ; j<m_ObjectPtr.size() ; j++)
{
CObject *theOtherObj = m_ObjectPtr[j];
if( theOtherObj != p_Object )
p_Object->getTouchedBy(*theOtherObj);
}
}
}
g_pVideoDriver->blitScrollSurface();
std::vector<CObject*>::iterator obj;
// Draw all the sprites but no player
for( obj=m_ObjectPtr.begin() ;
obj!=m_ObjectPtr.end() ; obj++ )
{
if((*obj)->honorPriority && (*obj)->m_type != OBJ_PLAYER)
(*obj)->draw();
}
// Now only draw the player sprite. So everything expect maked tiles are below his layer
for( obj=m_ObjectPtr.begin() ;
obj!=m_ObjectPtr.end() ; obj++ )
{
if((*obj)->m_type == OBJ_PLAYER)
(*obj)->draw();
}
// Draw masked tiles here!
m_Map.drawForegroundTiles();
for( obj=m_ObjectPtr.begin() ;
obj!=m_ObjectPtr.end() ; obj++ )
{
if(!(*obj)->honorPriority)
(*obj)->draw();
}
if(mp_option[OPT_HUD].value )
m_Inventory.drawHUD();
}
CMapPlayGalaxy::~CMapPlayGalaxy()
{
while(!m_ObjectPtr.empty())
{
delete m_ObjectPtr.back();
m_ObjectPtr.pop_back();
}
}
/*
* CMapPlayGalaxy.h
*
* Created on: 25.03.2011
* Author: gerstrong
*
* This is the play base class for Commander Keen Galaxy when the player
* has started the game. It is overloaded with CLevelPlay and CWorldMap to distinguish
* the play scenes. If those classes get to small due the common stuff they might get reduced
*/
#ifndef CMAPPLAYGALAXY_H_
#define CMAPPLAYGALAXY_H_
#include "common/CObject.h"
#include "fileio/CExeFile.h"
#include "engine/galaxy/CInventory.h"
#include "common/CBehaviorEngine.h"
#include "CMapLoaderGalaxy.h"
#include "sdl/CInput.h"
#include "sdl/CVideoDriver.h"
#include "sdl/music/CMusic.h"
#include "StringUtils.h"
#include <vector>
class CMapPlayGalaxy {
public:
CMapPlayGalaxy(CExeFile &ExeFile, CInventory &Inventory);
~CMapPlayGalaxy();
bool isActive();
void setActive(const bool value);
std::string getLevelName();
void process();
protected:
std::vector<CObject*> m_ObjectPtr;
bool m_active;
CMap m_Map;
CExeFile &m_ExeFile;
CInventory &m_Inventory;
stOption *mp_option;
};
#endif /* CMAPPLAYGALAXY_H_ */
......@@ -109,21 +109,20 @@ void CPlayGameGalaxy::process()
//if(m_Page.isActive())
//m_Page.process();
// process World Map if active. At the start it's enabled
if(m_WorldMap.isActive())
m_WorldMap.process();
// process World Map if active. At the start it's enabled
if(m_LevelPlay.isActive())
m_LevelPlay.process();
// We have to show the status screen, do so...
if( m_Inventory.showStatus() )
{
m_Inventory.drawStatus();
}
else
{
// process World Map if active. At the start it's enabled
if(m_WorldMap.isActive())
m_WorldMap.process();
// process World Map if active. At the start it's enabled
if(m_LevelPlay.isActive())
m_LevelPlay.process();
}
processRendering();
}
......
......@@ -6,36 +6,14 @@
*/
#include "CWorldMap.h"
#include "CMapLoaderGalaxy.h"
#include "sdl/CInput.h"
#include "sdl/CVideoDriver.h"
#include "sdl/music/CMusic.h"
#include "StringUtils.h"
namespace galaxy {
CWorldMap::CWorldMap(CExeFile &ExeFile,
CInventory &Inventory):
m_active(false),
m_ExeFile(ExeFile),
m_Inventory(Inventory),
mp_option(g_pBehaviorEngine->m_option)
CMapPlayGalaxy(ExeFile, Inventory)
{}
bool CWorldMap::isActive()
{ return m_active; }
void CWorldMap::setActive(bool value)
{
m_active = value;
if(m_active)
{
m_Map.drawAll();
// Set Scrollbuffer
g_pVideoDriver->setScrollBuffer(&m_Map.m_scrollx_buf, &m_Map.m_scrolly_buf);
}
}
void CWorldMap::init()
{
// Load the World map level.
......@@ -46,13 +24,6 @@ void CWorldMap::init()
m_Map.drawAll();
}
/**
* return the name of the opened level
*/
std::string CWorldMap::getLevelName()
{
return m_Map.getLevelName();
}
/**
* The map is not loaded again after the game started. But we have to reload its song.
......@@ -64,42 +35,4 @@ void CWorldMap::loadAndPlayMusic()
g_pMusicPlayer->play();
}
void CWorldMap::process()
{
// Animate the tiles of the map
m_Map.animateAllTiles();
for(size_t i=0 ; i<m_ObjectPtr.size() ; i++)
{
CObject* p_Object = m_ObjectPtr[i];
p_Object->process();
}
g_pVideoDriver->blitScrollSurface();
for( std::vector<CObject*>::iterator obj=m_ObjectPtr.begin() ;
obj!=m_ObjectPtr.end() ; obj++ )
{
(*obj)->draw();
}
// Draw masked tiles here!
m_Map.drawForegroundTiles();
// Draw the inventory
if(mp_option[OPT_HUD].value)
m_Inventory.drawHUD();
}
CWorldMap::~CWorldMap() {
while(!m_ObjectPtr.empty())
{
delete m_ObjectPtr.back();
m_ObjectPtr.pop_back();
}
}
}
......@@ -10,35 +10,16 @@
#ifndef CWORLDMAP_H_
#define CWORLDMAP_H_
#include "common/CObject.h"
#include "fileio/CExeFile.h"
#include "engine/galaxy/CInventory.h"
#include "common/CBehaviorEngine.h"
#include <vector>
#include "CMapPlayGalaxy.h"
namespace galaxy {
class CWorldMap {
class CWorldMap : public CMapPlayGalaxy {
public:
CWorldMap(CExeFile &ExeFile, CInventory &Inventory);
bool isActive();
void setActive(bool value);
void init();
std::string getLevelName();
void loadAndPlayMusic();
void process();
virtual ~CWorldMap();
private:
std::vector<CObject*> m_ObjectPtr;
bool m_active;
CMap m_Map;
CExeFile &m_ExeFile;
CInventory &m_Inventory;
stOption *mp_option;
};
}
......
......@@ -29,7 +29,7 @@ void CScrollEffect::process()
src.y = mp_ScrollSurface->h-m_ScrollPos;
dest.h = m_ScrollPos;
SDL_BlitSurface( mp_OldSurface, &gameres, g_pVideoDriver->getBlitSurface(), &gameres);
//SDL_BlitSurface( mp_OldSurface, &gameres, g_pVideoDriver->getBlitSurface(), &gameres);
SDL_BlitSurface( mp_ScrollSurface, &src, g_pVideoDriver->getBlitSurface(), &dest);
......@@ -53,7 +53,7 @@ CScrollEffect::~CScrollEffect() {
SDL_Rect gameres = g_pVideoDriver->getGameResolution();
// So the final image is loaded correctly
SDL_BlitSurface( mp_OldSurface, &gameres, g_pVideoDriver->getBlitSurface(), &gameres);
//SDL_BlitSurface( mp_OldSurface, &gameres, g_pVideoDriver->getBlitSurface(), &gameres);
if(m_Speed > 0)
SDL_BlitSurface( mp_ScrollSurface, &gameres, g_pVideoDriver->getBlitSurface(), &gameres);
......
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