コード例 #1
0
ファイル: SpriteManager.cpp プロジェクト: godsonkraju/Rebelle
/*
	addSpriteItemsToRenderList - This method goes through all of the sprites,
	including the player sprite, and adds the visible ones to the render list.
	This method should be called each frame.
*/
void SpriteManager::addSpriteItemsToRenderList()
{
	Game *game = Game::getSingleton();
	GameStateManager *gsm = game->getGSM();
	GameGUI *gui = game->getGUI();
	if (gsm->isWorldRenderable())
	{
		GameGraphics *graphics = game->getGraphics();
		RenderList *renderList = graphics->getWorldRenderList();
		Viewport *viewport = gui->getViewport();

		// ADD THE PLAYER SPRITE, IF THERE IS ONE
		if (player != nullptr)
			addSpriteToRenderList(player, renderList, viewport);

		// NOW ADD THE REST OF THE SPRITES
		list<Bot*>::iterator botIterator;
		botIterator = bots.begin();
		while (botIterator != bots.end())
		{			
			Bot *bot = (*botIterator);
			addSpriteToRenderList(bot, renderList, viewport);
			botIterator++;
		}
	}
}
コード例 #2
0
/*
	fillRenderLists - This method causes the render lists to be
	filled with the things that have to be drawn this frame.
*/
void GameGraphics::fillRenderLists(Game *game)
{
    // GENERATE RENDER LISTS FOR GAME WORLD AND GUI
    GameStateManager *gsm = game->getGSM();
    gsm->addGameRenderItemsToRenderList(game);
    GameGUI *gui = game->getGUI();
    gui->addRenderItemsToRenderList(game);
}
コード例 #3
0
int WINAPI WinMain(HINSTANCE hInstance,
                   HINSTANCE hPrevInstance,
                   LPSTR lpCmdLine,
                   int nCmdShow)
{

	b2Vec2 gravity(0.0f, -10.0f);


	// CREATE THE GAME
	Game *balloonEscapeGame = new Game();
	// FIRST WE'LL SETUP THE DATA LOADER, SINCE IT MAY NEED TO READ
	// IN DATA TO SETUP OTHER STUFF
	BalloonEscapeDataLoader *balloonEscapeDataLoader = new BalloonEscapeDataLoader();
	balloonEscapeDataLoader->initWinHandle(hInstance, nCmdShow);
	balloonEscapeGame->setDataLoader(balloonEscapeDataLoader);
	balloonEscapeDataLoader->loadGame(balloonEscapeGame, W_INIT_FILE);
	
	// WHAT WE SHOULD BE DOING HERE IS LOADING THE GAME DATA FROM FILES. THIS
	// MEANS THE GUIS THEMSELVES AS WELL AS THE LEVELS. THAT WILL BE LEFT
	// FOR BECHMARK HWS. FOR NOW WE WILL JUST HARD CODE THE LOADING OF THE GUI

	// LOAD THE GUI STUFF, AGAIN, NOTE THAT THIS SHOULD REALLY
	// BE DONE FROM A FILE, NOT HARD CODED
	balloonEscapeDataLoader->loadGUI(balloonEscapeGame, W_GUI_INIT_FILE);

	// SPECIFY WHO WILL HANDLE BUTTON EVENTS
	BalloonEscapeButtonEventHandler *balloonEscapeButtonHandler = new BalloonEscapeButtonEventHandler();
	GameGUI *gui = balloonEscapeGame->getGUI();
	gui->registerButtonEventHandler((ButtonEventHandler*)balloonEscapeButtonHandler);
	// SPECIFY WHO WILL HANDLE KEY EVENTS
	BalloonEscapeKeyEventHandler *balloonEscapeKeyHandler = new BalloonEscapeKeyEventHandler();
	balloonEscapeGame->getInput()->registerKeyHandler((KeyEventHandler*)balloonEscapeKeyHandler);

	// THIS WILL HANDLE PHYSICS COLLISION EVENTS
	BalloonEscapeCollisionListener *balloonEscapeCollisionListener = new BalloonEscapeCollisionListener();
	balloonEscapeGame->getGSM()->getPhysics()->setCollisionListener(balloonEscapeCollisionListener);

	// START THE GAME LOOP
	balloonEscapeGame->runGameLoop();

	// GAME'S OVER SHUTDOWN ALL THE STUFF WE CONSTRUCTED HERE
	delete (WindowsOS*)balloonEscapeGame->getOS();
	delete (WindowsInput*)balloonEscapeGame->getInput();
	delete (WindowsTimer*)balloonEscapeGame->getTimer();
	delete (DirectXGraphics*)balloonEscapeGame->getGraphics();
	delete (BalloonEscapeTextGenerator*)balloonEscapeGame->getText()->getTextGenerator();
	delete balloonEscapeButtonHandler;
	delete balloonEscapeKeyHandler;
	delete balloonEscapeGame;

	// AND RETURN
	return 0;
}
コード例 #4
0
/*
	respondToMouseInput - This method sends the updated cursor position
	to the GameGUI so that it can update the Button and Cursor states.
	It then checks to see if the left mouse button is pressed, and if
	so, it asks the gui to check to see if it needs to fire an event.
	This should be called once per frame, after input is retrieved.
*/
void WindowsInput::respondToMouseInput(Game *game)
{
	GameGUI *gui = game->getGUI();
	GameStateManager *gsm = game->getGSM();
	Viewport *viewport = gui->getViewport();
	gui->updateGUIState(mousePoint->x, mousePoint->y, gsm->getCurrentGameState());
	
	if ( (GetAsyncKeyState(VK_LBUTTON) & 0X8000)
		&& (inputState[VK_LBUTTON].isFirstPress))
	{
		if ((gsm->isGameInProgress()) && viewport->areScreenCoordinatesInViewport(mousePoint->x, mousePoint->y))
			mouseHandler->handleMousePressEvent(game, mousePoint->x-viewport->getViewportOffsetX(), mousePoint->y-viewport->getViewportOffsetY());
		gui->checkCurrentScreenForAction(game);
	}
}
コード例 #5
0
/*
	WinMain - This is the application's starting point. In this method we will construct a Game object,
	then initialize all the platform-dependent technologies, then construct all the custom data for our
	game, and then initialize the Game with	our custom data. We'll then start the game loop.
*/
int WINAPI WinMain(HINSTANCE hInstance,
                   HINSTANCE hPrevInstance,
                   LPSTR lpCmdLine,
                   int nCmdShow)
{
    // CREATE THE GAME
    Game *dummyGame = new Game();

    // FIRST WE'LL SETUP THE DATA LOADER, SINCE IT MAY NEED TO READ
    // IN DATA TO SETUP OTHER STUFF
    GroupGameDataLoader *dummyDataLoader = new GroupGameDataLoader();
    dummyDataLoader->initWinHandle(hInstance, nCmdShow);
    dummyGame->setDataLoader(dummyDataLoader);
    dummyDataLoader->loadGame(dummyGame, GG_INIT_FILE);

    // WHAT WE SHOULD BE DOING HERE IS LOADING THE GAME DATA FROM FILES. THIS
    // MEANS THE GUIS THEMSELVES AS WELL AS THE LEVELS. THAT WILL BE LEFT
    // FOR BECHMARK HWS. FOR NOW WE WILL JUST HARD CODE THE LOADING OF THE GUI

    // LOAD THE GUI STUFF, AGAIN, NOTE THAT THIS SHOULD REALLY
    // BE DONE FROM A FILE, NOT HARD CODED
    dummyDataLoader->loadGUI(dummyGame, L"");

    // SPECIFY WHO WILL HANDLE BUTTON EVENTS
    GroupGameButtonEventHandler *dummyButtonHandler = new GroupGameButtonEventHandler();
    GameGUI *gui = dummyGame->getGUI();
    gui->registerButtonEventHandler((ButtonEventHandler*)dummyButtonHandler);

    // SPECIFY WHO WILL HANDLE KEY EVENTS
    GroupGameKeyEventHandler *dummyKeyHandler = new GroupGameKeyEventHandler();
    dummyGame->getInput()->registerKeyHandler((KeyEventHandler*)dummyKeyHandler);

    // START THE GAME LOOP
    dummyGame->runGameLoop();

    // GAME'S OVER SHUTDOWN ALL THE STUFF WE CONSTRUCTED HERE
    delete (WindowsOS*)dummyGame->getOS();
    delete (WindowsInput*)dummyGame->getInput();
    delete (WindowsTimer*)dummyGame->getTimer();
    delete (DirectXGraphics*)dummyGame->getGraphics();
    delete (GroupGameTextGenerator*)dummyGame->getText()->getTextGenerator();
    delete dummyButtonHandler;
    delete dummyKeyHandler;
    delete dummyGame;

    // AND RETURN
    return 0;
}
コード例 #6
0
/*
	addWorldRenderItemsToRenderList - This method sends the render
	list and viewport to each of the layers such that they
	may fill it with RenderItems to draw.
*/
void World::addWorldRenderItemsToRenderList(Game *game)
{
	GameStateManager *gsm = game->getGSM();
	GameGUI *gui = game->getGUI();
	if (gsm->isWorldRenderable())
	{
		GameGraphics *graphics = game->getGraphics();
		RenderList *renderList = graphics->getWorldRenderList();
		Viewport *viewport = gui->getViewport();
		for (unsigned int i = 0; i < layers->size(); i++)
		{
			layers->at(i)->addRenderItemsToRenderList(	renderList,
														viewport);
		}
	}
}
コード例 #7
0
/*
	addSpriteItemsToRenderList - This method goes through all of the sprites,
	including the player sprite, and adds the visible ones to the render list.
	This method should be called each frame.
*/
void SpriteManager::addSpriteItemsToRenderList(	Game *game)
{
	GameStateManager *gsm = game->getGSM();
	GameGUI *gui = game->getGUI();
	if (gsm->isWorldRenderable())
	{
		GameGraphics *graphics = game->getGraphics();
		RenderList *renderList = graphics->getWorldRenderList();
		Viewport *viewport = gui->getViewport();

		// ADD THE PLAYER SPRITE
		addSpriteToRenderList(&player, renderList, viewport);


		// NOW ADD THE REST OF THE SPRITES
		list<AnimatedSprite*>::iterator botIterator;
		botIterator = enemies.begin();
		while (botIterator != enemies.end())
		{			
			AnimatedSprite *bot = (*botIterator);
			addSpriteToRenderList(bot, renderList, viewport);
			botIterator++;
		}

		// NOW ADD THE REST OF THE SPRITES
		list<AnimatedSprite*>::iterator blockIterator;
		blockIterator = blocks.begin();
		while (blockIterator != blocks.end())
		{
			AnimatedSprite *block = (*blockIterator);
			addSpriteToRenderList(block, renderList, viewport);
			blockIterator++;
		}

		list<AnimatedSprite*>::iterator exitIt;
		exitIt = exits.begin();
		while (exitIt != exits.end())
		{
			AnimatedSprite *exit = (*exitIt);
			addSpriteToRenderList(exit, renderList, viewport);
			exitIt++;
		}
	}
}
コード例 #8
0
/*
	addSpriteItemsToRenderList - This method goes through all of the sprites,
	including the player sprite, and adds the visible ones to the render list.
	This method should be called each frame.
*/
void SpriteManager::addSpriteItemsToRenderList(	Game *game)
{
	GameStateManager *gsm = game->getGSM();
	GameGUI *gui = game->getGUI();
	if (gsm->isWorldRenderable())
	{
		GameGraphics *graphics = game->getGraphics();
		RenderList *renderList = graphics->getWorldRenderList();
		Viewport *viewport = gui->getViewport();

		// ADD THE PLAYER SPRITE
		addSpriteToRenderList(&player, renderList, viewport);
	/*	X = player.getPhysicalProperties() -> getX();
		Y = player.getPhysicalProperties() -> getY();*/
		//addSpriteToRenderList(&healthBar, renderList, viewport);
		// NOW ADD THE REST OF THE SPRITES
		list<Bot*>::iterator botIterator;
		botIterator = bots.begin();
		while (botIterator != bots.end())
		{			

			Bot *bot = (*botIterator);
			if (bot->getCurrentState() == L"DYING" && bot->getRemoval() > 0)
				bot->setRemoval(bot->getRemoval()-1);
			if (bot->getRemoval() != 0) {
				addSpriteToRenderList(bot, renderList, viewport);
			}
			
			if (bot->getRemoval() == 0){
					
					
				//bot->setCurrentlyCollidable(false);	
			}
			
			botIterator++;
		}
	}
}
コード例 #9
0
/*
	Renders all tiles and sprites. Note that these objects can
	be rotated.
*/
void DirectXGraphics::renderWorldRenderList()
{
	worldRenderList->resetIterator();
	RenderItem itemToRender;
	LPDIRECT3DTEXTURE9 texture;
	RECT *rect = NULL;
	GameGUI *gui = game->getGUI();
	Viewport *viewport = gui->getViewport();

	// GO THROUGH EACH ITEM IN THE LIST
	while (worldRenderList->hasNext())
	{
		float translationX;
		float translationY;
		if (rect != NULL)
			delete rect;
		rect = NULL;
		itemToRender = worldRenderList->next();
		
		// LET'S GET THE TEXTURE WE WANT TO RENDER
		int id = itemToRender.id;
		if (id >= 0)
		{
			texture = ((DirectXTextureManager*)worldTextureManager)->getTexture(id);
			D3DXVECTOR3 position = D3DXVECTOR3(	(FLOAT)(itemToRender.x),
											(FLOAT)(itemToRender.y),
												0);

			position.x += viewport->getViewportOffsetX();
			position.y += viewport->getViewportOffsetY();

			// ADJUST FOR THE GUI OFFSET
			if ((position.x < viewport->getViewportOffsetX())
				||  (position.y < viewport->getViewportOffsetY()))
			{
				IDirect3DSurface9 *surface;
				UINT level = 0;
				HRESULT result = texture->GetSurfaceLevel(level, &surface);
				D3DSURFACE_DESC surfaceDescription;
				surface->GetDesc(&surfaceDescription);
				rect = new RECT();
				rect->left = 0;
				rect->top = 0;
				rect->right = surfaceDescription.Width;
				rect->bottom = surfaceDescription.Height;
				if (position.x < viewport->getViewportOffsetX())
				{
					int xDiff = viewport->getViewportOffsetX() - (int)position.x;
					rect->left = xDiff;
					position.x += xDiff;
				}
				if (position.y < viewport->getViewportOffsetY())
				{
					int yDiff = viewport->getViewportOffsetY() - (int)position.y;
					rect->top = yDiff;
					position.y += yDiff;
				}	
			}			

			// LET'S PUT THE STANDARD ROTATION MATRIX ASIDE
			// FOR A SECOND. IT WILL BE USED FOR RENDERING THE
			// GUI, BUT WE'LL WANT A CUSTOM ONE FOR WORLD OBJECTS
			D3DXMATRIX defaultTransform;
			D3DXMatrixIdentity(&defaultTransform);
				
			// TO RENDER A PROPERLY ROTATED OBJECT TO THE WORLD,
			// FIRST WE NEED TO MOVE IT TO THE ORIGIN, CENTERED
			// ABOUT THE ORIGIN SO WE SET UP THIS MATRIX
			// TO DO THIS
			D3DXMATRIX translationToOrigin;
			D3DXMatrixIdentity(&translationToOrigin);
		    translationToOrigin._41 = -(itemToRender.width/2);
			translationToOrigin._42 = -(itemToRender.height/2);
	
			// THEN WE NEED A MATRIX TO DO THE ROTATION
			D3DXMATRIX rotationAboutOrigin;
			D3DXMatrixIdentity(&rotationAboutOrigin);
	
			// THE PROBLEM ANGLES ARE 0, 90, 180, and 270
			float cosTheta = cos(itemToRender.rotationInRadians);
			float sinTheta = sin(itemToRender.rotationInRadians);
			if (cosTheta != cosTheta)
				cosTheta = 0;
			if (sinTheta != sinTheta)
				sinTheta = 0;
			rotationAboutOrigin._11 = cosTheta;
			rotationAboutOrigin._21 = -sinTheta;
			rotationAboutOrigin._12 = sinTheta;
			rotationAboutOrigin._22 = cosTheta;
	
			// AND THEN WE NEED A MATRIX TO ROTATE THE OBJECT
			// TO THE LOCATION WE WANT IT RENDERED
			D3DXMATRIX translationBackToCenter;
			D3DXMatrixIdentity(&translationBackToCenter);
			translationBackToCenter._41 = ((position.x) + (itemToRender.width/2));
			translationBackToCenter._42 = ((position.y) + (itemToRender.height/2));
	
			// THE COMBINED MATRIX COMBINES THESE 3 OPERATIONS
			// INTO A SINGLE MATRIX
			D3DXMATRIX combinedMatrix = translationToOrigin;
			combinedMatrix *= rotationAboutOrigin;
			combinedMatrix *= translationBackToCenter;
	
			// NOW LET'S USE THE COMBINED MATRIX TO POSITION AND ROTATE THE ITEM
			spriteHandler->SetTransform(&combinedMatrix);
		
			// RENDER THE OPAQUE ITEMS
			if (itemToRender.a == 255)
			{
				if (FAILED(spriteHandler->Draw(
					texture, 
					rect,
			        NULL,
					NULL,
					DEFAULT_ALPHA_COLOR)))
				{
					game->getText()->writeDebugOutput("\nspriteHandler->Draw: FAILED");
				}
				// RENDER THE ITEMS WITH CUSTOM TRANSPARENCY
				else
				{
					if (itemToRender.a < 0)
						itemToRender.a = 0;
					else if (itemToRender.a > 255)
						itemToRender.a = 255;
					if (FAILED(spriteHandler->Draw(
						texture,
						rect,
						NULL,
						NULL,
						D3DCOLOR_ARGB(itemToRender.a, 255, 255, 255))))
					{
						game->getText()->writeDebugOutput("\nspriteHandler->Draw: FAILED");
					}
				}
			}
		}
	}

	// NOW EMPTY THE LIST, WE'RE ALL DONE WITH IT
	worldRenderList->clear();
	if (rect != NULL)
		delete rect;
	
	// AND RESTORE THE MATRIX USED FOR RENDERING THE GUI
	D3DXMATRIX identityMatrix;
	D3DXMatrixIdentity(&identityMatrix);
	spriteHandler->SetTransform(&identityMatrix);
}
コード例 #10
0
/*
	WinMain - This is the application's starting point. In this
	method we will construct a Game object, then construct all the
	custom data for our game, and then initialize the Game with
	our custom data. We'll then start the game loop.
*/
int WINAPI WinMain(HINSTANCE hInstance,
                   HINSTANCE hPrevInstance,
                   LPSTR lpCmdLine,
                   int nCmdShow)
{
	// USE WINDOWED MODE (ONE LESS HEADACHE)
	bool fullscreen = false;

	// CREATE A GAME
	file = "";
	Game *worldRenderingGame = new Game();
	

	// SPECIFY THE DIRECTORY WHERE ALL GAME DESIGN FILES
	// ARE TO BE LOADED FROM
	wchar_t *gameDataPathName = constructEmptyWCHAR_TArray(L"design/");

	// WE'RE USING THE WINDOWS PLATFORM, SO MAKE A CUSTOM
	// GameOS OBJECT (WindowsGameOS), FOR SOME WINDOWS
	// PLATFORM STUFF, INCLUDING A Window OF COURSE
	wchar_t *gameTitle = constructEmptyWCHAR_TArray(L"World Scrolling Game");
	WindowsGameOS *os = new WindowsGameOS(	hInstance, 
											nCmdShow,
											fullscreen,
											gameTitle,
											worldRenderingGame);

	// RENDERING WILL BE DONE USING DirectX
	DirectXGraphics *graphics = new DirectXGraphics(worldRenderingGame);
	graphics->init();
	graphics->initGraphics(os->getWindowHandle(), fullscreen);
	graphics->initTextFont(22);
	// SOUND STUFF FROM XACT	
	XactSound *sound= new XactSound(worldRenderingGame);
	sound->intiSound();
	// WE'LL USE WINDOWS PLATFORM METHODS FOR GETTING INPUT
	WindowsGameInput *input = new WindowsGameInput();

	// AND THE TIMER
	WindowsGameTimer *timer = new WindowsGameTimer();

	// NOW INITIALIZE THE Game WITH ALL THE
	// PLATFORM AND GAME SPECIFIC DATA WE JUST CREATED
	worldRenderingGame->init(	gameDataPathName,
						(GameGraphics*)graphics,
						(GameOS*)os,
						(GameInput*)input,
						(GameTimer*)timer);

	// LOAD OUR CUSTOM TEXT GENERATOR, WHICH DRAWS
	// TEXT ON THE SCREEN EACH FRAME
	WRTextGenerator *textGenerator = new WRTextGenerator();
	textGenerator->initText(worldRenderingGame);
	worldRenderingGame->getText()->setTextGenerator((TextGenerator*)textGenerator);

	// LOAD THE GUI STUFF, NOTE THAT THIS SHOULD REALLY
	// BE DONE FROM A FILE, NOT HARD CODED
	initWRgui(worldRenderingGame);

	// SPECIFY WHO WILL HANDLE BUTTON EVENTS
	WRButtonEventHandler *eventHandler = new WRButtonEventHandler();
	GameGUI *gui = worldRenderingGame->getGUI();
	gui->registerButtonEventHandler((ButtonEventHandler*)eventHandler);

	// SPECIFY WHO WILL HANDLE KEY EVENTS
	WRKeyEventHandler *keyHandler = new WRKeyEventHandler();
	input->registerKeyHandler((KeyEventHandler*)keyHandler);

	GameWorld *world = worldRenderingGame->getWorld();
	dataloader = worldRenderingGame->getDataLoader();

	// START THE GAME LOOP
	worldRenderingGame->runGameLoop();

	return 0;
}
コード例 #11
0
/*
	initWRgui - This method builds a GUI for the Empty Game application.
	Note that we load all the GUI components from this method, including
	the ScreenGUI with Buttons and Overlays and the Cursor.
*/
void initWRgui(Game *game)
{
	GameGraphics *graphics = game->getGraphics();
	GameDataLoader *dataLoader = game->getDataLoader();
	GameGUI *gui = game->getGUI();
	DirectXTextureManager *guiTextureManager = (DirectXTextureManager*)graphics->getGUITextureManager();

	// COLOR USED FOR RENDERING TEXT
	graphics->setFontColor(255, 255, 255);

	// COLOR KEY - COLOR TO BE IGNORED WHEN LOADING AN IMAGE
	graphics->setColorKey(96, 128, 224);

		// SETUP THE CURSOR
	vector<int> *imageIDs = new vector<int>();

	PlayerStatsGui *screenGUI = new PlayerStatsGui();
	Player *playerObject = game->getPlayerObject();
	OverlayImage *imageToAdd;
	Button *buttonToAdd;
	wchar_t *buttonCommand;
	int normalTextureID;
	int mouseOverTextureID;
	int initX;
	int initY;
	int initWidth;
	int initHeight;

	file = game->getDataLoader()->getGameMenuFile();

	using namespace std;
	wchar_t *value;
	ifstream inputFile;
	string lineRead;
	inputFile.open(file);
	if (inputFile)
	{
		char inputLine[255];
		stringstream ss;
		while (getline(inputFile, lineRead))
		{
			ss<<lineRead;
			while(getline(ss,lineRead,','))
			{
				if(lineRead.compare("cursor")==0)
				{
					getline(ss,lineRead,',');
					fileName= dataLoader->stringToLCPWSTR(lineRead);
					imageID = guiTextureManager->loadTexture(fileName);
					imageIDs->push_back(imageID);
					Cursor *cursor = new Cursor();
					cursor->initCursor(	imageIDs,
						*(imageIDs->begin()),
						0,
						0,
						0,
						255,
						32,
						32);
					gui->setCursor(cursor);
				}
				else if (lineRead.compare("splashScreen")==0)
				{
					getline(ss, lineRead, ',');
					screenGUI = new PlayerStatsGui();
					fileName = constructEmptyWCHAR_TArray(dataLoader->stringToLCPWSTR(lineRead));
					imageID = guiTextureManager->loadTexture(fileName);
					imageToAdd = new OverlayImage();
					getline(ss, lineRead, ',');
					imageToAdd->x = atoi(lineRead.c_str());
					getline(ss, lineRead, ',');
					imageToAdd->y = atoi(lineRead.c_str());
					imageToAdd->z = 0;
					imageToAdd->alpha = 200;
					getline(ss, lineRead, ',');
					imageToAdd->width = atoi(lineRead.c_str());
					getline(ss, lineRead, ',');
					imageToAdd->height = atoi(lineRead.c_str());
					imageToAdd->imageID = imageID;
					screenGUI->addOverlayImage(imageToAdd);
					gui->addScreenGUI(screenGUI);
				}
				else if (lineRead.compare("exit")==0)
				{
					buttonToAdd = new Button();
					buttonCommand = constructEmptyWCHAR_TArray(L"Exit");
					getline(ss, lineRead, ',');
					fileName = constructEmptyWCHAR_TArray(dataLoader->stringToLCPWSTR(lineRead));
					normalTextureID = guiTextureManager->loadTexture(fileName);
					getline(ss, lineRead, ',');
					fileName = constructEmptyWCHAR_TArray(dataLoader->stringToLCPWSTR(lineRead));
					mouseOverTextureID = guiTextureManager->loadTexture(fileName);
					getline(ss, lineRead, ',');
					initX = atoi(lineRead.c_str());
					getline(ss, lineRead, ',');
					initY = atoi(lineRead.c_str());
					getline(ss, lineRead, ',');
					initWidth = atoi(lineRead.c_str());
					getline(ss, lineRead, ',');
					initHeight = atoi(lineRead.c_str());
					buttonToAdd->initButton(normalTextureID, 
							mouseOverTextureID,
							initX,
							initY,
							0,
							255,
							initWidth,
							initHeight,
							false,
							buttonCommand);
					screenGUI->addButton(buttonToAdd);
				}
				else if (lineRead.compare("startGame")==0)
				{
					buttonToAdd = new Button();
					buttonCommand = constructEmptyWCHAR_TArray(L"Start");
					getline(ss, lineRead, ',');
					fileName = constructEmptyWCHAR_TArray(dataLoader->stringToLCPWSTR(lineRead));
					normalTextureID = guiTextureManager->loadTexture(fileName);
					getline(ss, lineRead, ',');
					fileName = constructEmptyWCHAR_TArray(dataLoader->stringToLCPWSTR(lineRead));
					mouseOverTextureID = guiTextureManager->loadTexture(fileName);
					getline(ss, lineRead, ',');
					initX = atoi(lineRead.c_str());
					getline(ss, lineRead, ',');
					initY = atoi(lineRead.c_str());
					getline(ss, lineRead, ',');
					initWidth = atoi(lineRead.c_str());
					getline(ss, lineRead, ',');
					initHeight = atoi(lineRead.c_str());
					buttonToAdd->initButton(normalTextureID, 
							mouseOverTextureID,
							initX,
							initY,
							0,
							255,
							initWidth,
							initHeight,
							false,
							buttonCommand);
					screenGUI->addButton(buttonToAdd);
				}
				else if (lineRead.compare("about")==0)
				{
					buttonToAdd = new Button();
					buttonCommand = constructEmptyWCHAR_TArray(L"About");
					getline(ss, lineRead, ',');
					fileName = constructEmptyWCHAR_TArray(dataLoader->stringToLCPWSTR(lineRead));
					normalTextureID = guiTextureManager->loadTexture(fileName);
					getline(ss, lineRead, ',');
					fileName = constructEmptyWCHAR_TArray(dataLoader->stringToLCPWSTR(lineRead));
					mouseOverTextureID = guiTextureManager->loadTexture(fileName);
					getline(ss, lineRead, ',');
					initX = atoi(lineRead.c_str());
					getline(ss, lineRead, ',');
					initY = atoi(lineRead.c_str());
					getline(ss, lineRead, ',');
					initWidth = atoi(lineRead.c_str());
					getline(ss, lineRead, ',');
					initHeight = atoi(lineRead.c_str());
					buttonToAdd->initButton(normalTextureID, 
							mouseOverTextureID,
							initX,
							initY,
							0,
							255,
							initWidth,
							initHeight,
							false,
							buttonCommand);
					screenGUI->addButton(buttonToAdd);
				}
				else if (lineRead.compare("controls")==0)
				{
					buttonToAdd = new Button();
					buttonCommand = constructEmptyWCHAR_TArray(L"Controls");
					getline(ss, lineRead, ',');
					fileName = constructEmptyWCHAR_TArray(dataLoader->stringToLCPWSTR(lineRead));
					normalTextureID = guiTextureManager->loadTexture(fileName);
					getline(ss, lineRead, ',');
					fileName = constructEmptyWCHAR_TArray(dataLoader->stringToLCPWSTR(lineRead));
					mouseOverTextureID = guiTextureManager->loadTexture(fileName);
					getline(ss, lineRead, ',');
					initX = atoi(lineRead.c_str());
					getline(ss, lineRead, ',');
					initY = atoi(lineRead.c_str());
					getline(ss, lineRead, ',');
					initWidth = atoi(lineRead.c_str());
					getline(ss, lineRead, ',');
					initHeight = atoi(lineRead.c_str());
					buttonToAdd->initButton(normalTextureID, 
							mouseOverTextureID,
							initX,
							initY,
							0,
							255,
							initWidth,
							initHeight,
							false,
							buttonCommand);
					screenGUI->addButton(buttonToAdd);
				}
				else if (lineRead.compare("help")==0)
				{
					buttonToAdd = new Button();
					buttonCommand = constructEmptyWCHAR_TArray(L"Help");
					getline(ss, lineRead, ',');
					fileName = constructEmptyWCHAR_TArray(dataLoader->stringToLCPWSTR(lineRead));
					normalTextureID = guiTextureManager->loadTexture(fileName);
					getline(ss, lineRead, ',');
					fileName = constructEmptyWCHAR_TArray(dataLoader->stringToLCPWSTR(lineRead));
					mouseOverTextureID = guiTextureManager->loadTexture(fileName);
					getline(ss, lineRead, ',');
					initX = atoi(lineRead.c_str());
					getline(ss, lineRead, ',');
					initY = atoi(lineRead.c_str());
					getline(ss, lineRead, ',');
					initWidth = atoi(lineRead.c_str());
					getline(ss, lineRead, ',');
					initHeight = atoi(lineRead.c_str());
					buttonToAdd->initButton(normalTextureID, 
							mouseOverTextureID,
							initX,
							initY,
							0,
							255,
							initWidth,
							initHeight,
							false,
							buttonCommand);
					screenGUI->addButton(buttonToAdd);
				}
				else if (lineRead.compare("equip")==0)
				{
					buttonToAdd = new Button();
					buttonCommand = constructEmptyWCHAR_TArray(L"Equip");
					getline(ss, lineRead, ',');
					fileName = constructEmptyWCHAR_TArray(dataLoader->stringToLCPWSTR(lineRead));
					normalTextureID = guiTextureManager->loadTexture(fileName);
					getline(ss, lineRead, ',');
					fileName = constructEmptyWCHAR_TArray(dataLoader->stringToLCPWSTR(lineRead));
					mouseOverTextureID = guiTextureManager->loadTexture(fileName);
					getline(ss, lineRead, ',');
					initX = atoi(lineRead.c_str());
					getline(ss, lineRead, ',');
					initY = atoi(lineRead.c_str());
					getline(ss, lineRead, ',');
					initWidth = atoi(lineRead.c_str());
					getline(ss, lineRead, ',');
					initHeight = atoi(lineRead.c_str());
					buttonToAdd->initButton(normalTextureID, 
							mouseOverTextureID,
							initX,
							initY,
							0,
							255,
							initWidth,
							initHeight,
							false,
							buttonCommand);
					screenGUI->addButton(buttonToAdd);
				}
				else if (lineRead.compare("controlsScreen")==0)
				{
					getline(ss, lineRead, ',');
					screenGUI = new PlayerStatsGui();
					fileName = constructEmptyWCHAR_TArray(dataLoader->stringToLCPWSTR(lineRead));
					imageID = guiTextureManager->loadTexture(fileName);
					imageToAdd = new OverlayImage();
					getline(ss, lineRead, ',');
					imageToAdd->x = atoi(lineRead.c_str());
					getline(ss, lineRead, ',');
					imageToAdd->y = atoi(lineRead.c_str());
					imageToAdd->z = 0;
					imageToAdd->alpha = 200;
					getline(ss, lineRead, ',');
					imageToAdd->width = atoi(lineRead.c_str());
					getline(ss, lineRead, ',');
					imageToAdd->height = atoi(lineRead.c_str());
					imageToAdd->imageID = imageID;
					screenGUI->addOverlayImage(imageToAdd);
					gui->addScreenGUI(screenGUI);
				}
				else if (lineRead.compare("back")==0)
				{
					buttonToAdd = new Button();
					buttonCommand = constructEmptyWCHAR_TArray(L"Back");
					getline(ss, lineRead, ',');
					fileName = constructEmptyWCHAR_TArray(dataLoader->stringToLCPWSTR(lineRead));
					normalTextureID = guiTextureManager->loadTexture(fileName);
					getline(ss, lineRead, ',');
					fileName = constructEmptyWCHAR_TArray(dataLoader->stringToLCPWSTR(lineRead));
					mouseOverTextureID = guiTextureManager->loadTexture(fileName);
					getline(ss, lineRead, ',');
					initX = atoi(lineRead.c_str());
					getline(ss, lineRead, ',');
					initY = atoi(lineRead.c_str());
					getline(ss, lineRead, ',');
					initWidth = atoi(lineRead.c_str());
					getline(ss, lineRead, ',');
					initHeight = atoi(lineRead.c_str());
					buttonToAdd->initButton(normalTextureID, 
							mouseOverTextureID,
							initX,
							initY,
							0,
							255,
							initWidth,
							initHeight,
							false,
							buttonCommand);
					screenGUI->addButton(buttonToAdd);
				}
				else if (lineRead.compare("restart")==0)
				{
					buttonToAdd = new Button();
					buttonCommand = constructEmptyWCHAR_TArray(L"Restart");
					getline(ss, lineRead, ',');
					fileName = constructEmptyWCHAR_TArray(dataLoader->stringToLCPWSTR(lineRead));
					normalTextureID = guiTextureManager->loadTexture(fileName);
					getline(ss, lineRead, ',');
					fileName = constructEmptyWCHAR_TArray(dataLoader->stringToLCPWSTR(lineRead));
					mouseOverTextureID = guiTextureManager->loadTexture(fileName);
					getline(ss, lineRead, ',');
					initX = atoi(lineRead.c_str());
					getline(ss, lineRead, ',');
					initY = atoi(lineRead.c_str());
					getline(ss, lineRead, ',');
					initWidth = atoi(lineRead.c_str());
					getline(ss, lineRead, ',');
					initHeight = atoi(lineRead.c_str());
					buttonToAdd->initButton(normalTextureID, 
							mouseOverTextureID,
							initX,
							initY,
							0,
							255,
							initWidth,
							initHeight,
							false,
							buttonCommand);
					screenGUI->addButton(buttonToAdd);
				}
				else if (lineRead.compare("resume")==0)
				{
					buttonToAdd = new Button();
					buttonCommand = constructEmptyWCHAR_TArray(L"Resume");
					getline(ss, lineRead, ',');
					fileName = constructEmptyWCHAR_TArray(dataLoader->stringToLCPWSTR(lineRead));
					normalTextureID = guiTextureManager->loadTexture(fileName);
					getline(ss, lineRead, ',');
					fileName = constructEmptyWCHAR_TArray(dataLoader->stringToLCPWSTR(lineRead));
					mouseOverTextureID = guiTextureManager->loadTexture(fileName);
					getline(ss, lineRead, ',');
					initX = atoi(lineRead.c_str());
					getline(ss, lineRead, ',');
					initY = atoi(lineRead.c_str());
					getline(ss, lineRead, ',');
					initWidth = atoi(lineRead.c_str());
					getline(ss, lineRead, ',');
					initHeight = atoi(lineRead.c_str());
					buttonToAdd->initButton(normalTextureID, 
							mouseOverTextureID,
							initX,
							initY,
							0,
							255,
							initWidth,
							initHeight,
							false,
							buttonCommand);
					screenGUI->addButton(buttonToAdd);
				}
				else if (lineRead.compare("helpScreen")==0)
				{
					getline(ss, lineRead, ',');
					screenGUI = new PlayerStatsGui();
					fileName = constructEmptyWCHAR_TArray(dataLoader->stringToLCPWSTR(lineRead));
					imageID = guiTextureManager->loadTexture(fileName);
					imageToAdd = new OverlayImage();
					getline(ss, lineRead, ',');
					imageToAdd->x = atoi(lineRead.c_str());
					getline(ss, lineRead, ',');
					imageToAdd->y = atoi(lineRead.c_str());
					imageToAdd->z = 0;
					imageToAdd->alpha = 200;
					getline(ss, lineRead, ',');
					imageToAdd->width = atoi(lineRead.c_str());
					getline(ss, lineRead, ',');
					imageToAdd->height = atoi(lineRead.c_str());
					imageToAdd->imageID = imageID;
					screenGUI->addOverlayImage(imageToAdd);
					gui->addScreenGUI(screenGUI);
				}
				else if (lineRead.compare("aboutScreen")==0)
				{
					getline(ss, lineRead, ',');
					screenGUI = new PlayerStatsGui();
					fileName = constructEmptyWCHAR_TArray(dataLoader->stringToLCPWSTR(lineRead));
					imageID = guiTextureManager->loadTexture(fileName);
					imageToAdd = new OverlayImage();
					getline(ss, lineRead, ',');
					imageToAdd->x = atoi(lineRead.c_str());
					getline(ss, lineRead, ',');
					imageToAdd->y = atoi(lineRead.c_str());
					imageToAdd->z = 0;
					imageToAdd->alpha = 200;
					getline(ss, lineRead, ',');
					imageToAdd->width = atoi(lineRead.c_str());
					getline(ss, lineRead, ',');
					imageToAdd->height = atoi(lineRead.c_str());
					imageToAdd->imageID = imageID;
					screenGUI->addOverlayImage(imageToAdd);
					gui->addScreenGUI(screenGUI);
				}
				else if (lineRead.compare("gameOverScreen")==0)
				{
					getline(ss, lineRead, ',');
					screenGUI = new PlayerStatsGui();
					fileName = constructEmptyWCHAR_TArray(dataLoader->stringToLCPWSTR(lineRead));
					imageID = guiTextureManager->loadTexture(fileName);
					imageToAdd = new OverlayImage();
					getline(ss, lineRead, ',');
					imageToAdd->x = atoi(lineRead.c_str());
					getline(ss, lineRead, ',');
					imageToAdd->y = atoi(lineRead.c_str());
					imageToAdd->z = 0;
					imageToAdd->alpha = 200;
					getline(ss, lineRead, ',');
					imageToAdd->width = atoi(lineRead.c_str());
					getline(ss, lineRead, ',');
					imageToAdd->height = atoi(lineRead.c_str());
					imageToAdd->imageID = imageID;
					screenGUI->addOverlayImage(imageToAdd);
					gui->addScreenGUI(screenGUI);
				}
				else if (lineRead.compare("inGameScreen")==0)
				{
					screenGUI = new PlayerStatsGui();
					getline(ss, lineRead, ',');
					fileName = constructEmptyWCHAR_TArray(dataLoader->stringToLCPWSTR(lineRead));
					imageID = guiTextureManager->loadTexture(fileName);
					imageToAdd = new OverlayImage();
					getline(ss, lineRead, ',');
					imageToAdd->x = atoi(lineRead.c_str());
					getline(ss, lineRead, ',');
					imageToAdd->y = atoi(lineRead.c_str());
					imageToAdd->z = 0;
					imageToAdd->alpha = 255;
					getline(ss, lineRead, ',');
					imageToAdd->width = atoi(lineRead.c_str());
					getline(ss, lineRead, ',');
					imageToAdd->height = atoi(lineRead.c_str());
					imageToAdd->imageID = imageID;
					screenGUI->addOverlayImage(imageToAdd);

					//equipBar images
					
					
					fileName = constructEmptyWCHAR_TArray(dataLoader->stringToLCPWSTR("textures/gui/overlays/itemButton.png"));
					int inventoryButtonID = guiTextureManager->loadTexture(fileName);
					Item *itemtorender = new Item();
					itemtorender->imageID = inventoryButtonID;
					playerObject->setAtkEquipped(itemtorender);
					playerObject->setMscEquipped(itemtorender);
					//initialize inventory empty images
					dataloader->clearInventory(game);
					/*for (int i=0; i<15; i++)
					{
						playerObject->setInventoryImage(i,inventoryButtonID);
					}*/

					//hp images
					while(getline(ss, lineRead, ','))
					{
						fileName = constructEmptyWCHAR_TArray(dataLoader->stringToLCPWSTR(lineRead));
						imageID = guiTextureManager->loadTexture(fileName);
						imageToAdd = new OverlayImage();
						getline(ss, lineRead, ',');
						imageToAdd->x = atoi(lineRead.c_str());
						getline(ss, lineRead, ',');
						imageToAdd->y = atoi(lineRead.c_str());
						imageToAdd->z = 0;
						imageToAdd->alpha = 255;
						getline(ss, lineRead, ',');
						imageToAdd->width = atoi(lineRead.c_str());
						getline(ss, lineRead, ',');
						imageToAdd->height = atoi(lineRead.c_str());
						imageToAdd->imageID = imageID;
						playerObject->addHPIcon(imageToAdd);
						playerObject->resetHP(playerObject->getHPImages());
					}
					screenGUI->setHPBar(playerObject->getHPBar());
					screenGUI->setEquipBar(playerObject->getEquipBar());
					gui->addScreenGUI(screenGUI);

				}
				else if (lineRead.compare("pauseScreen")==0)
				{
					getline(ss, lineRead, ',');
					screenGUI = new PlayerStatsGui();
					fileName = constructEmptyWCHAR_TArray(dataLoader->stringToLCPWSTR(lineRead));
					imageID = guiTextureManager->loadTexture(fileName);
					imageToAdd = new OverlayImage();
					getline(ss, lineRead, ',');
					imageToAdd->x = atoi(lineRead.c_str());
					getline(ss, lineRead, ',');
					imageToAdd->y = atoi(lineRead.c_str());
					imageToAdd->z = 0;
					imageToAdd->alpha = 200;
					getline(ss, lineRead, ',');
					imageToAdd->width = atoi(lineRead.c_str());
					getline(ss, lineRead, ',');
					imageToAdd->height = atoi(lineRead.c_str());
					imageToAdd->imageID = imageID;
					screenGUI->addOverlayImage(imageToAdd);

					getline(ss, lineRead, ',');
					fileName = constructEmptyWCHAR_TArray(dataLoader->stringToLCPWSTR(lineRead));
					imageID = guiTextureManager->loadTexture(fileName);
					imageToAdd = new OverlayImage();
					getline(ss, lineRead, ',');
					imageToAdd->x = atoi(lineRead.c_str());
					getline(ss, lineRead, ',');
					imageToAdd->y = atoi(lineRead.c_str());
					imageToAdd->z = 0;
					imageToAdd->alpha = 255;
					getline(ss, lineRead, ',');
					imageToAdd->width = atoi(lineRead.c_str());
					getline(ss, lineRead, ',');
					imageToAdd->height = atoi(lineRead.c_str());
					imageToAdd->imageID = imageID;
					screenGUI->addOverlayImage(imageToAdd);
					screenGUI->setHPBar(playerObject->getHPBar());
					screenGUI->setEquipBar(playerObject->getEquipBar());
					gui->addScreenGUI(screenGUI);
				}
				else if (lineRead.compare("inventory")==0)
				{
					getline(ss, lineRead, ',');
					screenGUI = new PlayerStatsGui();
					fileName = constructEmptyWCHAR_TArray(dataLoader->stringToLCPWSTR(lineRead));
					imageID = guiTextureManager->loadTexture(fileName);
					imageToAdd = new OverlayImage();
					getline(ss, lineRead, ',');
					imageToAdd->x = atoi(lineRead.c_str());
					getline(ss, lineRead, ',');
					imageToAdd->y = atoi(lineRead.c_str());
					imageToAdd->z = 0;
					imageToAdd->alpha = 200;
					getline(ss, lineRead, ',');
					imageToAdd->width = atoi(lineRead.c_str());
					getline(ss, lineRead, ',');
					imageToAdd->height = atoi(lineRead.c_str());
					imageToAdd->imageID = imageID;
					screenGUI->addOverlayImage(imageToAdd);

					getline(ss, lineRead, ',');
					fileName = constructEmptyWCHAR_TArray(dataLoader->stringToLCPWSTR(lineRead));
					imageID = guiTextureManager->loadTexture(fileName);
					imageToAdd = new OverlayImage();
					getline(ss, lineRead, ',');
					imageToAdd->x = atoi(lineRead.c_str());
					getline(ss, lineRead, ',');
					imageToAdd->y = atoi(lineRead.c_str());
					imageToAdd->z = 0;
					imageToAdd->alpha = 255;
					getline(ss, lineRead, ',');
					imageToAdd->width = atoi(lineRead.c_str());
					getline(ss, lineRead, ',');
					imageToAdd->height = atoi(lineRead.c_str());
					imageToAdd->imageID = imageID;
					screenGUI->addOverlayImage(imageToAdd);
					screenGUI->setHPBar(playerObject->getHPBar());
					screenGUI->setEquipBar(playerObject->getEquipBar());
					playerObject->updateInventoryBar(playerObject->getInventoryImages());
					screenGUI->setInventoryBar(playerObject->getInventoryBar());
					for (int i = 0; i <15;i++)
					{
						buttonToAdd = new Button();
						stringstream out;
						out << i;
						string buttonName = "item" + out.str();
						buttonCommand = constructEmptyWCHAR_TArray(dataLoader->stringToLCPWSTR(buttonName));
						fileName = constructEmptyWCHAR_TArray(dataLoader->stringToLCPWSTR("textures/gui/overlays/itemButton.png"));
						normalTextureID = guiTextureManager->loadTexture(fileName);
						mouseOverTextureID = guiTextureManager->loadTexture(fileName);
						initX = (290 + 8 + (i%5)*95);
						initY = (450 + 8 + (i/5)*90);
						initWidth = 50;
						initHeight = 50;
						buttonToAdd->initButton(normalTextureID, 
							mouseOverTextureID,
							initX,
							initY,
							0,
							255,
							initWidth,
							initHeight,
							false,
							buttonCommand);
						screenGUI->addButton(buttonToAdd);
					}
					gui->addScreenGUI(screenGUI);
				}
				else if (lineRead.compare("inventoryRow")==0)
				{
					getline(ss, lineRead, ',');
					fileName = constructEmptyWCHAR_TArray(dataLoader->stringToLCPWSTR(lineRead));
					imageID = guiTextureManager->loadTexture(fileName);
					imageToAdd = new OverlayImage();
					getline(ss, lineRead, ',');
					imageToAdd->x = atoi(lineRead.c_str());
					getline(ss, lineRead, ',');
					imageToAdd->y = atoi(lineRead.c_str());
					imageToAdd->z = 0;
					imageToAdd->alpha = 255;
					getline(ss, lineRead, ',');
					imageToAdd->width = atoi(lineRead.c_str());
					getline(ss, lineRead, ',');
					imageToAdd->height = atoi(lineRead.c_str());
					imageToAdd->imageID = imageID;
					screenGUI->addOverlayImage(imageToAdd);
				}
				else if (lineRead.compare("checkScreen")==0)
				{
					getline(ss, lineRead, ',');
					screenGUI = new PlayerStatsGui();
					fileName = constructEmptyWCHAR_TArray(dataLoader->stringToLCPWSTR(lineRead));
					imageID = guiTextureManager->loadTexture(fileName);
					imageToAdd = new OverlayImage();
					getline(ss, lineRead, ',');
					imageToAdd->x = atoi(lineRead.c_str());
					getline(ss, lineRead, ',');
					imageToAdd->y = atoi(lineRead.c_str());
					imageToAdd->z = 0;
					imageToAdd->alpha = 200;
					getline(ss, lineRead, ',');
					imageToAdd->width = atoi(lineRead.c_str());
					getline(ss, lineRead, ',');
					imageToAdd->height = atoi(lineRead.c_str());
					imageToAdd->imageID = imageID;
					screenGUI->addOverlayImage(imageToAdd);

					getline(ss, lineRead, ',');
					fileName = constructEmptyWCHAR_TArray(dataLoader->stringToLCPWSTR(lineRead));
					imageID = guiTextureManager->loadTexture(fileName);
					imageToAdd = new OverlayImage();
					getline(ss, lineRead, ',');
					imageToAdd->x = atoi(lineRead.c_str());
					getline(ss, lineRead, ',');
					imageToAdd->y = atoi(lineRead.c_str());
					imageToAdd->z = 0;
					imageToAdd->alpha = 255;
					getline(ss, lineRead, ',');
					imageToAdd->width = atoi(lineRead.c_str());
					getline(ss, lineRead, ',');
					imageToAdd->height = atoi(lineRead.c_str());
					imageToAdd->imageID = imageID;
					screenGUI->addOverlayImage(imageToAdd);
					screenGUI->setHPBar(playerObject->getHPBar());
					screenGUI->setEquipBar(playerObject->getEquipBar());
					gui->addScreenGUI(screenGUI);

					/////////////////////////////
				}
			}
			ss.clear();
		}
	}

}
コード例 #12
0
ファイル: GameGUIBuilder.cpp プロジェクト: realej/mk-tp-7542
GameGUI* GameGUIBuilder::createDefault() {

    FILE_LOG(logDEBUG) << "Entire configuration set by default";
    GameGUI *gameGUI = GameGUI::getInstance();

    //window by default
    int windowXpos = ((MAX_WINDOW_WIDTH_PX-DEFAULT_WINDOW_WIDTH_PX)/2);
    int windowYpos = ((MAX_WINDOW_HEIGHT_PX-DEFAULT_WINDOW_HEIGHT_PX)/2);
    Window* ptrWindow = new Window(GAME_TITLE, windowXpos, windowYpos, DEFAULT_WINDOW_WIDTH_PX, DEFAULT_WINDOW_HEIGHT_PX, DEFAULT_WINDOW_WIDTH);
    FILE_LOG(logDEBUG) << "JSON - Window width: " << DEFAULT_WINDOW_WIDTH_PX << " px";
    FILE_LOG(logDEBUG) << "JSON - Window height: " << DEFAULT_WINDOW_HEIGHT_PX << " px";
    FILE_LOG(logDEBUG) << "JSON - Window width: " << DEFAULT_WINDOW_WIDTH;

    gameGUI->setWindow(ptrWindow);

    //stage by default
    Stage* ptrStage = new Stage(DEFAULT_STAGE_WIDTH, DEFAULT_STAGE_HEIGHT, DEFAULT_STAGE_YFLOOR);
    FILE_LOG(logDEBUG) << "JSON - Stage width: " << DEFAULT_STAGE_WIDTH;
    FILE_LOG(logDEBUG) << "JSON - Stage height: " << DEFAULT_STAGE_HEIGHT;
    FILE_LOG(logDEBUG) << "JSON - Stage ypiso: " << DEFAULT_STAGE_YFLOOR;

    gameGUI->setStage(ptrStage);

    float ratioX = getRatio(DEFAULT_WINDOW_WIDTH_PX, DEFAULT_WINDOW_WIDTH,"X");
    float ratioY = getRatio(DEFAULT_WINDOW_HEIGHT_PX, DEFAULT_STAGE_HEIGHT,"Y");

    TextureManager::Instance()->ratioHeight = ratioY;
    TextureManager::Instance()->ratioWidth = ratioX;

    //characters by default
    vector<Character*> characters;

    //TODO put in constant
    float character_width = DEFAULT_CHARACTER_WIDTH;
    float character_height = DEFAULT_CHARACTER_HEIGHT;
    int character_zindex = DEFAULT_CHARACTER_ZINDEX;
    string character_name = "default";
    float characterPosX = 0;
    float stage_win_ypiso = DEFAULT_STAGE_YFLOOR;
    float characterPosY = (stage_win_ypiso - character_height) * ratioY;
    double character_alt_color_h_inicial = 180;
    double character_alt_color_h_final = 300;
    double character_alt_color_shift = 60;
    LoaderParams* characterParams = new LoaderParams(characterPosX, characterPosY, character_width, character_height, character_zindex, ratioX, ratioY, character_name);
    AlternativeColor* altColor = new AlternativeColor(character_alt_color_h_inicial, character_alt_color_h_final, character_alt_color_shift);

    Character* fighterOne = new Character(characterParams);
    fighterOne->setPlayerNumber("1");
    fighterOne->setAlternativeColor(altColor);
    fighterOne->setPositionX(GameGUI::getInstance()->getWindow()->widthPx / 4 - fighterOne->getWidth() * fighterOne->getRatioX()/2);
    fighterOne->setIsRightOriented(true);
    Character* fighterTwo = fighterOne->getCopyInstance();
    fighterTwo->setPlayerNumber("2");
    fighterTwo->setPositionX((GameGUI::getInstance()->getWindow()->widthPx / 4)*3 -  fighterTwo->getWidth() * fighterTwo->getRatioX()/2);
    fighterTwo->setIsAlternativePlayer(true);
    fighterTwo->setIsRightOriented(false);
    Fight* fight = new Fight();
    fight->setFighterOne(fighterOne);
    fight->setFighterTwo(fighterTwo);

    characters.push_back(fight->getFighterOne());
    characters.push_back(fight->getFighterTwo());

    MKGame::Instance()->getObjectList().push_back(fight->getFighterOne());
    MKGame::Instance()->getObjectList().push_back(fight->getFighterTwo());
    gameGUI->setCharacters(characters);
    delete fight;

    //Add layers to the game loop
    gameGUI->setLayers(buildLayersByDefault(ratioX, ratioY, ptrWindow, ptrStage));

    //createGameInfo(ptrWindow, characters, ratioX, ratioY);

    //createThrowableObject(characters, ptrWindow, ratioX, ratioY);

    InputControl::Instance()->loadDefaultButtons(0);
    InputControl::Instance()->loadDefaultButtons(1);

    FILE_LOG(logDEBUG) << "Configuration process finished";
    return gameGUI;

}
コード例 #13
0
ファイル: GameGUIBuilder.cpp プロジェクト: realej/mk-tp-7542
GameGUI* GameGUIBuilder::create() {
    FILE_LOG(logDEBUG) << "CONFIGURATION INITIALIZED";
    GameGUI *gameGUI = GameGUI::getInstance();

    Json::Value root;
    Json::Reader reader;

    ifstream gameConfig(this->configFilePath.c_str(), std::ifstream::binary);

    if (!gameConfig.good()) {
        MessageError fileNotFound(ERROR_FILE_NOT_FOUND, FILE_CONFIG_NOT_FOUND, LOG_LEVEL_ERROR);
        Log<Output2FILE>::logMsgError(fileNotFound);
        return createDefault();
    }
    bool parsingSuccessful = reader.parse(gameConfig, root, false);

    if (!parsingSuccessful) {
        MessageError parseException(ERROR_PARSER_JSON, reader.getFormattedErrorMessages(), LOG_LEVEL_ERROR);
        Log<Output2FILE>::logMsgError(parseException);
        return createDefault();
    }

    try {
        const Json::Value value1 = root.get(JSON_KEY_PERSONAJES, 0);
        const Json::Value value2 = root.get(JSON_KEY_CAPAS,0);
        Json::Value value3 = root[JSON_KEY_ESCENARIO];
        Json::Value value14 = root[JSON_KEY_VENTANA];
        Json::Value value5 = root[JSON_KEY_PELEA];
        Json::Value value6 = root[JSON_KEY_JOYSTICKS];
        Json::Value value7 = root[JSON_KEY_SECUENCES];
    } catch(std::exception const & e) {
        FILE_LOG(logDEBUG) << "Corrupt JSON File. Exception: "<<e.what();
        return createDefault(); //TODO: Validate create default
    }
    Window* window = jsonGetWindow(root);
    Stage* stage = jsonGetStage(root,window->width);

    gameGUI->setWindow(window);
    gameGUI->setStage(stage);

    float ratioX = getRatio(window->widthPx, window->width,"X");
    float ratioY = getRatio(window->heightPx, stage->getHeight(),"Y");

    TextureManager::Instance()->ratioHeight = ratioY;
    TextureManager::Instance()->ratioWidth = ratioX;

    vector<Layer*> layers = jsonGetLayers(root, ratioX, ratioY, window, stage);
    if (layers.size()==0) {
        layers = buildLayersByDefault(ratioX, ratioY,window,stage);
    }

    vector<Character*> characters = jsonGetCharacters(root, ratioX, ratioY, stage);
    gameGUI->setCharacters(characters);

    //The fight is now being triggered by the MENU
    /*Fight* fight = jsonGetFight(root);
    gameGUI->setFight(fight);
    if (fight->getFighterOne()->getName() == fight->getFighterTwo()->getName()) {
    	fight->getFighterTwo()->setIsAlternativePlayer(true);
    }
    fight->getFighterOne()->setIsRightOriented(true);
    MKGame::Instance()->getObjectList().push_back(fight->getFighterOne());
    MKGame::Instance()->getObjectList().push_back(fight->getFighterTwo());*/

    gameGUI->setLayers(layers);

    //The fight is now being triggered by the MENU
    //vector<Character*> fightingCharacters;
    //fightingCharacters.push_back(fight->getFighterOne());
    //fightingCharacters.push_back(fight->getFighterTwo());
    /*gameGUI->setCharacters(fightingCharacters);
    createGameInfo(window, fightingCharacters, ratioX, ratioY);
    createThrowableObject(fightingCharacters, window, ratioX, ratioY);*/


    jsonGetJoysticks(root);

    jsonGetSecuences(root);

    vector<VisualEffect*> visualEffects = createVisualEffects(ratioX, ratioY, window, stage);

    gameGUI->setVisualEffects(visualEffects);

    FILE_LOG(logDEBUG) << "CONFIGURATION FINISHED";

    return gameGUI;
}
コード例 #14
0
ファイル: DirectXGraphics.cpp プロジェクト: Knoth77/Odyssey
void DirectXGraphics::renderWorldRenderList()
{
	worldRenderList->resetIterator();
	RenderItem itemToRender;
	LPDIRECT3DTEXTURE9 texture;
	RECT *rect = NULL;
	GameGUI *gui = game->getGUI();
	Viewport *viewport = gui->getViewport();

	// GO THROUGH EACH ITEM IN THE LIST
	while (worldRenderList->hasNext())
	{
		if (rect != NULL)
			delete rect;
		rect = NULL;
		itemToRender = worldRenderList->next();
		
		// LET'S GET THE TEXTURE WE WANT TO RENDER
		int id = itemToRender.id;
		if (id >= 0)
		{
			texture = ((DirectXTextureManager*)worldTextureManager)->getTexture(id);
			D3DXVECTOR3 position = D3DXVECTOR3(	(FLOAT)(itemToRender.x),
											(FLOAT)(itemToRender.y),
												0);

			if (id == 97)
			{
				int breakHere = 2;
				breakHere++;
			}


			position.x += viewport->getViewportOffsetX();
			position.y += viewport->getViewportOffsetY();

			// ADJUST FOR THE GUI OFFSET
			if (((position.x < viewport->getViewportOffsetX())
				|| (position.y < viewport->getViewportOffsetY())) && itemToRender.rotationInRadians == 0.0)
			{
				IDirect3DSurface9 *surface;
				UINT level = 0;
				HRESULT result = texture->GetSurfaceLevel(level, &surface);
				D3DSURFACE_DESC surfaceDescription;
				surface->GetDesc(&surfaceDescription);
				rect = new RECT();
				rect->left = 0;
				rect->top = 0;
				rect->right = surfaceDescription.Width;
				rect->bottom = surfaceDescription.Height;
				if (position.x < viewport->getViewportOffsetX())
				{
					int xDiff = viewport->getViewportOffsetX() - (int)position.x;
					rect->left = xDiff;
					position.x += xDiff;
				}
				if (position.y < viewport->getViewportOffsetY())
				{
					int yDiff = viewport->getViewportOffsetY() - (int)position.y;
					rect->top = yDiff;
					position.y += yDiff;
				}	
			}

			
			
			//D3DXMatrixRotationX()

			D3DXMATRIX trans;
			D3DXMATRIX Omx;
			//spriteHandler->GetTransform(&Omx);
			D3DXMatrixTransformation2D(&trans, NULL, NULL, NULL, &D3DXVECTOR2((position.x) + (itemToRender.width / 2), (position.y) + (itemToRender.height / 2)), itemToRender.rotationInRadians, NULL);
			//Omx *= trans;
			spriteHandler->SetTransform(&trans);		
		

			// RENDER THE OPAQUE ITEMS
			if (itemToRender.a == 255)
			{
				if (FAILED(spriteHandler->Draw(
					texture, 
					rect,
			        NULL,
					&position,
					DEFAULT_ALPHA_COLOR)))
				{
					game->getText()->writeDebugOutput("\nspriteHandler->Draw: FAILED");
				}
			
				// RENDER THE ITEMS WITH CUSTOM TRANSPARENCY
				else
				{
					if (itemToRender.a < 0)
						itemToRender.a = 0;
					else if (itemToRender.a > 255)
						itemToRender.a = 255;

					if (FAILED(spriteHandler->Draw(
						texture,
						rect,
						NULL,
						&position,
						D3DCOLOR_ARGB(itemToRender.a, 255, 255, 255))))
					{
						game->getText()->writeDebugOutput("\nspriteHandler->Draw: FAILED");
					}
				}
			}
		}
	}

	// NOW EMPTY THE LIST, WE'RE ALL DONE WITH IT
	worldRenderList->clear();
	if (rect != NULL)
		delete rect;

	D3DXMATRIX identityMatrix;
	D3DXMatrixIdentity(&identityMatrix);
	spriteHandler->SetTransform(&identityMatrix);

}