Example #1
0
// 1 = Play; 0 = Exit Game
bool mainMenu(RenderWindow& window) {

	Rectangle play(299, 505, 435, 501);
	Rectangle exit(299, 505, 539, 605);
	Rectangle info(684, 788, 746, 788);

	Sprite background;
	background.setTexture(menuNothingHighlighted);
	window.draw(background);
	window.display();

	Event event;
	while (true) {

		if (hovering(window, play, event)) {
			background.setTexture(menuPlayHighlighted);
			window.draw(background);
			window.display();
		}
		else if (hovering(window, exit, event)) {
			background.setTexture(menuExitHighlighted);
			window.draw(background);
			window.display();
		}
		else if (hovering(window, info, event)) {
			background.setTexture(menuInfoHighlighted);
			window.draw(background);
			window.display();
		}
		else {
			background.setTexture(menuNothingHighlighted);
			window.draw(background);
			window.display();
		}

		if (!window.pollEvent(event)) continue;

		if (event.type == Event::Closed) return false;
		if (wasClicked(window, play, event)) return true;
		if (wasClicked(window, exit, event)) return false;
		if (wasClicked(window, info, event)) {
			infoScreen(window);
			while (window.pollEvent(event));
			if (!window.isOpen()) return false;
		}
	}

	return false;
}
    void start(RenderWindow& window) {
        Ball ball{windowWidth/2, windowHeight/2};
        Paddle paddle{windowWidth/2, windowHeight - 50};

        vector<Brick> bricks;

        for(int iX{0}; iX < countBlocksX; iX++) {
            for(int iY{0}; iY < countBlocksY; iY++) {
                bricks.emplace_back((iX + 1) * (blockWidth + 3) + 22, (iY + 2) * (blockHeight + 3));
            }
        }
        /*
         * Game Loop
         * */
        while(true) {
            window.clear(Color::Black);

            if(Keyboard::isKeyPressed(Keyboard::Key::Escape)) break;
            ball.update();
            paddle.update();

            testCollision(paddle, ball);
            for(auto& brick : bricks) {
                if(!brick.destroyed) {
                    window.draw(brick.shape);
                }
            }
            hitBrick(bricks, ball);
            window.draw(paddle.shape);
            window.draw(ball.shape);
            window.display();
        }
    }
Example #3
0
void draw_game(RenderWindow &window, Level &lvl, std::list<Entity*>::iterator &it, std::list<Entity*> &entities, PLAYER &Player, PlayerScores &plScores, int levelNumber)
{
	init_font font;
	window.clear(Color(107, 140, 255));

	lvl.Draw(window);

	for (it = entities.begin();it != entities.end();it++)
		(*it)->draw(window);

	Player.draw(window);
	plScores.draw(window, levelNumber);

	if (Player.isWin)
	{
		font.textFinish.setPosition(view.getCenter().x - 120, view.getCenter().y);
		window.draw(font.textFinish);
		font.textWin.setPosition(view.getCenter().x - 200, view.getCenter().y- 20);
		window.draw(font.textWin);
	}
	else
	if (!Player.life)
	{
		font.textFinish.setPosition(view.getCenter().x - 120, view.getCenter().y);
		window.draw(font.textFinish);
		font.textDead.setPosition(view.getCenter().x - 40, view.getCenter().y - 20);
		window.draw(font.textDead);
	}
	window.display();
}
Example #4
0
	void display() {
		window.clear(Color::White);
		switch (gameState) {
		case INTRO:
			window.draw(title);
			window.draw(start);
			break;
		case PLAYING:
			window.draw(left);
			window.draw(right);            
            grid.display(window);
            window.draw(player);    
            window.draw(ball);    
            window.draw(score);    
            window.draw(lives);    
            window.draw(top);
            window.draw(bottom);        
            window.draw(fps);
			break;
		case GAME_WON:
            window.draw(won);
            break;
        case GAME_LOST:
            window.draw(lost);
            break;
		}
		window.display();
	}
Example #5
0
void Game::menu() //menu function
{
    std::cout << "state = MENU\n";

    Button* menuTable[2]; //table of menu buttons
    menuTable[0] = new NewGameButton(Vector2f(300,40), Vector2f(0,0), Color::Green, "New Game" ); //button to the new game
    menuTable[1] = new ExitButton(Vector2f(300,40), Vector2f(0,100), Color::Red, "Exit" ); // button to exit


    while( state == MENU )
    {
        Vector2f mouse(Mouse::getPosition( window )); //mouse handler
		Event event;

		while(window.pollEvent( event ))
		{
            if( event.type == Event::Closed )
                state = END;

            else if( event.type == Event::MouseButtonReleased && event.mouseButton.button == Mouse::Left ) //mouse pressed
                {
                    if ( menuTable[0]->contains( mouse ))
                        state = GAME;
                    else if ( menuTable[1]->contains( mouse ))
                        menuTable[1]->onClick();
                }
		}

		window.clear( Color::White );
		for( int i=0; i<2; i++ )
            window.draw( *menuTable[i] );
		window.display();
    }
}
Example #6
0
File: item.cpp Project: Coguar/TP
void draw(Group & group, RenderWindow & window) 
{
	for(Block &thing: group.blocks)
		window.draw(*thing.block);
	window.display();
	window.clear(Color::White);
}
Example #7
0
void drawing(RenderWindow &window, engine *en) {
	window.clear();
	ostringstream playerHealthString;
	playerHealthString << en->p->health;
	en->txt->healph.setString("" + playerHealthString.str());
	en->map->lvl.Draw(window);
	window.draw(en->txt->healph);
	for (Entity* brick : en->map->listBrick) {
		window.draw(*brick->sprite);
	}
	for (Entity* bonus : en->map->listPointsBonus) {
		window.draw(*bonus->sprite);
	}
	checkForWinOrLosePlayer(en->id, window, en->im, en->txt, en->p);
	window.draw(*en->targetProtecting->sprite);
	for (Entity* entity : en->map->bullesPlayer) {
		window.draw(*entity->sprite);
	}
	for (Entity* entity : en->map->entities) {
		window.draw(*entity->sprite);
	}
	for (Entity* bulles : en->map->bullesEnemy) {
		window.draw(*bulles->sprite);
	}
	for (Entity* enemy : en->map->numberEnemies) {
		window.draw(*enemy->sprite);
	}
	if (en->id->g_appearanceEnemies) window.draw(en->im->spriteAppEnemies);
	window.display();
}
void run_animation(RenderWindow &window)
{
	Clock clock;
	std::vector<initialization_blocks*>  object;
	float x = RECTANGLES_SIZE.x / 2, y = 0;
	int number_block;
	for (int i = 0; i < NUMBER_BLOCKS; i++) {
		y += 10 + RECTANGLES_SIZE.y;
		object.push_back(new initialization_blocks(x, y, i));
	}
	while (window.isOpen())
	{
		Event event;
		while (window.pollEvent(event))
			if (event.type == Event::Closed)
				window.close();

		float time = clock.getElapsedTime().asMicroseconds();
		clock.restart();
		time = time / 800;
		
		window.clear(Color::White);
		number_block = 0;
		for (auto i : object) {
			i->update(time, number_block);
			window.draw(i->rectangle);
			number_block++;
		}
		window.display();
	}
}
Example #9
0
void computerTurnAnimation(RenderWindow& window, Player& human, Player& computer) {

	Sprite message;
	message.setTexture(messageTexture);
	message.setPosition(Vector2f(0, 160));

	Sprite wheel;
	wheel.setTexture(wheelTexture);
	wheel.setOrigin(Vector2f(400, 400));
	wheel.setPosition(Vector2f(400, 400));
	wheel.setScale(Vector2f(0.5, 0.5));
	wheel.setPosition(Vector2f(400, 560));

	Sprite compTurn;
	compTurn.setTexture(compTurnTexture);

	clock_t timer;
	timer = clock();

	while (clock() - timer <= CLOCKS_PER_SEC * float(1.5)) {
		drawGameWindow(window, human, computer);
		window.draw(wheel);
		window.draw(message);
		window.draw(compTurn);
		window.display();
		wheel.setRotation(wheel.getRotation() + 1);
	}
}
Example #10
0
void update_graphics( RenderWindow& fen1, Building& Bataclan, vector<RectangleShape>& walls_ ){
  //Rafraichissement du dessin
  fen1.clear(Color::Black);
  RectangleShape awareness(Vector2f((Pedest::ZONE_XMAX-Pedest::ZONE_XMIN)*Building::ZOOM , (Pedest::ZONE_YMAX-Pedest::ZONE_YMIN)*Building::ZOOM));
  awareness.setPosition(Pedest::ZONE_XMIN*Building::ZOOM, Pedest::ZONE_YMIN*Building::ZOOM);
  awareness.setOutlineThickness(1);
  awareness.setFillColor(Color::Black);
  awareness.setOutlineColor(Color::Red);
  
  for (int i=0; i<Bataclan.width(); i++){
    for (int j=0; j<Bataclan.length(); j++){
      RectangleShape wall(Vector2f(Building::ZOOM,Building::ZOOM));
      wall.setPosition(Building::ZOOM*i, Building::ZOOM*j);
      wall.setOutlineThickness(1);
      wall.setFillColor(Color::Black);
      wall.setOutlineColor(Color::Blue);
      fen1.draw(wall);
    }
  }
  fen1.draw(awareness);
  for (unsigned int j=0; j<walls_.size(); j++){
    fen1.draw(walls_[j]);
  }
  for (int i=0; i<Building::NPEDEST; i++){
    fen1.draw(Bataclan.people(i).img());
  }
  fen1.display();
}
Example #11
0
File: game.cpp Project: Waqee/Chess
//Actual 2-player game
Game::Game(RenderWindow &wind) : GameState(wind),status(0)
{
    //sets end variable to false indicating game is not finished
    end=false;
    wind.clear(); //Clears window
    Chess.reset(wind); //Resets the chess game
	wind.display();
}
Example #12
0
File: Car.cpp Project: Coguar/TP
void Draw(RenderWindow & window, Car & car) {
	window.draw(car.SpriteFrontWheel);
	window.draw(car.SpriteBackWheel);
	window.draw(car.SpritePriora);
	window.draw(car.Road);
	window.display();
	window.clear(Color::White);
}
Example #13
0
//Similar to 2-player game with just 1 difference i.e the function computer turn is called in case of 2nd players turn
comvcom::comvcom(RenderWindow &wind) : GameState(wind)
{
    end=false;
    wind.clear();
    Chess.reset(wind);
    turn = 1;
    wind.display();
}
Example #14
0
//a little bit ugly
string fetchNameFromUser()
{	
	string resultString= "You have ended the game with score:" + std::to_string(score);
	
	Text alphabet [26];

	Text resultText;
	setText(resultText, font, Color::White, 35, resultString, { 200,220 });

	Text enterNameText;
	setText(enterNameText, font, Color::White, 30, "Please Enter Your Name", { 340,300 });

	Text gameOverText;
	setText(gameOverText, font, Color::Red, 40, "GAME OVER", { 370,150 });

	pair <unsigned char, unsigned char> myPair = { 0,0 };
	char chosenLetter = 'A';
	string userName = "******";

	Text providedNameText;

	RectangleShape marker;
	while (window.waitEvent(myEvent))
	{
		window.clear(Color::Black);
		setText(providedNameText, font, Color::White, 30, userName, { 460,360 });
		drawTextes(gameOverText, enterNameText, providedNameText, scoreText,resultText);

		int j = 1;
		int k = 0;

		for (unsigned char i = 0; i<26; ++i)
		{	
			if (0 == i % 13) 
			{
					++j; k=0;
			}
			++k;
			char letter[2] = "A";
			letter[0] = letter[0] + i;
	
			setText(alphabet[i], font, Color::White, 20 , letter , {350.0f+20*k,380.0f+20*j});
			window.draw(alphabet[i]);
		}

		setMarker(marker, alphabet[chosenLetter - 65].getPosition());
		window.draw(marker);
	
		static int i = 0;
		gameOverInput(myEvent, userName, chosenLetter, myPair, i);

		window.display();

		if (3 == i)
			return userName;
	}
}
Example #15
0
void Draw(RenderWindow& window, RectangleStruct rect[QUANTITY])
{
	for (int i = 0; i < QUANTITY; i++)
	{
		window.draw(rect[i].square);
	}
	window.display();
	window.clear(sf::Color::White);
}
Example #16
0
void Turt::window::
animate_window(RenderWindow& window, Graphics& graphics){

	window.clear(sf::Color::Black);

	draw_drawables(window, graphics);
	
	window.display();

}
Example #17
0
void loadingScreen(RenderWindow& window) {
	Text loadingMessage;
	loadingMessage.setFont(infoFont);
	loadingMessage.setColor(Color::Green);
	loadingMessage.setString("Loading...");
	loadingMessage.setPosition(Vector2f(660, 750));
	window.clear(Color::Black);
	window.draw(loadingMessage);
	window.display();
}
Example #18
0
void Game::menu()
{
	Text title("Mechanized Techno Explorer",font,80);
	title.setStyle(Text::Bold);

	title.setPosition(1280/2-title.getGlobalBounds().width/2,20);

	const int ile = 2;

	Text tekst[ile];

	string str[] = {"Play","Exit"};
	for(int i=0;i<ile;i++)
	{
		tekst[i].setFont(font);
		tekst[i].setCharacterSize(65);

		tekst[i].setString(str[i]);
		tekst[i].setPosition(1280/2-tekst[i].getGlobalBounds().width/2,250+i*120);
	}

	while(state == MENU)
	{
		Vector2f mouse(Mouse::getPosition());
		Event event;

		while(window.pollEvent(event))
		{
			//Wciœniêcie ESC lub przycisk X
			if(event.type == Event::Closed || event.type == Event::KeyPressed &&
				event.key.code == Keyboard::Escape)
				state = END;
			
			//klikniêcie EXIT
			else if(tekst[1].getGlobalBounds().contains(mouse) &&
				event.type == Event::MouseButtonReleased && event.key.code == Mouse::Left)
			{
				state = END;
			}
		}
		for(int i=0;i<ile;i++)
			if(tekst[i].getGlobalBounds().contains(mouse))
				tekst[i].setColor(Color::Cyan);
			else tekst[i].setColor(Color::White);
		
		window.clear();
		
		window.draw(title);
		for(int i=0;i<ile;i++)
			window.draw(tekst[i]);

		window.display();
	}
}
Example #19
0
int main(int, char const**)
{
    // Create the main window
    RenderWindow window;
    window.create(VideoMode(800, 600), "Pong");

    
    
    //Create and initialize the actual game screen
    GameScreen gamescreen = GameScreen();
    gamescreen.initialize();
    
    
    // Start the game loop
    while (window.isOpen()) {
        
        // Process events
        Event p1;
        while (window.pollEvent(p1)) {
            // Close window: exit
            if (p1.type == Event::Closed) {
                window.close();
            }
            
        }
        

        // Clear screen
        window.clear();

        
        
        /*
         
         Here I am trying to use that standard game loop with initialize, update, and draw. If I ever try to make a real game in C++ I know that I will need to know how to use these methods and create objects outside of this class.
         
         */
        gamescreen.update();        
        
        //Draw each entity (sprite)
        for(Sprite ent : gamescreen.entities) {
            window.draw(ent);
        }
        
        
        
        // Update the window
        window.display();
    }

    return EXIT_SUCCESS;
}
Example #20
0
void Score::Draw(RenderWindow& window, Time timeSinceLastDrawCall)
{
	window.setFramerateLimit(70);
	window.clear();
	window.draw(ScoreBackground);
	window.draw(CoinsCollectedLabel);
	window.draw(Coins);
	window.draw(Lives);
	window.draw(LivesleftLabel);
	window.draw(ScoreMade);
	window.draw(ScoreMadeLabel);
	window.display();

}
Example #21
0
void UserInterface::CreateADialog(string Text , int fontsize, Font font, RenderWindow &win)
{

    sf::Text text;
    text.setFont(font);
    text.setString(Text);
    text.setCharacterSize(fontsize);
    DialogSprite.setPosition(0 + 5, win.getSize().y - DialogSprite.getGlobalBounds().height);
    text.setPosition(DialogSprite.getGlobalBounds().left + 20, DialogSprite.getGlobalBounds().top + 30);
    win.draw(DialogSprite);
    win.draw(text);
    win.display();
    win.clear();

}
Example #22
0
void Game::menu() /// uruchamia i wyświetla menu
{
	Text title("Pacman",font,200); /// nagłówek gry, czcionka i jej wielkość
	title.setColor(sf::Color(255, 211, 0, 255)); /// kolor nagłówka
	title.setPosition(1280/2-title.getGlobalBounds().width/2,20); /// pozycja nagłówka na ekranie

	const int liczba = 2; /// liczba napisów

	Text tekst[liczba];

	string str[] = {"To Play Press P","To Exit Press Esc"}; /// tablica z napisami
	for(int i=0;i<liczba;i++) /// ustawienie parametrów dla dwóch napisów
	{
		tekst[i].setFont(font); /// ustawienie czcionki
		tekst[i].setCharacterSize(50); /// ustawienie wielkości czcionki

		tekst[i].setString(str[i]);
		tekst[i].setPosition(1280/2-tekst[i].getGlobalBounds().width/2,300+i*120); /// ustawienie napisów na ekranie
	}

	while(state == MENU) /// menu się wyświetla, dopóki user chce być w menu
	{
		Event event;

		while(window.pollEvent(event))
		{
			///Wciśnięcie ESC lub przycisk X
			if(event.type == Event::Closed || event.type == Event::KeyPressed &&
				event.key.code == Keyboard::Escape)
				state = END;

			///kliknięcie MENU
			else if(event.type == Event::KeyPressed && event.key.code == Keyboard::P)
				state = GAME;
		}

		for(int i=0;i<liczba;i++)///ustawienie koloru dla tekstu
			tekst[i].setColor(Color(6, 56, 171, 255));

		window.clear(Color::White);/// ustawienie białego tła
		window.draw(title); /// wyświetlenie tytułu
		for(int i=0;i<liczba;i++) /// wyświetlenie tekstu
			window.draw(tekst[i]);

		window.display();
	}
}
Example #23
0
//renders game
void InGame::Render(Snake &snake)
{	
	drawsnake(snake);
	if (apple != NULL)
	{
		window.draw(apple->shape);
	};

	if (powerUp != NULL)
	{
		window.draw(powerUp->shape);
	}

	scoreText.setString(std::to_string(score));
	window.draw(scoreText);
	window.display();
}
Example #24
0
void render()
{
		
		window.clear(Color::Black);
		if (isGameStarted == false) 
		{
			window.draw(initialText);
		}

		window.draw(ball.ballShape);
		window.draw(scoreText);

		for (int i = 0; i < 4; ++i) {
			window.draw(platform[i].platformShape);
		}
		window.display();
}
Example #25
0
void Renderer::render(RenderWindow& window, const World& world) {
  // clear the window with black color
  window.clear(Color::Black);
  Renderer::renderShip(world.getShip(), window);
  for (auto& e : world.getEnemies()) {
    Renderer::renderEnemyShip(*e, window);
  }
  cout << world.getBullets().size() << endl;
  for (auto& b : world.getBullets()) {
    Renderer::renderBullet(*b, window);
  }
  // draw everything here...
  // window.draw(...);
 
  // end the current frame
  window.display();
  
}
Example #26
0
void intro()
{
	Sprite firecan;
	firecan.setTexture(MediaBucket.getTexture("firecan"));
	firecan.setOrigin(firecan.getLocalBounds().width/2, firecan.getLocalBounds().height/2);
	firecan.setPosition(400, 300);
	Time	intro_time = seconds(4);
	Clock 	clock;

	double opacity = 255;

	RectangleShape filter;
	filter.setFillColor(Color(255,255,255,opacity));
	filter.setSize(Vector2f(800,600));
	filter.setOrigin(400,300);
	filter.setPosition(400,300);

	while(intro_time > seconds(0)) 
	{
		while(app.pollEvent(event))
		{
			if(event.type == Event::KeyPressed) {
				if(event.key.code == Keyboard::Escape) {
					intro_time = seconds(0);
				}
			}
		}
		elapsed_time = clock.restart();
		intro_time -= elapsed_time;
		if(opacity >= 0) {
			opacity -= 255/2*elapsed_time.asSeconds();
			if(opacity < 0) {
				opacity = 0;
			}
		}
		filter.setFillColor(Color(255,255,255,opacity));
		app.clear(Color::White);
		app.draw(firecan);
		app.draw(filter);
		app.display();
	}
}
Example #27
0
File: main.cpp Project: dlxgit/TP
void StartProgram(RenderWindow & window, vector<Block> & blocks, int & stateIndex)
{
	Clock frameClock;   //time for screen-update
	float timeSinceLastFrame;

	while (window.isOpen())
	{
		timeSinceLastFrame = frameClock.getElapsedTime().asMilliseconds();
		ProcessEvents(window);
		if (timeSinceLastFrame >= TIME_PER_FRAME)		//screen update every second
		{
			window.clear(Color::White);
			frameClock.restart();

			Update(blocks, stateIndex);
			Draw(window, blocks);

			window.display();
		}
	}
}
Example #28
0
void StartProgram(RenderWindow & window, Pendulum & pendulum)
{
	Clock frameClock;
	int timeSinceLastFrame;

	while (window.isOpen())
	{
		timeSinceLastFrame = frameClock.getElapsedTime().asMilliseconds();
		ProcessEvents(window);
		if (timeSinceLastFrame >= TIME_PER_FRAME)
		{
			frameClock.restart();

			ComputePhysics(pendulum);
			UpdatePendulum(pendulum);

			window.clear(Color::White);
			Draw(window, pendulum);
			window.display();
		}
	}
};
Example #29
0
void render(RenderWindow &window, Sprite &mapSprite, Sprite *buttons,
	char(*myPlace)[sizeRectangleWeb], char(*enemyPlace)[sizeRectangleWeb])
{
	window.clear();

	// ќтрисовка карты
	for (int i = 1; i < sizeRectangleWeb - 1; i++)
		for (int j = 1; j < sizeRectangleWeb - 1; j++)
		{
			if (myPlace[i][j] == '_')  mapSprite.setTextureRect(IntRect(0, 0, 32, 32));
			if (myPlace[i][j] == '0') mapSprite.setTextureRect(IntRect(32, 0, 32, 32));
			if (myPlace[i][j] == '#') mapSprite.setTextureRect(IntRect(64, 0, 32, 32));
			if (myPlace[i][j] == 'X') mapSprite.setTextureRect(IntRect(96, 0, 32, 32));

			mapSprite.setPosition(j * 32, i * 32);
			window.draw(mapSprite);


			if (enemyPlace[i][j] == '_')  mapSprite.setTextureRect(IntRect(128, 0, 32, 32));
			if (enemyPlace[i][j] == '0') mapSprite.setTextureRect(IntRect(32, 0, 32, 32));
			if (enemyPlace[i][j] == '#') mapSprite.setTextureRect(IntRect(128, 0, 32, 32));
			if (enemyPlace[i][j] == 'X') mapSprite.setTextureRect(IntRect(96, 0, 32, 32));

			mapSprite.setPosition(j * 32 + (sizeRectangleWeb - 1) * 32, i * 32);
			window.draw(mapSprite);
		}

	// ќтрисовка кнопок
	buttons[0].setTextureRect(IntRect(0, 0, 96, 32));
	buttons[1].setTextureRect(IntRect(0, 32, 96, 32));

	buttons[0].setPosition((sizeRectangleWeb - 2) * 32, (sizeRectangleWeb - 2) * 32 + 64);
	buttons[1].setPosition((sizeRectangleWeb - 2) * 32, (sizeRectangleWeb - 2) * 32 + 108);

	window.draw(buttons[0]);
	window.draw(buttons[1]);

	window.display();
}
Example #30
0
void StartProgram(RenderWindow & window, Car & car, Physics & physics, const RectangleShape & ground)
{
	Clock frameClock;
	int timeSinceLastFrame;

	while (window.isOpen())
	{
		timeSinceLastFrame = frameClock.getElapsedTime().asMilliseconds();
		ProcessEvents(window);
		if (timeSinceLastFrame >= TIME_PER_FRAME)
		{
			frameClock.restart();

			ComputePhysics(physics);
			UpdateCar(car, physics);

			window.clear(Color::White);
			Draw(window, car, ground);
			window.display();
		}
	}
}