Пример #1
0
ScoreNode::ScoreNode(const FontHolder& fonts)
	: mScore()
	, mStaticScoreText()
	, mScoreText()
	, mLivesText()
{
	using namespace utility;

	const auto TextPadding = 5.f;
	mStaticScoreText.setString("Score: ");
	mStaticScoreText.setFont(fonts.get(Fonts::Main));
	mStaticScoreText.setPosition(TextPadding, TextPadding);
	mStaticScoreText.setCharacterSize(30u);

	mScoreText.setString(std::to_string(mScore));
	mScoreText.setFont(fonts.get(Fonts::Main));
	auto bounds(mStaticScoreText.getGlobalBounds());
	mScoreText.setPosition(bounds.left + bounds.width + TextPadding, TextPadding * TextPadding);
	mScoreText.setCharacterSize(25u);
	mScoreText.setColor(sf::Color::Green);
	centerOrigin(mScoreText);

	mLivesText.setString("Lives: ");
	mLivesText.setFont(fonts.get(Fonts::Main));
	const auto XPadding = 600.f;
	mLivesText.setPosition(XPadding, TextPadding);
	mLivesText.setCharacterSize(30u);
}
Пример #2
0
TextNode::TextNode(const std::string& text, const FontHolder& fonts) :
    mText(text, fonts.get(Fonts::Main), 20),
    mShow(true)
{
    centerOrigin(mText);
    mText.setColor(sf::Color::White);
}
Пример #3
0
TextNode::TextNode(const FontHolder& fonts, const std::string& text)
{
	mText.setFont(fonts.get(Fonts::Main));
	mText.setCharacterSize(20);
	mText.setColor(sf::Color::Black);
	setString(text);
}
Пример #4
0
TextNode::TextNode(b2World* _pw, const FontHolder& fonts, const std::string& text)
	:SceneNode(_pw),
	lifetime(0.0)
{
	mText.setFont(fonts.get(Fonts::main));
	mText.setCharacterSize(30);
	mText.setColor(sf::Color::Black);
	setString(text);
}
Button::Button(const FontHolder& fonts, const TextureHolder& textures)
: mCallback()
, mSprite(textures.get(Textures::Buttons))
, mText("", fonts.get(Fonts::Main), 16)
, mIsToggle(false)
{
	changeTexture(Normal);

	sf::FloatRect bounds = mSprite.getLocalBounds();
	mText.setPosition(bounds.width / 2.f, bounds.height / 2.f);
}
Пример #6
0
Button::Button(const FontHolder &fonts, const TextureHolder &/*textures*/) :
    mCallback(),
    //mButtonTexture(),
    mSprite(),
    mText("", fonts.get(Fonts::Main), 16),
    mIsToggled(false)
{
    sf::IntRect textureRect(0, 0, 200, 50);
    //mSprite.setTexture(mButtonTexture);
    mSprite.setTextureRect(textureRect);

    sf::FloatRect bounds = mSprite.getLocalBounds();
    mText.setPosition(bounds.width / 2.f, bounds.height / 2.f);
}
Пример #7
0
   Button::Button(const FontHolder& fonts, const TextureHolder& textures)
   : mCallback(),
   mNormalTexture(textures.get(Textures::ButtonNormal)),
   mSelectedTexture(textures.get(Textures::ButtonSelected)),
   mPressedTexture(textures.get(Textures::ButtonPressed)),
   mSprite(),
   mText("", fonts.get(Fonts::Main), 16),
   mIsToggle(false) {

      mSprite.setTexture(mNormalTexture);
      centerOrigin(mSprite);

      mText.setPosition(0, 0);
   }
Пример #8
0
    Button::Button(ButtonStyle style, const FontHolder& fonts, const TextureHolder& textures)
    : mStyle(style),
      mFonts(fonts),
      mTextures(textures),
      mIsFocusable(true),
      mIsFixedSize(true),
      mCallback(),
      p_mShape(nullptr),
      p_mSprite(nullptr),
      p_mText(nullptr),
      mColor(COLOR_ON_RELEASED),
      mTextColor(TEXT_COLOR_DEFAULT),
      mScale(1.f, 1.f),
      mState(State::OnReleased)
    {
        if (mStyle == Button::Sprite)
        {
            std::unique_ptr<sf::Sprite> p_sprite(new sf::Sprite());
            p_sprite->setTexture(textures.get(Textures::Button));
            Graphics::centerOrigin(*p_sprite);
            p_mSprite = std::move(p_sprite);
            setText("");
        }
        else
        {
            std::unique_ptr<sf::RectangleShape> p_rect(
                new sf::RectangleShape(sf::Vector2f(BUTTON_WIDTH, BUTTON_HEIGHT)));
            Graphics::centerOrigin(*p_rect);
            p_mShape = std::move(p_rect);

            if (mStyle == ButtonStyle::Text)
            {
                std::unique_ptr<sf::Text> p_text(new sf::Text());
                p_text->setFont(fonts.get(Fonts::Chinese));
                //p_text->setCharacterSize(30);
                p_text->setColor(mTextColor);
                p_text->setString("Button");
                Graphics::centerOrigin(*p_text);
                
                p_mShape->setFillColor(TEXT_BG_COLOR_RELEASED);
                p_mShape->setOutlineThickness(OUT_LINE_THICKNESS);
                p_mShape->setOutlineColor(mTextColor);

                p_mText = std::move(p_text);
            }

            setText("");
        }
    }
Пример #9
0
WaveGenerator::WaveGenerator(TextureHolder& textures, FontHolder &fonts, MusicPlayer &musics) :
    SceneNode(Category::WaveGenerator),
    mTextures(textures),
    mMusicPlayer(musics),
    mCurrentWaveIndex(-1),
    mCurrentWaveNumber(-1),
    mPoints(0),
    mKidsRemaining(0),
    mWaveState(Paused),
    mWaveTimer(sf::Time::Zero),
    mNbKidPoped(0),
    mGaveTraps(false)
{
    mDisplay.setFont(fonts.get(Fonts::Main));
    mDisplay.setString("0 points - Wave 0");
    centerOrigin(mDisplay);
    mDisplay.setPosition(1280.f / 2 + 150.f, 16.f);

    mWaves = WaveTable;
}
Пример #10
0
int main()
{
	srand(static_cast<unsigned>(time(0)));

	sf::RenderWindow window(sf::VideoMode(1280, 720), "SFML works!", sf::Style::Default, sf::ContextSettings(0, 0, 16));
	window.setFramerateLimit(144);

	using namespace pyro;
	using namespace utils;

	enum class FontType { Basic };
	FontHolder<FontType> fontHolder;
	fontHolder.load(FontType::Basic, "C:/Users/glegl/Documents/Visual Studio 2013/Projects/2016 Projects/C++ & SFML Projects/Age of War/Age of War/Assets/Fonts/Menu.ttf");


	Text text;
	text.activateShadow(true);
	text.setFont(fontHolder.get(FontType::Basic));
	text.setString("Lorem Ipsum");
	text.setCharacterSize(40);
	text.setTextColor(sf::Color::Black);
	text.setShadowOffset(1.8f, 1.8f);
	text.setShadowColor(sf::Color(0, 0, 0, 100));
	text.setPosition(0.f, 0.f);

	Text text2;
	text2.loadFontFromFile("C:/Users/glegl/Documents/Visual Studio 2013/Projects/2016 Projects/C++ & SFML Projects/Age of War/Age of War/Assets/Fonts/Menu.ttf");
	text2.setString("Lorem Ipsum");
	text2.setCharacterSize(40);
	text2.setTextColor(sf::Color::Black);
	text2.setPosition(0.f, 100.f);

	Text text3;
	text3.activateShadow(true);
	text3.loadFontFromFile("C:/Users/glegl/Documents/Visual Studio 2013/Projects/2016 Projects/C++ & SFML Projects/Age of War/Age of War/Assets/Fonts/Menu.ttf");
	text3.setString("Lorem Ipsum");
	text3.setCharacterSize(40);
	text3.setTextColor(sf::Color::Black);
	text3.setShadowOffset(2.f, 2.f);
	text3.setShadowColor(sf::Color(102, 153, 153, 150));
	text3.setPosition(0.f, 200.f);

	sf::Texture ianTexture;
	ianTexture.loadFromFile("C:/Users/glegl/Pictures/Ian/Ian1.jpg");

	ParticleSystem particleSystem(sf::Quads, 5000);
	particleSystem.activateEmitter(true);
	particleSystem.setInitializer([]()
	{
		Particle particle;
		particle.size = sf::Vector2f(2.f, 3.5f);
		float speed = 350.f;
		float min = -135.f, max = -45.f;
		float angle = pyro::math::toRadians(std::rand() / (RAND_MAX / (max - min)) + min);
		particle.velocity = sf::Vector2f(cos(angle) * speed, sin(angle) * speed);
		particle.acceleration = sf::Vector2f(0.f, 5.f);
		int randValue = rand() % 11;
		particle.color = sf::Color(std::min(randValue * 25, 255), std::min(randValue * 10, 255) + 153, 255);
		particle.lifetime = sf::seconds(2.5f);

		return std::move(particle);
	});
	particleSystem.setAffector([](Particle& particle, sf::Time dt)
	{
		particle.velocity += particle.acceleration;
		particle.position += particle.velocity * dt.asSeconds();
	});

	sf::Clock clock;
	const sf::Time TimePerFrame(sf::seconds(1.f / 60.f));
	sf::Time TimeSinceLastUpdate(sf::Time::Zero);
	while (window.isOpen())
	{
		TimeSinceLastUpdate += clock.restart();
		while (TimeSinceLastUpdate > TimePerFrame)
		{
			TimeSinceLastUpdate -= TimePerFrame;
			sf::Event event;
			while (window.pollEvent(event))
			{
				if (event.type == sf::Event::Closed)
					window.close();
			}
			particleSystem.setEmitterPosition(static_cast<sf::Vector2f>(sf::Mouse::getPosition(window)));
			particleSystem.update(TimePerFrame);
		}
		window.clear(sf::Color::Black);
		window.draw(text);
		window.draw(text2);
		window.draw(text3);
		window.draw(particleSystem);
		window.display();
	}

	return 0;
}
Пример #11
0
Label::Label(const std::string& text, const FontHolder& fonts)
: mText(text, fonts.get(Fonts::Arcade), 16)
{
}
Пример #12
0
TextNode::TextNode(const std::string& text, const FontHolder& fonts) :
    mText(text, fonts.get(Fonts::Main), 20)
{
    centerOrigin(mText);
}
Пример #13
0
TextNode::TextNode(const std::string& text, const FontHolder& fontHolder)
    : text_(text, fontHolder.get(FontID::Sensation), 18)
{
    centerOrigin();
}
Пример #14
0
TextNode::TextNode(const FontHolder& fonts, const std::string& text)
{
	m_text.setFont(fonts.Get(Fonts::Main));
	m_text.setCharacterSize(20);
	SetString(text);
}
Пример #15
0
TextNode::TextNode(const FontHolder& fonts, const std::string& text, unsigned int size)
{
    mText.setFont(fonts.getConst(Fonts::Main));
    mText.setCharacterSize(size);
    setString(text);
}