CPlayGameGalaxy.cpp 3 KB
Newer Older
gerstrong's avatar
gerstrong committed
1 2 3 4 5 6 7 8
/*
 * CPlayGame.cpp
 *
 *  Created on: 31.01.2010
 *      Author: gerstrong
 */

#include "CPlayGameGalaxy.h"
gerstrong's avatar
gerstrong committed
9 10
#include "CMapLoaderGalaxy.h"

11 12 13 14
#include "graphics/CGfxEngine.h"
#include "sdl/CVideoDriver.h"
#include "sdl/CInput.h"
#include "StringUtils.h"
15

gerstrong's avatar
gerstrong committed
16 17 18
namespace galaxy
{

gerstrong's avatar
gerstrong committed
19
CPlayGameGalaxy::CPlayGameGalaxy(CExeFile &ExeFile, char level,
Gerhard Stein's avatar
Gerhard Stein committed
20
		 char numplayers, Uint8& difficulty,
21
		 stOption *p_option, CSavedGame &SavedGame) :
22
CPlayGame(ExeFile, level, numplayers, difficulty, p_option),
23
m_WorldMap(ExeFile, m_Inventory),
24
m_LevelPlay(ExeFile, m_Inventory),
25 26
mp_Menu(NULL),
m_SavedGame(SavedGame)
27 28 29
{
	m_WorldMap.init();
}
gerstrong's avatar
gerstrong committed
30 31

bool CPlayGameGalaxy::loadGameState()
32
{	return false;	}
gerstrong's avatar
gerstrong committed
33

34 35
// Setup for the ingame
bool CPlayGameGalaxy::init()
36
{
37 38 39 40 41 42 43 44
	if(m_Level == 0)
	{
		m_WorldMap.setActive(true);
		return false;
	}
	else
	{
		// manually a level has been loaded
45
		m_LevelPlay.loadLevel(m_Level);
46 47 48
		m_LevelPlay.setActive(true);
		return true;
	}
49 50
}

51 52 53
/**
 *  The main ingame process cycle when keen galaxy is up and running
 */
54 55
void CPlayGameGalaxy::process()
{
56 57 58 59 60 61 62 63 64 65 66 67
	if(mp_Menu) // In case the menu is open
	{
		// draw the title bitmap here!
		m_BackgroundBitmap.draw(g_pVideoDriver->BlitSurface, 0, 0);

		if(mp_Menu->mustClose())
		{
			delete mp_Menu;
			mp_Menu = NULL;
		}
		else if(mp_Menu->getExitEvent())
			m_exitgame = true;
68 69
		else if(mp_Menu->mustEndGame())
			m_endgame = true;
70 71 72 73 74 75 76 77 78
		else
			mp_Menu->process();
	}
	else
	{
		processInput();

		// process World Map if active. At the start it's enabled
		if(m_WorldMap.isActive())
79
		{
80
			m_WorldMap.process();
81 82
		}

83
		// process World Map if active. At the start it's enabled
84 85 86 87
		if(m_LevelPlay.isActive())
		{
			m_LevelPlay.process();
		}
88

89 90
		// process Page if one is open. Could be one of the finale scenes
		//if(m_Page.isActive())
91
		//m_Page.process();
92

93 94
		processRendering();
	}
95 96 97 98 99

	// In this part we will poll all the relevant Events that are important for the
	// Galaxy Main Engine itself. For example, load map, setup world map, show Highscore
	// are some of those events.
	CEventContainer& EventContainer = g_pBehaviorEngine->m_EventList;
100
	if( EventEnterLevel* ev = EventContainer.occurredEvent<EventEnterLevel>() )
101
	{
102
		// Start a new level!
103
		if(ev->data > 0xC000)
104 105
		{
			m_WorldMap.setActive(false);
106
			m_LevelPlay.loadLevel(ev->data - 0xC000);
107 108
			m_LevelPlay.setActive(true);
		}
109
		EventContainer.pop_Event();
110
	}
111
	else if( EventContainer.occurredEvent<EventExitLevel>() )
112 113 114 115 116
	{
		m_LevelPlay.setActive(false);
		m_WorldMap.setActive(true);
	}

117

118 119 120 121
}

void CPlayGameGalaxy::processInput()
{
122 123 124
	// open the menu
	if(g_pInput->getPressedCommand(IC_QUIT))
	{
125
		mp_Menu = new CMenuGalaxy(ACTIVE, m_ExeFile, m_SavedGame, mp_option, m_restartVideo);
126 127
		m_BackgroundBitmap = *g_pGfxEngine->getBitmap("KEENSWATCH");
	}
128 129
}

130 131 132 133
/*
 * This processes the rendering over all the other stuff. THis is used for extra messages normally
 * blit scrollsurface happens with m_WorldMap or m_LevelPlay
 */
134 135
void CPlayGameGalaxy::processRendering()
{
136

137
}
gerstrong's avatar
gerstrong committed
138

139

gerstrong's avatar
gerstrong committed
140 141 142
void CPlayGameGalaxy::cleanup()
{}

gerstrong's avatar
gerstrong committed
143 144
CPlayGameGalaxy::~CPlayGameGalaxy()
{
145 146
	if(mp_Menu)
		delete mp_Menu;
gerstrong's avatar
gerstrong committed
147 148 149
}

}