Commit 4d4b685d authored by Gerhard Stein's avatar Gerhard Stein

First Steps for multiplayer

parent fd70585c
......@@ -29,7 +29,6 @@ void CMainMenu::createVorticonMenu( const bool openedGamePlay )
#else
CGUIButton *button = new CGUIButton( "New Game",
new OpenMenuEvent( new CPlayersSelection<NewGamePlayersEvent>(true) ) );
#endif
mpMenuDialog->addControl( button );
......@@ -71,10 +70,15 @@ void CMainMenu::createVorticonMenu( const bool openedGamePlay )
void CMainMenu::createGalaxyMenu( const bool openedGamePlay )
{
g_pBehaviorEngine->mPlayers = 1;
#if defined (SINGLEPLAYER)
g_pBehaviorEngine->mPlayers = 1;
CGUIButton *button = new CGUIButton( "New Game",
new OpenMenuEvent(new CDifficultySelection) );
#else
CGUIButton *button = new CGUIButton( "New Game",
new OpenMenuEvent( new CPlayersSelection<NewGamePlayersEvent>(true) ) );
#endif
CGUIButton *button = new CGUIButton( "New Game",
new OpenMenuEvent(new CDifficultySelection) );
mpMenuDialog->addControl( button );
......
......@@ -46,16 +46,8 @@ CBaseMenu( CRect<float>(0.25f, 0.24f, 0.5f, 0.32f) )
mpMenuDialog->addControl( new CGUIButton( "Controls",
new OpenMenuEvent( new CControlsettings(1) ) ) );
#else
if(g_pBehaviorEngine->getEngine() == ENGINE_GALAXY)
{
mpMenuDialog->addControl( new CGUIButton( "Controls",
new OpenMenuEvent( new CControlsettings(1) ) ) );
}
else if(g_pBehaviorEngine->getEngine() == ENGINE_VORTICON)
{
mpMenuDialog->addControl(new CGUIButton( "Controls",
new OpenMenuEvent( new CPlayersSelection<OpenControlMenuEvent>() ) ) );
}
mpMenuDialog->addControl(new CGUIButton( "Controls",
new OpenMenuEvent( new CPlayersSelection<OpenControlMenuEvent>() ) ) );
#endif
......
......@@ -34,12 +34,6 @@ void CGameMain::switchToGamePlayMode()
/*void CGameMain::init()
{}*/
void CGameMain::ponder()
{
// process any triggered Game Main related event
......
......@@ -181,14 +181,16 @@ void CMapPlayGalaxy::render()
auto obj = mObjectPtr.rbegin();
// Draw all the sprites without player
// The player sprites are drawn as last
galaxy::CPlayerBase *player = NULL;
// The player sprites are drawn at the end
galaxy::CPlayerBase* player[MAX_PLAYERS] = {nullptr, nullptr, nullptr, nullptr};
int pIt = 0;
for( ; obj!=mObjectPtr.rend() ; obj++ )
{
if( galaxy::CPlayerBase* curplayer = dynamic_cast<galaxy::CPlayerBase*>(obj->get()) )
{
player = curplayer;
player[pIt] = curplayer;
pIt++;
continue;
}
......@@ -196,9 +198,9 @@ void CMapPlayGalaxy::render()
(*obj)->draw();
}
if(player)
for(int i=0 ; i<pIt ; i++)
{
player->draw();
player[i]->draw();
}
// Draw masked tiles here!
......
......@@ -344,6 +344,8 @@ void CMapLoaderGalaxy::spawnFoes(CMap &Map)
if(!m_ObjectPtr.empty())
m_ObjectPtr.clear();
const int numPlayers = g_pBehaviorEngine->mPlayers;
// he we go to the adding objects
Map.mNumFuses = 0;
Map.mFuseInLevel = false;
......@@ -352,9 +354,28 @@ void CMapLoaderGalaxy::spawnFoes(CMap &Map)
{
for(size_t x=0 ; x<width ; x++)
{
std::shared_ptr<CGalaxySpriteObject> pNewfoe(addFoe(Map, *data_ptr++, x<<CSF, y<<CSF));
if(pNewfoe)
m_ObjectPtr.push_back(pNewfoe);
const int foeID = *data_ptr;
// Check if it is the player, because in multiplayer we spawn multiple keens
if(foeID > 2 && foeID <= 3) // World Map only
{
for(int i = 0 ; i < numPlayers ; i++)
{
std::shared_ptr<CGalaxySpriteObject> pNewfoe( addFoe(Map, foeID, x<<CSF, y<<CSF) );
if(pNewfoe)
m_ObjectPtr.push_back(pNewfoe);
}
}
else
{
std::shared_ptr<CGalaxySpriteObject> pNewfoe( addFoe(Map, foeID, x<<CSF, y<<CSF) );
if(pNewfoe)
m_ObjectPtr.push_back(pNewfoe);
}
data_ptr++;
}
}
......
......@@ -144,18 +144,22 @@ const int CPlayerBase::mEpisodeActionNumMap[3][NUM_KEEN_ACTIONS] =
//{}
};
CPlayerBase::CPlayerBase(
int CPlayerBase::numPlayers = 0;
CPlayerBase::CPlayerBase
(
CMap *pmap,
const Uint16 foeID,
Uint32 x,
Uint32 y,
direction_t facedir,
CInventory &l_Inventory,
stCheat &Cheatmode) :
stCheat &Cheatmode
) :
CGalaxySpriteObject(pmap, foeID, x, y),
m_Inventory(l_Inventory),
m_camera(pmap,x,y,this),
mPlayerNum(0),
mPlayerNum(numPlayers++),
m_Cheatmode(Cheatmode),
mp_processState(NULL)
{
......@@ -171,6 +175,11 @@ mp_processState(NULL)
m_camera.setPosition(m_Pos);
}
CPlayerBase::~CPlayerBase()
{
numPlayers--;
}
void CPlayerBase::getAnotherLife(const int lc_x, const int lc_y, const bool display, const bool alt)
{
......
......@@ -86,6 +86,8 @@ public:
CInventory &l_Inventory,
stCheat &Cheatmode);
virtual ~CPlayerBase();
/**
* Pushes the players by the given object Reference
*/
......@@ -181,6 +183,7 @@ protected:
static const int mEpisodeActionNumMap[3][NUM_KEEN_ACTIONS];
VectorD2<int> mTarget;
static int numPlayers;
};
};
......
......@@ -120,6 +120,8 @@ VectorD2<int> CPlayerWM::fetchFootDestCoord()
*/
void CPlayerWM::process()
{
processInput();
// Perform animation cycle
if(m_animation_ticker >= m_animation_time)
{
......@@ -228,9 +230,10 @@ void CPlayerWM::processWaving()
}
waveTimer++;
if( g_pInput->getHoldedCommand(IC_UP) || g_pInput->getHoldedCommand(IC_DOWN) ||
g_pInput->getHoldedCommand(IC_LEFT) || g_pInput->getHoldedCommand(IC_RIGHT) ||
g_pInput->getHoldedCommand(IC_JUMP) || waveTimer >= (TIME_TO_WAVE/4) )
if( m_playcontrol[PA_Y] != 0 || m_playcontrol[PA_X] != 0 ||
m_playcontrol[PA_JUMP] || waveTimer >= (TIME_TO_WAVE/4) )
{
mProcessPtr = &CPlayerWM::processMoving;
m_basesprite = walkBaseFrame;
......@@ -324,9 +327,10 @@ void CPlayerWM::processMoving()
verifyTeleportation();
// Normal walking
if(g_pInput->getHoldedCommand(IC_LEFT) && !bleft)
if( m_playcontrol[PA_X]<0 && !bleft)
{
if(!g_pInput->getHoldedCommand(IC_UP) && !g_pInput->getHoldedCommand(IC_DOWN))
if( m_playcontrol[PA_Y] == 0 )
yDirection = 0;
moveLeft(movespeed);
......@@ -334,9 +338,9 @@ void CPlayerWM::processMoving()
xDirection = LEFT;
waveTimer = 0;
}
else if(g_pInput->getHoldedCommand(IC_RIGHT) && !bright)
{
if(!g_pInput->getHoldedCommand(IC_UP) && !g_pInput->getHoldedCommand(IC_DOWN))
else if( m_playcontrol[PA_X]>0 && !bright)
{
if(m_playcontrol[PA_Y]==0)
yDirection = 0;
moveRight(movespeed);
......@@ -344,83 +348,83 @@ void CPlayerWM::processMoving()
xDirection = RIGHT;
waveTimer = 0;
}
if(g_pInput->getHoldedCommand(IC_UP) && !bup)
if(m_playcontrol[PA_Y]<0 && !bup)
{
if(!g_pInput->getHoldedCommand(IC_LEFT) && !g_pInput->getHoldedCommand(IC_RIGHT))
xDirection = 0;
moveUp(movespeed);
walking = true;
yDirection = UP;
waveTimer = 0;
if(m_playcontrol[PA_X]==0)
xDirection = 0;
moveUp(movespeed);
walking = true;
yDirection = UP;
waveTimer = 0;
}
else if(g_pInput->getHoldedCommand(IC_DOWN) && !bdown)
else if(m_playcontrol[PA_Y]>0 && !bdown)
{
if(!g_pInput->getHoldedCommand(IC_LEFT) && !g_pInput->getHoldedCommand(IC_RIGHT))
xDirection = 0;
moveDown(movespeed);
walking = true;
yDirection = DOWN;
waveTimer = 0;
if(m_playcontrol[PA_X]==0)
xDirection = 0;
moveDown(movespeed);
walking = true;
yDirection = DOWN;
waveTimer = 0;
}
// In case noclipping was triggered, make it solid, or remove it...
if(m_Cheatmode.noclipping)
{
solid = !solid;
m_Cheatmode.noclipping = false;
solid = !solid;
m_Cheatmode.noclipping = false;
}
// perform actions depending on if the jump button was pressed
if(g_pInput->getPressedCommand(IC_JUMP))
if( m_playcontrol[PA_JUMP] )
{
// Get the object
Uint16 object = mp_Map->getPlaneDataAt(2, getXMidPos(), getYMidPos());
if(object) // if we found an object
{
// start the level
startLevel(object);
g_pInput->flushCommands();
}
// Get the object
Uint16 object = mp_Map->getPlaneDataAt(2, getXMidPos(), getYMidPos());
if(object) // if we found an object
{
// start the level
startLevel(object);
g_pInput->flushCommands();
}
}
// If keen is just walking on the map or swimming in the sea. Do the proper animation for it.
if(m_basesprite == walkBaseFrame)
{
performWalkingAnimation(walking);
m_cantswim = false;
waveTimer++;
if( waveTimer >= TIME_TO_WAVE)
{
mProcessPtr = &CPlayerWM::processWaving;
m_basesprite = wavingBaseFrame;
waveTimer = 0;
return;
}
performWalkingAnimation(walking);
m_cantswim = false;
waveTimer++;
if( waveTimer >= TIME_TO_WAVE)
{
mProcessPtr = &CPlayerWM::processWaving;
m_basesprite = wavingBaseFrame;
waveTimer = 0;
return;
}
}
else if(m_basesprite == swimBaseFrame)
{
if(m_Inventory.Item.m_special.ep4.swimsuit)
{
performSwimmingAnimation();
}
else
{
if( !m_cantswim )
{
CEventContainer& EventContainer = g_pBehaviorEngine->m_EventList;
g_pSound->playSound( SOUND_CANT_DO, PLAY_PAUSEALL );
EventContainer.add( new EventSendBitmapDialogMsg(g_pGfxEngine->getBitmap(105),
g_pBehaviorEngine->getString("CANT_SWIM_TEXT"), LEFT) );
m_cantswim = true;
}
}
if(m_Inventory.Item.m_special.ep4.swimsuit)
{
performSwimmingAnimation();
}
else
{
if( !m_cantswim )
{
CEventContainer& EventContainer = g_pBehaviorEngine->m_EventList;
g_pSound->playSound( SOUND_CANT_DO, PLAY_PAUSEALL );
EventContainer.add( new EventSendBitmapDialogMsg(g_pGfxEngine->getBitmap(105),
g_pBehaviorEngine->getString("CANT_SWIM_TEXT"), LEFT) );
m_cantswim = true;
}
}
}
}
......
......@@ -110,7 +110,7 @@ CGalaxySpriteObject* CMapLoaderGalaxyEp4::addFoe(CMap &Map, word foe, size_t x,
switch(foe)
{
case 0x01:
case 0x02:
case 0x02:
// This is the player on the map in one level
p_newfoe = new galaxy::CPlayerLevel(&Map, foe, x, y, m_ObjectPtr,
(foe==0x01) ? RIGHT : LEFT, m_Inventory, m_Cheatmode, 0x98C);
......
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