예제 #1
0
int main()
{
    sf::RenderWindow app(sf::VideoMode(768, 512), "Cheese Multiplayer - Alpha");

	GameState *gameState = new PlayState(&app);

	//app.SetFramerateLimit(6);

	while (app.IsOpened())
    {
        sf::Event event;
       if (app.GetEvent(event))
        {
            if (event.Type == sf::Event::Closed)
                app.Close();

            gameState->EventUpdate(event);
        }

        GameState *oldState = gameState;
        if((gameState=gameState->Update(app)) != oldState)
        {
            delete oldState;
        }

        app.Clear();

        gameState->Draw(app);

        app.Display();
    }

    return EXIT_SUCCESS;
}
예제 #2
0
/* drawSprites()
 * - this function is what actually draws the sprites
 *   onto the screen at their appropriate location
 * - it actually loops through a list of active sprites
 *   and then sorts them by their layerID and then draws them
 * - the sorting has to happen so that you draw from back to front
 *   just like a painter and a canvas.
 */
void Game::drawSprites()
{
	/* we could just do the following to draw the three sprites
	   but that would be silly since we have a list of sprites to draw
	   stored, so all we need to do is go through the list and draw eaach 
	   sprite in the list */
	/* // silly way 
	testSprite->draw();
	animatedSprite->draw();
	animatedSprite2->draw();
	*/
	
	/* better way */
	/* this is better because it doesn't matter how many sprites we have, they will always be drawn */

	//tassos says:

	// instead of this list, just tell the current game class to draw
	// give it a draw call

	//void GameState::Draw()
	//{


	/*std::vector<Sprite*>::iterator it; 
	for(it=spriteListToDraw.begin(); it != spriteListToDraw.end(); it++)
	{
		Sprite *s = (*it);
		s->draw();
	}*/
//===========================================================================================
//								 SPRITE ITERATOR
//===========================================================================================
	std::vector<GameState*>::iterator it;
	for (it = states.begin(); it != states.end(); it++)
	{
		if (*it)
		{  
			  GameState* s = (*it);
			  if(s->active==true)
			  s->Draw();
		}

	}


}