CPlayGameGalaxy.cpp 6.36 KB
Newer Older
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
#include "graphics/CGfxEngine.h"
12
#include "dialog/CMessageBoxBitmapGalaxy.h"
13
#include "dialog/CMessageBoxSelection.h"
14
#include "sdl/CVideoDriver.h"
15
#include "sdl/input/CInput.h"
16
#include "sdl/sound/CSound.h"
17
#include "sdl/music/CMusic.h"
18
#include "StringUtils.h"
19

20 21 22
namespace galaxy
{

gerstrong's avatar
gerstrong committed
23
CPlayGameGalaxy::CPlayGameGalaxy(CExeFile &ExeFile, char level,
24 25 26
		 char numplayers, CSaveGameController &SavedGame) :
CPlayGame(ExeFile, level, numplayers ),
m_Inventory(m_LevelName),
Gerstrong's avatar
Gerstrong committed
27 28
m_WorldMap(ExeFile, m_Inventory, m_Cheatmode),
m_LevelPlay(ExeFile, m_Inventory, m_Cheatmode),
29
m_SavedGame(SavedGame)
30 31 32
{
	m_WorldMap.init();
}
33 34

bool CPlayGameGalaxy::loadGameState()
35
{	return false;	}
36

Gerhard Stein's avatar
Gerhard Stein committed
37 38 39 40
bool CPlayGameGalaxy::saveGameState()
{	return false;	}


41 42
// Setup for the ingame
bool CPlayGameGalaxy::init()
43
{
44 45 46
	if(m_Level == 0)
	{
		m_WorldMap.setActive(true);
Gerhard Stein's avatar
Gerhard Stein committed
47
		m_WorldMap.loadAndPlayMusic();
48
		m_LevelName = m_WorldMap.getLevelName();
49 50 51 52
	}
	else
	{
		// manually a level has been loaded
53
		m_LevelPlay.loadLevel(m_Level);
54
		m_LevelPlay.setActive(true);
55
		m_LevelName = m_LevelPlay.getLevelName();
56
	}
57 58

	return true;
59 60
}

61 62 63
/**
 *  The main ingame process cycle when keen galaxy is up and running
 */
64 65
void CPlayGameGalaxy::process()
{
66 67 68
	if(g_pSound->pauseGamePlay())
		return;

69
	/*if(mp_Menu) // In case the menu is open
70 71
	{
		// draw the title bitmap here!
72
		m_BackgroundBitmap.draw(g_pVideoDriver->mp_VideoEngine->getBlitSurface(), 0, 0);*/
73

74
		/*if(mp_Menu->mustClose())
75
		{
Gerhard Stein's avatar
Gerhard Stein committed
76
			g_pMusicPlayer->play();
77 78 79 80 81
			delete mp_Menu;
			mp_Menu = NULL;
		}
		else if(mp_Menu->getExitEvent())
			m_exitgame = true;
82 83
		else if(mp_Menu->mustEndGame())
			m_endgame = true;
84
		else
85
			mp_Menu->process();*/
86 87
	/*}
	else*/
88 89 90
	{
		processInput();

91 92 93 94
		// Trigger the Status screen here
		if(m_Inventory.showStatus())
		{
			if(g_pInput->getPressedAnyCommand())
95 96
			{
				g_pSound->playSound(SOUND_STATUS_SLIDE_OUT);
97
				m_Inventory.toggleStatusScreen();
98
			}
99 100 101 102
		}
		else
		{
			if(g_pInput->getPressedCommand(IC_STATUS))
103 104
			{
				g_pSound->playSound(SOUND_STATUS_SLIDE_IN);
105
				m_Inventory.toggleStatusScreen();
106
			}
107 108 109
		}


Gerstrong's avatar
Gerstrong committed
110
		if(g_pInput->getPressedCommand(IC_STATUS))
111
		{
Gerstrong's avatar
Gerstrong committed
112
			m_Inventory.toggleStatusScreen();
113
		}
114

115
		const bool msgboxactive = !mMessageBoxes.empty();
Gerstrong's avatar
Gerstrong committed
116

117 118
		// process Page if one is open. Could be one of the finale scenes
		//if(m_Page.isActive())
119
		//m_Page.process();
120

121 122
		// process World Map if active. At the start it's enabled
		if(m_WorldMap.isActive())
123
		{
Gerstrong's avatar
Gerstrong committed
124
			m_WorldMap.process(msgboxactive);
125
		}
126 127 128

		// process World Map if active. At the start it's enabled
		if(m_LevelPlay.isActive())
129
		{
Gerstrong's avatar
Gerstrong committed
130
			m_LevelPlay.process(msgboxactive);
131
		}
132

Gerstrong's avatar
Gerstrong committed
133 134 135 136 137
		// We have to show the status screen, do so...
		if( m_Inventory.showStatus() )
		{
			m_Inventory.drawStatus();
		}
Gerstrong's avatar
Gerstrong committed
138 139 140 141

		// Draw some Textboxes with Messages only if one of those is open and needs to be drawn
		if(msgboxactive)
		{
142
			CMessageBoxGalaxy *pMB = mMessageBoxes.front().get();
Gerstrong's avatar
Gerstrong committed
143 144
			pMB->process();

145
			if(pMB->isFinished())
Gerstrong's avatar
Gerstrong committed
146
			{
147
				mMessageBoxes.pop_front();
Gerstrong's avatar
Gerstrong committed
148 149 150 151 152 153 154 155 156 157 158 159 160 161
			}
			return;
		}

		//// Special Keyboard Input

		/// Cheat Codes
		if( g_pInput->getHoldedKey(KF10) )
		{
			if(g_pInput->getHoldedKey(KJ))
			{
				m_Cheatmode.jump = !m_Cheatmode.jump;
				std::string jumpstring = "Jump-Cheat has been ";
				jumpstring += ((m_Cheatmode.jump) ? "enabled" : "disabled");
162
				mMessageBoxes.push_back(new CMessageBoxGalaxy(jumpstring));
Gerstrong's avatar
Gerstrong committed
163 164 165 166 167 168
			}
			else if(g_pInput->getHoldedKey(KG))
			{
				m_Cheatmode.god = !m_Cheatmode.god;
				std::string godstring = "God-Mode has been ";
				godstring += ((m_Cheatmode.god) ? "enabled" : "disabled");
169
				mMessageBoxes.push_back(new CMessageBoxGalaxy(godstring));
Gerstrong's avatar
Gerstrong committed
170 171 172 173
			}
			else if(g_pInput->getHoldedKey(KI))
			{
				m_Cheatmode.items = true;
174
				mMessageBoxes.push_back(new CMessageBoxGalaxy("Get all Items!"));
Gerstrong's avatar
Gerstrong committed
175 176 177 178 179 180
				m_Inventory.Item.triggerAllItemsCheat();
				m_Cheatmode.items = true;
			}
			else if(g_pInput->getHoldedKey(KN))
			{
				m_Cheatmode.noclipping = true;
181
				mMessageBoxes.push_back(new CMessageBoxGalaxy("No clipping toggle!"));
Gerstrong's avatar
Gerstrong committed
182 183
			}
		}
184
	}
185 186 187 188 189

	// 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;
190 191

	if( EventSendBitmapDialogMsg* ev = EventContainer.occurredEvent<EventSendBitmapDialogMsg>() )
192
	{
193
		CMessageBoxBitmapGalaxy *pMsgBox = new CMessageBoxBitmapGalaxy( ev->Msg, ev->BitmapID, ev->Direction );
194
		pMsgBox->init();
195 196 197
		//CMessageBoxGalaxy *pMsgBox = new CMessageBoxGalaxy( ev->Msg );

		mMessageBoxes.push_back( pMsgBox );
198 199 200 201
		EventContainer.pop_Event();
	}
	else if( EventSendSelectionDialogMsg* ev = EventContainer.occurredEvent<EventSendSelectionDialogMsg>() )
	{
202
		g_pMusicPlayer->stop();
203
		mMessageBoxes.push_back( new CMessageBoxSelection( ev->Message, ev->Options ) );
204
		EventContainer.pop_Event();
205
	}
206

207

208
	if(mMessageBoxes.empty())
209
	{
210
		if( EventEnterLevel *ev = EventContainer.occurredEvent<EventEnterLevel>() )
211 212 213 214 215 216 217 218 219 220 221 222 223 224
		{
			// Start a new level!
			if(ev->data > 0xC000)
			{
				const Uint16 NewLevel = ev->data - 0xC000;
				g_pMusicPlayer->stop();
				m_WorldMap.setActive(false);
				m_LevelPlay.loadLevel(NewLevel);
				m_LevelName = m_LevelPlay.getLevelName();
				g_pSound->playSound( SOUND_ENTER_LEVEL );
				m_LevelPlay.setActive(true);
			}
			EventContainer.pop_Event();
		}
225
		else if( EventContainer.occurredEvent<EventRestartLevel>() )
226
		{
227 228
			g_pMusicPlayer->stop();
			m_LevelPlay.reloadLevel();
229 230
			EventContainer.pop_Event();
		}
231
		else if( EventExitLevel *ev = EventContainer.occurredEvent<EventExitLevel>() )
232 233 234 235 236 237
		{
			g_pMusicPlayer->stop();
			m_LevelPlay.setActive(false);
			m_WorldMap.setActive(true);
			m_LevelName = m_WorldMap.getLevelName();
			m_WorldMap.loadAndPlayMusic();
238
			EventContainer.add( new EventPlayerEndLevel(*ev) );
239 240 241 242 243
			EventContainer.pop_Event();
		}
		else if( EventPlayTrack *ev =  EventContainer.occurredEvent<EventPlayTrack>() )
		{
			g_pMusicPlayer->stop();
244
			if( g_pMusicPlayer->loadTrack(m_ExeFile, ev->track) )
245 246
				g_pMusicPlayer->play();
			EventContainer.pop_Event();
247
		}
248
	}
249 250 251 252
}

void CPlayGameGalaxy::processInput()
{
253
	// open the menu
254 255
	//if(g_pInput->getPressedCommand(IC_BACK))
	//{
256
		//mp_Menu = new CMenuGalaxy(ACTIVE, m_SavedGame, m_restartVideo);
257
		//m_BackgroundBitmap = *g_pGfxEngine->getBitmap("KEENSWATCH");
258 259
		//g_pMusicPlayer->pause();
	//}
260 261
}

262

263 264

}