Example #1
0
void Item::Draw(sf::RenderWindow& renderWindow, sf::Text &text)
{
	TextureManager *t = Resources::getTextureManager("tileMap");
		sf::Sprite s;
		sf::Vector2f item_pos = GetPosition();
		t->generateSprite(id, item_pos, s, sf::Vector2f(GetWidth(),GetHeight()));
		renderWindow.draw(s);



	sf::Vector2f test_pos = GetPosition();
	text.setPosition(test_pos.x, test_pos.y);
	text.setScale(sf::Vector2f(1.5,1.5));
	renderWindow.draw(text);
		//renderWindow.draw(_sprite);
		/*if(amount >0){
			char c[10];
			sprintf(c, "%i", amount);
			std::string string(c);
			sf::String str(string);
			text.setString(str);
			text.setPosition(GetPosition().x, GetPosition().y);
			renderWindow.draw(text);	
		}*/

}
Example #2
0
void resize(sf::Text& text, float width, float height)
{
    int local_width  = text.getLocalBounds().width;
    int local_height = text.getLocalBounds().height;

    if ((local_width > 0) && (local_height > 0))
        text.setScale(width / local_width, height / local_height);
}
Example #3
0
void GraphicEngine::transformSprite(sf::Text& sprite, const Transformation& t, const Color& color)
{
	if (t.hasPosition())
		sprite.setPosition((float)t.getX(), (float)t.getY());
	if (t.hasRotation())
		sprite.rotate(t.getRotation());
	if (color.isUsed())
		sprite.setColor(sf::Color(color.getColor()));
	if (t.hasScale())
		sprite.setScale(t.getScaleX(), t.getScaleY());
}
Example #4
0
	GameEnd(sf::String message, float durationParam = 1.0f) :
		timer(0.0f),
		duration(durationParam),

		color(0xff, 0, 0, 0)
	{

		text.setFont(font);
		text.setCharacterSize(64);
		text.setScale(0.002f, 0.002f);

		text.setString(message);
	}
Example #5
0
int PlayerConnection::Run(sf::RenderWindow &mainWin, int screen)
{
	
	if (!this->font.loadFromFile("resources/fonts/" + DEFAULT_FONT))
	{
		std::cerr << "Error loading the font " + DEFAULT_FONT << std::endl;
		system("pause");
		return (-1);
	}

	this->initializeItems();
	
	sf::Event Event;

	//Boucler tant que la fenêtre n'est pas fermée
    while (true)
    {
		bool usernameIsValid = username.size() > 3;

        //Vérifier les événements
        while (mainWin.pollEvent(Event))
        {
            if (Event.type == sf::Event::Closed)
            {
                return (-1);
            }

			if (Event.type == sf::Event::TextEntered) //On veut seulement les caracteres ASCII
			{	
				bool isANumber = (Event.text.unicode >= 48 && Event.text.unicode <= 57);
				bool isALetter = (Event.text.unicode >= 65 && Event.text.unicode <= 90) || (Event.text.unicode >= 97 && Event.text.unicode <= 122);

				if (username.size() < 13 && (isANumber || isALetter))
				{
					username += static_cast<char>(Event.text.unicode);
				}
			}

			if (Event.type == sf::Event::KeyReleased && Event.key.code == sf::Keyboard::BackSpace)
			{
				username = "";
			}

            if (Event.type == sf::Event::MouseButtonReleased)
            {
				sf::Vector2f mouse_coords = sf::Vector2f(Event.mouseButton.x, Event.mouseButton.y);

				if (intersects(mouse_coords, start.getGlobalBounds()) && usernameIsValid)
				{
					return (MENU);        
				}
				else if	(intersects(mouse_coords, nameContainer.getGlobalBounds()))
				{
					username = "";
				}
			}

            if (Event.type == sf::Event::MouseMoved)
            {
				sf::Vector2f mouse_coords = sf::Vector2f(Event.mouseMove.x, Event.mouseMove.y);
				if (intersects(mouse_coords, start.getGlobalBounds()))
				{
					start.setColor(sf::Color::Red);
					start.setScale(1.05, 1.05);
				}
				else
				{
					start.setColor(sf::Color::White);
					start.setScale(1,1);
				}
			}

			nameDisplay.setString(username);
        }

        mainWin.clear();

		mainWin.draw(spriteLogo);

		mainWin.draw(text);

		if (!usernameIsValid)
		{
			nameContainer.setOutlineColor(sf::Color::Red);
		}
		else
		{
			nameContainer.setOutlineColor(sf::Color::White);
		}

		mainWin.draw(nameContainer);

		mainWin.draw(nameDisplay);

		mainWin.draw(start);

        mainWin.display();
    }

    //On ne devrait jamais se rendre jusqu'à ce point, mais juste au cas, on ferme l'application.
    return (-1);
}
Example #6
0
inline void ManageLevel::setnbAttempTextScale(sf::Vector2f _pos)
{
    m_nbAttemp.setScale(_pos);
};
Example #7
0
 inline Text(Ctx& mCtx, const Vec2f& mPos)
     : Base{mCtx, mPos}, impl{"", *Assets::get().liberationSans, 30}
 {
     impl.setScale(0.f, 0.f);
     impl.setColor(sf::Color::White);
 }