Esempio n. 1
0
void pauseMenu()
{
	pause.setFont(myFont);
	pause.setCharacterSize(WIDTH / 16);
	pause.setStyle(sf::Text::Bold);
	pause.setColor(sf::Color::Black);
	pause.setString("PAUSE");
	pause.setOrigin(pause.getLocalBounds().width / 2, pause.getLocalBounds().height / 2);
	pause.setPosition(WIDTH / 2, 3 * HEIGHT / 16);

	sf::Vector2f menuRectSize(3 * WIDTH / 16, HEIGHT / 8);

	for (int i = 0; i < pauseMenuRect.size(); i++)
	{
		pauseMenuRect[i].setSize(menuRectSize);
		pauseMenuRect[i].setFillColor(grey);
		pauseMenuRect[i].setOrigin(menuRectSize.x / 2, menuRectSize.y / 2);
		pauseMenuRect[i].setPosition(WIDTH / 2, 6 * HEIGHT / 16 + i * (5 * HEIGHT / 32));

		pauseMenuText[i].setFont(myFont);
		pauseMenuText[i].setCharacterSize(2 * pause.getCharacterSize() / 5);
		pauseMenuText[i].setStyle(sf::Text::Bold);
		pauseMenuText[i].setColor(sf::Color::Black);
		pauseMenuText[i].setString(pauseMenuCommands[i]);
		pauseMenuText[i].setOrigin(pauseMenuText[i].getLocalBounds().width / 2, pauseMenuText[i].getLocalBounds().height / 2);
		pauseMenuText[i].setPosition(pauseMenuRect[i].getPosition().x, pauseMenuRect[i].getPosition().y);
	}

	BILLIARDS.draw(pause);
	for (int i = 0; i < pauseMenuRect.size(); i++)
	{
		BILLIARDS.draw(pauseMenuRect[i]);
		BILLIARDS.draw(pauseMenuText[i]);
	}
}
Esempio n. 2
0
	//Player constructor.
	Player(sf::Texture& texture, sf::Texture& hpImage, int x, int y, sf::Font& font) {

		mSprite.setTexture(texture);
		mRect = sf::FloatRect(x, y, 120, 110);					//Character x, y, width, height.
		
		mName = "Player 1";
		mTextName.setString(mName);
		mTextName.setFont(font);
		mTextName.setCharacterSize(30);
		mTextName.setStyle(sf::Text::Bold);
		mTextName.setColor(sf::Color::Red);
		
		mHpSprite.setTexture(hpImage);
		mHpSprite.setTextureRect(sf::IntRect(0, 0, 100, 10));

		mSprite.setTextureRect(sf::IntRect(0, 15, 120, 110));
	
		mSpeed = 0.1;
		mMovement.x = 0;
		mMovement.y = 0;

		mCurrentFrame = 0;
		mAnimationSpeed = 0.005;

		mIsAlive = true;
		mHP = 100;
		mMaxHp = 100;
		mMP = 100;
	}
Esempio n. 3
0
void Game::prepareText(sf::Text &text, int height)
{
    text.setFont(font);
    text.setCharacterSize(Game::characterSize);
    text.setStyle(sf::Text::Bold);
    text.setColor(sf::Color::White);
    text.setPosition(420, height);
}
Esempio n. 4
0
void WindowCreateThing::init(sf::RenderWindow &window) {

    rectTitle.setSize(sf::Vector2f(window.getSize().x*0.45, window.getSize().y*0.07));
    rectTitle.setPosition(sf::Vector2f(window.getSize().x/2-(rectTitle.getSize().x/2), window.getSize().x/4-(rectTitle.getSize().y/2)));
    rectTitle.setFillColor(sf::Color(158, 158, 158));
    rectTitle.setOutlineColor(sf::Color::Black);
    rectTitle.setOutlineThickness(1.f);

    rectMain.setSize(sf::Vector2f(window.getSize().x*0.45,window.getSize().y*0.45));
    rectMain.setPosition(sf::Vector2f(rectTitle.getPosition().x, rectTitle.getPosition().y+rectTitle.getSize().y));
    rectMain.setFillColor(sf::Color::White);
    rectMain.setOutlineColor(sf::Color::Black);
    rectMain.setOutlineThickness(1.f);

    load();


    starting_position = sf::Mouse::getPosition(window);



    textTitle.setFont(font);
    textTitle.setString("CreateThings.txt");
    textTitle.setCharacterSize(24);
    textTitle.setColor(sf::Color::White);
    textTitle.setPosition(sf::Vector2f(rectTitle.getPosition().x+rectTitle.getSize().x*0.3, rectTitle.getPosition().y+rectTitle.getSize().y*0.1));
    //textTitle.setPosition(sf::Vector2f(400,10));

    textClose.setFont(font);
    textClose.setString("X");
    textClose.setStyle(sf::Text::Bold);
    textClose.setCharacterSize(35);
    textClose.setColor(sf::Color::White);
    textClose.setPosition(sf::Vector2f(rectTitle.getPosition().x+rectTitle.getSize().x-30, rectTitle.getPosition().y+rectTitle.getSize().y*0.05));


    ///// FOLDER ICONE
    textureFolder.setSmooth(true);
    spriteFodler.setTexture(textureFolder);
    sf::Vector2f targetSize(25.0f, 25.0f);
    spriteFodler.setScale(
        targetSize.x / spriteFodler.getLocalBounds().width,
        targetSize.y / spriteFodler.getLocalBounds().height);
    spriteFodler.setPosition(sf::Vector2f(textTitle.getPosition().x-targetSize.x, textTitle.getPosition().y));




    ///// CLOSE ICONE
    /*textureClose.setSmooth(true);
    spriteClose.setTexture(textureClose);
    sf::Vector2f targetSize2(window.getSize().y*0.07, window.getSize().y*0.07);
    spriteClose.setScale(
        targetSize2.x / spriteClose.getLocalBounds().width,
        targetSize2.y / spriteClose.getLocalBounds().height);
    spriteClose.setPosition(rectTitle.getPosition().x+rectTitle.getSize().x-targetSize2.x, rectTitle.getPosition().y);*/
}
Esempio n. 5
0
void MoveDraw()
{
	moves.setFont(myFont);
	moves.setCharacterSize(12);
	moves.setStyle(sf::Text::Bold);
	moves.setColor(sf::Color::Red);
	moves.setOrigin(moves.getLocalBounds().width / 2, moves.getLocalBounds().height / 2);
	moves.setPosition(WIDTH * 3 / 4, borderDepth / 2);
	bestScore.setFont(myFont);
	bestScore.setCharacterSize(12);
	bestScore.setStyle(sf::Text::Bold);
	bestScore.setColor(sf::Color::Red);
	bestScore.setOrigin(bestScore.getLocalBounds().width / 2, bestScore.getLocalBounds().height / 2);
	bestScore.setPosition(WIDTH * 1 / 4, borderDepth / 2);

	stringstream mess2;
	if (BS != 0)
		mess2 << "Best Score: " << BS;
	else
		mess2 << "Best Score: --";
	string message2 = mess2.str();
	bestScore.setString(message2);

	if ((twoPlayerGame) || (pause2P))
	{
		if (mover > 2)
			mover = 1;
		stringstream mess;
		mess << "Player " << mover << "'s turn";
		string message = mess.str();
		moves.setString(message);
		BILLIARDS.draw(moves);
	}
	else
	{
		stringstream mess;
		mess << "Moves: " << mover;
		string message = mess.str();
		moves.setString(message);
		BILLIARDS.draw(bestScore);
		if ((onePlayerGame)||(pause1P))
			BILLIARDS.draw(moves);
	}
}
Esempio n. 6
0
void MenuScreen::generateGameModeButton(sf::Text& button, const string& modeName, 
	short position, const sf::Font *font,
	const sf::Vector2u& screenSize )
{
	button = sf::Text( modeName, *font );
	button.setColor( sf::Color::Blue );
	button.setStyle( sf::Text::Regular );
	sf::FloatRect textRect = button.getGlobalBounds();
	button.setOrigin( textRect.left + textRect.width / 2.0f,
		textRect.top + textRect.height / 2.0f );
	button.setPosition( screenSize.x / 2, screenSize.y * 0.2 + position * Constants::LENGTH_BUTTON_SEPERATION );
}
bool startMenu(sf::Text title, sf::Text anyKey, sf::Text credits, sf::RenderWindow& window)
{
  // create and load texture for earth.png
  sf::Texture earth;
  if(!earth.loadFromFile("img/earth2.png")) cout << "Error, could not load earth.png" << endl;

  sf::Sprite earthSprite;
  earthSprite.setTexture(earth);
  earthSprite.setPosition(WINDOW_WIDTH / 4 , WINDOW_HEIGHT / 4);

  // set title color, position, size and style
  title.setColor(sf::Color::Black);
  title.setPosition(WINDOW_WIDTH / 5, 0);
  title.setCharacterSize(50);
  title.setStyle(sf::Text::Bold);

  // set anyKey position and color
  anyKey.setPosition(WINDOW_WIDTH / 4.5, 410);
  anyKey.setColor(sf::Color::Black);

  credits.setPosition(WINDOW_WIDTH / 2.6, 450);
  credits.setCharacterSize(10);
  credits.setColor(sf::Color::Black);

  while(window.isOpen())
  {
    sf::Event event;
    while (window.pollEvent(event)) // process events
    {
      // QUIT
      if (event.type == sf::Event::Closed)
      {
          window.close(); // close the window
          return false;
      }

      // if the user presses any key
      if(event.type == sf::Event::KeyPressed || event.type == sf::Event::MouseButtonPressed)
        return true;
    }

    window.clear(sf::Color(255, 255, 235, 0));

    window.draw(earthSprite);
    window.draw(title);
    window.draw(anyKey);
    window.draw(credits);
    window.display();
  }

  return false;
}
Esempio n. 8
0
	// Constructeur & destructeur
	Observer(const sf::Vector2f& center)
	{
		//sf::Font font;
		assert(_font.loadFromFile("vera.ttf") == true);
		_text.setColor(sf::Color::White);
		_text.setFont(_font);
		_text.setCharacterSize(50);
		_text.setStyle(sf::Text::Italic);
		_border.setPosition(center);
		_border.setOutlineColor(sf::Color::White);
		_border.setOutlineThickness(2.0);
		_border.setFillColor(sf::Color::Transparent);
	}
Esempio n. 9
0
void endGame()
{
	endTitle.setFont(myFont);
	endTitle.setCharacterSize(WIDTH / 16);
	endTitle.setStyle(sf::Text::Bold);
	endTitle.setColor(sf::Color::Black);
	string str;
	if (end1P)
	{
		stringstream message;
		message << "Final score: " << mover;
		str = message.str();
		
	}
	else if (end2P)
	{
		stringstream message;
		message << "Player " << mover << " wins!";
		str = message.str();
	}
	endTitle.setString(str);
	endTitle.setOrigin(endTitle.getLocalBounds().width / 2, endTitle.getLocalBounds().height / 2);
	endTitle.setPosition(WIDTH / 2, 2 * HEIGHT / 5);

	sf::Vector2f menuRectSize(3 * WIDTH / 16, HEIGHT / 8);

	for (int i = 0; i < endMenuRect.size(); i++)
	{
		endMenuRect[i].setSize(menuRectSize);
		endMenuRect[i].setFillColor(grey);
		endMenuRect[i].setOrigin(menuRectSize.x / 2, menuRectSize.y / 2);
		endMenuRect[i].setPosition(WIDTH / 2, 4 * HEIGHT / 5);

		endMenuText[i].setFont(myFont);
		endMenuText[i].setCharacterSize(2 * pause.getCharacterSize() / 5);
		endMenuText[i].setStyle(sf::Text::Bold);
		endMenuText[i].setColor(sf::Color::Black);
		endMenuText[i].setString(endMenuCommands[i]);
		endMenuText[i].setOrigin(endMenuText[i].getLocalBounds().width / 2, endMenuText[i].getLocalBounds().height / 2);
		endMenuText[i].setPosition(endMenuRect[i].getPosition().x, endMenuRect[i].getPosition().y);
	}

	BILLIARDS.draw(endTitle);
	for (int i = 0; i < endMenuRect.size(); i++)
	{
		BILLIARDS.draw(endMenuRect[i]);
		BILLIARDS.draw(endMenuText[i]);
	}
}
Esempio n. 10
0
	//Enemy constructor.
	Enemy(sf::Texture& texture, int x, int y, sf::Font& font) {
		mSprite.setTexture(texture);
		mRect = sf::FloatRect(x, y, 120, 110);					//Character x, y, width, height.

		mName = "Enemy";
		mTextName.setString(mName);
		mTextName.setFont(font);
		mTextName.setCharacterSize(30);
		mTextName.setStyle(sf::Text::Bold);
		mTextName.setColor(sf::Color::Magenta);

		mSprite.setTextureRect(sf::IntRect(0, 15, 120, 110));

		mDirection = rand() % 4;
		mSpeed = 0.05;

		mCurrentFrame = 0;
		mAnimationSpeed = mSpeed * 0.05;

		mIsAlive = true;
		mHP = 100;

		mDamage = 30;
	}
int mainMenu(sf::Text title, sf::Font font, sf::RenderWindow& window)
{
  // create and load texture and sprite to be drawn to the screen
  sf::Texture earth;
  if(!earth.loadFromFile("img/earth2.png")) cout << "Error, could not load earth.png" << endl;

  sf::Sprite earthSprite;
  earthSprite.setTexture(earth);
  earthSprite.setPosition(20, 100);

  // set title color, position, size and style
  title.setColor(sf::Color::Black);
  title.setString("B i g   C o u n t r y   Q u i z");
  title.setPosition(5, 5);
  title.setCharacterSize(25);
  title.setStyle(sf::Text::Bold);

  // menu text objects:
  sf::Text world("World", font);
  world.setColor(sf::Color::Black);
  world.setPosition(400, 140);

  sf::Text continent("Continent Mode", font);
  continent.setColor(sf::Color::Black);
  continent.setPosition(400, 200);

  sf::Text practice("Practice", font);
  practice.setColor(sf::Color::Black);
  practice.setPosition(400, 260);

  sf::Text exit("Exit", font);
  exit.setColor(sf::Color::Black);
  exit.setPosition(400, 320);

  while(window.isOpen())
  {
    sf::Event event;
    while (window.pollEvent(event)) // process events
    {
      // QUIT
      if(event.type == sf::Event::Closed)
      {
          window.close(); // close the window
          return 0;
      }

      // if the left mouse button is clicked, run these checks
      if(sf::Mouse::isButtonPressed(sf::Mouse::Left))
      {
        // if the user clicks world mode
        if(isTextClicked(world, window))
          return 1;

        // if the user clicks practice
        if(isTextClicked(practice, window))
          return 3;

        // if the user clicks exit
        if(isTextClicked(exit, window))
        {
          window.close();
          return 0;
        }
      }
    }

    window.clear(sf::Color(255, 255, 235, 0));

    window.draw(title);
    window.draw(world);
    window.draw(continent);
    window.draw(practice);
    window.draw(exit);
    window.draw(earthSprite);
    window.display();
  }

  return false;
}
void setup(sf::RenderWindow& s, sf::Event& e, sf::Text& t, sf::Font& tf, sf::Text& v, tgui::ListBox::Ptr& res, tgui::ListBox::Ptr& mode, tgui::EditBox::Ptr& c1, tgui::EditBox::Ptr& c2, tgui::Button::Ptr& b, tgui::Gui& sg)
{
	tf.loadFromFile("sansation.ttf");

	//WINDOW
	s.setFramerateLimit(10);

	//TITLE
	t.setFont(tf);
	t.setPosition(-5, 0);
	t.setStyle(sf::Text::Underlined);
	t.setString(" GRAVITY SIMULATOR ");
	t.setCharacterSize(30);

	//VERSIONTEXT
	v.setFont(tf);
	v.setColor(sf::Color(51, 255, 255));
	v.setPosition(247, 33);
	v.setString("v1.0");
	v.setCharacterSize(25);

	//GUI
	sg.setFont(tf);
	sg.add(res);
	sg.add(mode);
	sg.add(c1);
	sg.add(c2);
	sg.add(b);

	//VIDEOMODE
	mode->setScrollbar(nullptr);
	mode->setPosition(20, 80);
	mode->setItemHeight(15);
	mode->setSize(95, 30);
	mode->setTextSize(15);
	mode->addItem("FULLSCREEN");
	mode->addItem("WINDOWED");
	mode->setSelectedItemByIndex(0);

	//RESOLUTIONS
	res->setScrollbar(nullptr);
	res->setPosition(20, 115);
	res->setItemHeight(15);
	res->setTextSize(15);

	res->addItem("2560 x 1440");
	res->addItem("1920 x 1080");
	res->addItem("1366 x 768");
	res->addItem("CUSTOM");
	res->setSize(95, res->getItemCount() * 15);

	//CUSTOM RESOLUTION
	c1->setDefaultText("X");
	c1->setPosition(125, 140);
	c1->setSize(50, 15);
	c1->setTextSize(15);
	c1->setMaximumCharacters(4);
	
	c2->setDefaultText("Y");
	c2->setPosition(125, 160);
	c2->setSize(50, 15);
	c2->setTextSize(15);
	c2->setMaximumCharacters(4);

	//STARTBUTTON
	b->setPosition(185, 140);
	b->setSize(95, 35);
	b->setText("START");
	b->setTextSize(15);
	b->connect("pressed", start, res, mode, c1, c2);

}
Esempio n. 13
0
void GameBoardDrawer::drawBoard()
{
	int positionX, positionY;
	Ball ball;
	Player player[2];

	// draw ball
	sharedMemory.getCurrentState(ball, player[0], player[1]);

	ball.getPosition(positionX, positionY);
	window->clear(sf::Color::Black);

	sf::CircleShape circle(circleRadius);
	circle.setPosition(positionX - circleRadius, positionY - circleRadius);
	circle.setFillColor(sf::Color::Green);
	window->draw(circle);

	// draw bottom platform
	player[0].getPosition(positionX, positionY);

	sf::RectangleShape bottomPlayer(sf::Vector2f(platformWidth, platformHeight));
	bottomPlayer.setPosition(positionX - platformWidth/2, positionY - platformHeight/2);
	bottomPlayer.setFillColor(sf::Color::Red);
	window->draw(bottomPlayer);

	// draw top platform
	player[1].getPosition(positionX, positionY);

	sf::RectangleShape topPlayer(sf::Vector2f(platformWidth, platformHeight));
	topPlayer.setPosition(positionX - platformWidth/2, positionY - platformHeight/2);
	topPlayer.setFillColor(sf::Color::Yellow);
	window->draw(topPlayer);

	// draw borders
	sf::RectangleShape topBorder(sf::Vector2f(windowWidth, 2*borderSize));
	topBorder.setPosition(0, -borderSize);
	topBorder.setFillColor(sf::Color::Blue);
	window->draw(topBorder);

	sf::RectangleShape leftBorder(sf::Vector2f(2*borderSize, windowHeight));
	leftBorder.setPosition(-borderSize, 0);
	leftBorder.setFillColor(sf::Color::Blue);
	window->draw(leftBorder);

	sf::RectangleShape bottomBorder(sf::Vector2f(windowWidth, 2*borderSize));
	bottomBorder.setPosition(0, windowHeight-borderSize);
	bottomBorder.setFillColor(sf::Color::Blue);
	window->draw(bottomBorder);

	sf::RectangleShape rightBorder(sf::Vector2f(2*borderSize, windowHeight));
	rightBorder.setPosition(windowWidth-borderSize, 0);
	rightBorder.setFillColor(sf::Color::Blue);
	window->draw(rightBorder);

	static sf::Font font;
	static bool fontLoaded = false;
	if (!fontLoaded && font.loadFromFile("dreamorphans.ttf"))
	{
		std::cout << "font loaded" << std::endl;
		fontLoaded = true;
	}
	
	if (fontLoaded)
	{
		static int score = 0;
		player[0].getScore(score);

		char buffer[32];
		sprintf(buffer, "score: %d", score);

		static sf::Text text;
		text.setFont(font);
		text.setString(buffer);
		text.setCharacterSize(24);
		text.setColor(sf::Color::White);
		text.setStyle(sf::Text::Bold);
		text.setPosition(20,20);
		window->draw(text);

		player[1].getScore(score);
		sprintf(buffer, "score: %d", score);
		text.setString(buffer);
		text.setPosition(20,windowHeight-54);
		window->draw(text);
	}

	window->display();
}
Esempio n. 14
0
static void Text_resetStyle(sf::Text& text)
{
    text.setStyle(sf::Text::Regular);
}
// Draw a character at screen location (x,y) with color.
// Return 0 if ok, else -1.
int df::GraphicsManager::drawCh(Position world_pos, char ch, df::Color color) const {
	
	// Make sure window is allocated.
	if (p_window == NULL)
		return -1;

	Position view_pos = df::Utility::worldToView(world_pos);

	df::GraphicsManager &gm = df::GraphicsManager::getInstance();
	// Convert spaces (x,y) to pixels (x,y).
	Position pixel_pos = gm.spacesToPixels(view_pos);

	// Draw background rectangle since text is "see through" in SFML.
	sf::RectangleShape rectangle;
	rectangle.setSize(sf::Vector2f(gm.charWidth(), gm.charHeight() - 1));
	rectangle.setFillColor(WINDOW_BACKGROUND_COLOR_DEFAULT);
	rectangle.setPosition(pixel_pos.getX() + gm.charWidth() / 2 - 5, pixel_pos.getY() + gm.charHeight() / 2 - 12);
	p_window->draw(rectangle);

	// Create character text to draw.
	static sf::Text text("", font);
	text.setString(ch);
	text.setStyle(sf::Text::Bold); // Make bold, since looks better. 

	// Scale to right size.
	if (gm.charWidth() < gm.charHeight())
		text.setCharacterSize(gm.charWidth() * 2);
	else
		text.setCharacterSize(gm.charHeight() * 2);

	// Set SFML color based on Dragonfly color.
	switch (color){
	case df::BLACK:
		text.setColor(sf::Color::Black);
		break;
	case df::RED:
		text.setColor(sf::Color::Red);
		break;
	case df::GREEN:
		text.setColor(sf::Color::Green);
		break;
	case df::YELLOW:
		text.setColor(sf::Color::Yellow);
		break;
	case df::BLUE:
		text.setColor(sf::Color::Blue);
		break;
	case df::MAGENTA:
		text.setColor(sf::Color::Magenta);
		break;
	case df::CYAN:
		text.setColor(sf::Color::Cyan);
		break;
	case df::WHITE:
		text.setColor(sf::Color::White);
		break;
	default:
		text.setColor(sf::Color::White);
		break;
	}

	// Set position in window (in pixels).
	text.setPosition(pixel_pos.getX(), pixel_pos.getY());

	// Draw character.
	p_window->draw(text);

	return 0;
}