Пример #1
0
Picture::Picture(int sx, int sy, int px, int py,
        const std::string& path, Widget *parent) :
    Rectangle(sx, sy, px, py, parent) {
        texture.loadFromFile(path);
        texture.setRepeated(true);
        setColor(sf::Color(255, 255, 255, 255));
        rect.setTexture(&texture);
        setRepeated(false);
}
Пример #2
0
void CTexture::load(std::string fileName)
{
	bool isLoaded = loadFromFile(fileName);
#ifdef DEBUG
	assert(isLoaded);
#endif
	setSmooth(true);
	setRepeated(false);
}
Пример #3
0
RemainingTargets::RemainingTargets(Object2D* parent, SceneGraph::DrawableGroup2D* drawables, SceneGraph::AnimableGroup2D* animables): AbstractHudText(parent, drawables), SceneGraph::Animable2D(*this, animables) {
    (text = new Text::Renderer2D(*font, *glyphCache, 0.06f, Text::Alignment::LineLeft))
        ->reserve(32, BufferUsage::DynamicDraw, BufferUsage::StaticDraw);

    setDuration(0.4f);
    setRepeated(true);
    setRepeatCount(2);

    translate({-1.303f, -0.97f});
}
Пример #4
0
bool System::texture_setRepeated(unsigned int id, bool repeated)
{
    auto texture = mTextureHandler.get(id);

    if(nullptr == texture)
    {
        return false;
    }

    texture->setRepeated(repeated);

    return true;
}
Пример #5
0
	CubeTexture &CubeTexture::operator=(const CubeTexture &cubeTex)
	{
		FRONTIER_HEAVYCOPY_NOTE;
		
		if (cubeTex.getGlId())
		{
			create(cubeTex.getSize());
			C(6)
				getFace(i).copyFace(cubeTex,i);
		}
		else
		{
			if (getGlId() && glIsTexture(getGlId()) == GL_TRUE)
				glDeleteTextures(1,&getGlId());
			
			getGlId() = 0;
			m_size    = 0;
		}
		
		setRepeated(cubeTex.m_isRepeated);
		setSmooth(cubeTex.m_isSmooth);
	}
Пример #6
0
bool ld::PlayState::init()
{
    std::srand(static_cast<unsigned int>(std::time(0)));
    
    if (m_music.openFromFile("assets/Audio/Music/Abstraction - Ludum Dare 28 - First Track.wav"))
        m_music.play();
    m_music.setLoop(true);

    const float buttonScale = 2.f;
    // Pause menu
    {
        std::array<std::unique_ptr<Button>, 3> buttons;

        for (auto& i : buttons)
        {
            i.reset(new Button(*m_window));

            i->setFillColor(sf::Color(255, 255, 255, 255));
            i->setSound("assets/Audio/Sound Effects/menuselect.ogg");
        }
        const float buttonOffset = 50.f;

        /****** Resume button ******/
        auto tex = ldResource.getTexture("assets/Graphics/Menus/retry.png");
        buttons[0]->setTexture(tex);
        buttons[0]->setSize(sf::Vector2f(tex->getSize()) * buttonScale);
        buttons[0]->setPosition(100.f, 100.f);
        buttons[0]->setCallback([this]()
        {
            m_menuState = Count;
            Engine::getInstance().setPaused(false);
        });

        /****** Restart button ******/
        tex = ldResource.getTexture("assets/Graphics/Menus/restart.png");
        buttons[1]->setTexture(tex);
        buttons[1]->setSize(buttons[0]->getSize());
        buttons[1]->setPosition(100.f, buttons[0]->getPosition().y + buttons[0]->getSize().y + buttonOffset);
        buttons[1]->setCallback([this]()
        {
            auto ptr = new PlayState(*m_window);
            ptr->setDifficulty(m_difficulty);
            Engine::getInstance().changeState(ptr);
            Engine::getInstance().setPaused(false);
        });

        /****** Exit button ******/
        tex = ldResource.getTexture("assets/Graphics/Menus/backToMenu.png");
        buttons[2]->setTexture(tex);
        buttons[2]->setSize(buttons[1]->getSize());
        buttons[2]->setPosition(100.f, buttons[1]->getPosition().y + buttons[1]->getSize().y + buttonOffset);
        buttons[2]->setCallback([this]()
        {
            Engine::getInstance().changeState(new MainMenuState(*m_window));
            Engine::getInstance().setPaused(false);
        });

        for (auto& i : buttons)
            m_menus[Pause]->addElement(i.release());
    }

    // Game over menu
    {
        std::array<std::unique_ptr<Button>, 2> buttons;

        for (auto& i : buttons)
        {
            i.reset(new Button(*m_window));

            i->setFillColor(sf::Color(255, 255, 255, 255));
            i->setSound("assets/Audio/Sound Effects/menuselect.ogg");
        }

        const float buttonOffset = 50.f;

        /****** Restart button ******/
        auto tex = ldResource.getTexture("assets/Graphics/Menus/restart.png");
        buttons[0]->setTexture(tex);
        buttons[0]->setSize(sf::Vector2f(tex->getSize()) * buttonScale);
        buttons[0]->setPosition(100.f, 100.f);
        buttons[0]->setCallback([this]()
        {
            auto ptr = new PlayState(*m_window);
            ptr->setDifficulty(m_difficulty);

            Engine::getInstance().changeState(ptr);
            Engine::getInstance().setPaused(false);
        });

        /****** Quit button ******/
        tex = ldResource.getTexture("assets/Graphics/Menus/backToMenu.png");
        buttons[1]->setTexture(tex);
        buttons[1]->setSize(buttons[0]->getSize());
        buttons[1]->setPosition(100.f, buttons[0]->getPosition().y + buttons[0]->getSize().y + buttonOffset);
        buttons[1]->setCallback([this]()
        {
            Engine::getInstance().changeState(new MainMenuState(*m_window));
            Engine::getInstance().setPaused(false);
        });

        for (auto& i : buttons)
            m_menus[GameOver]->addElement(i.release());
    }

	//Player
	auto tex = ldResource.getTexture("assets/Graphics/Player and shield planets/Player_Base.png");
	tex->setSmooth(true);
	m_player.setTexture(tex);
	m_player.setSize(sf::Vector2f(128.f,128.f));
	m_player.setOrigin(m_player.getSize().x / 2, m_player.getSize().y / 2);
	m_player.setPosition(m_window->getView().getCenter());

	tex = ldResource.getTexture("assets/Graphics/Player and shield planets/Shield.png");
	tex->setSmooth(true);
	m_player.m_shield.setTexture(tex);
	m_player.m_shield.setSize(sf::Vector2f(128.f, 128.f));
	m_player.m_shield.setOrigin(m_player.m_shield.getSize().x / 2, m_player.m_shield.getSize().y / 2);
	m_player.m_shield.setPosition(m_player.getPosition() - m_player.getSize());

	tex = ldResource.getTexture("assets/Graphics/Effects/electricity_chain_loop.png");
	tex->setSmooth(true);
	tex->setRepeated(true);
	m_player.m_chain.setTexture(tex);
	m_player.m_chain.setSize(sf::Vector2f(200, 200));
	m_player.m_chain.setOrigin(m_player.m_chain.getSize().x / 2, 0);
	m_player.m_chain.setPosition(m_player.getPosition());

    tex = ldResource.getTexture("assets/Graphics/Player and shield planets/Player_Cloud.png");
    tex->setSmooth(true);
    m_player.m_clouds.setTexture(tex);
    m_player.m_clouds.setSize(m_player.getSize());
    m_player.m_clouds.setScale(m_player.getScale());
    m_player.m_clouds.setOrigin(m_player.getSize() / 2.f);
    m_player.m_clouds.setPosition(m_player.getPosition());
	
    tex = ldResource.getTexture("assets/Graphics/Backgrounds/background.png");
    tex->setSmooth(true);
    m_background.setSize(m_window->getView().getSize());
    m_background.setTexture(tex);

    tex = ldResource.getTexture("assets/Graphics/Menus/healthcounter.png");
    tex->setSmooth(true);
    m_lifeIcon.setTexture(tex);
    m_lifeIcon.setSize(sf::Vector2f(m_lifeIcon.getTexture()->getSize()));

    tex = ldResource.getTexture("assets/Graphics/Menus/killcounter.png");
    tex->setSmooth(true);
    m_killIcon.setTexture(tex);
    m_killIcon.setSize(sf::Vector2f(m_killIcon.getTexture()->getSize()));

    auto font = ldResource.getFont("assets/Graphics/Roboto-Black.ttf");
    m_scoreText.setFont(*font);
    m_scoreText.setCharacterSize(50);
    m_scoreText.setColor(sf::Color(255, 255, 255, 255));

    m_killsText.setFont(*font);
    m_killsText.setCharacterSize(65);
    m_killsText.setColor(sf::Color(255, 255, 255, 255));

    switch (m_difficulty)
    {
        case 1:
            m_Time = 6.f;
            m_minTime = 3.f;
			m_player.setLives(5);
			m_enemySpeed = 150.f;
			m_enemySpeedMin = 100.f;
			break;
        case 2:
            m_Time = 3.5f;
            m_minTime = 1.f;
            m_player.setLives(4);
			m_enemySpeed = 185.f;
			m_enemySpeedMin = 100.f;
            break;
        case 3:
            m_Time = 2.5f;
            m_minTime = 0.25f;
			m_player.setLives(3);
			m_enemySpeed = 225.f;
			m_enemySpeedMin = 100.f;
            break;
		default:
			assert(false);
			break;
    }

    m_scoreClock.restart();

	//Enemy
	addEnemy();

	return true;
}
Пример #7
0
 RepeatingAnimable(AbstractObject3D& object, AnimableGroup3D* group = nullptr): SceneGraph::Animable3D(object, group), time(-1.0f) {
     setDuration(10.0f);
     setState(AnimationState::Running);
     setRepeated(true);
 }
Пример #8
0
void GameState::onDraw(sf::RenderTarget& target) {
    float w = target.getSize().x;
    float h = target.getSize().y;
    m_renderTextures[0].clear();
    m_renderTextures[1].clear();

    sf::RenderTarget& t = m_renderTextures[0];

    target.clear();
    t.clear(sf::Color(80, 80, 80));

    // backdrop
    // t.setView(t.getDefaultView());
    // sf::RectangleShape backdrop(sf::Vector2f(t.getSize()));
    // backdrop.setFillColor(sf::Color(100, 150, 255));
    // backdrop.setFillColor(sf::Color(40, 40, 40));
    // auto shader = Root().resources.getShader("backdrop");
    // shader->setParameter("size", sf::Vector2f(t.getSize()));
    // shader->setParameter("time", getTime());
    // t.draw(backdrop, shader.get());

    setView(t);
    int backTiles = 50;
    float s = 4.0;

    auto tex = Root().resources.getTexture("cave-1");
    tex->setRepeated(true);
    sf::Sprite back(*tex.get());
    back.setTextureRect(sf::IntRect(0, 0, tex->getSize().x * backTiles, tex->getSize().y * backTiles));
    back.setScale(s / tex->getSize().x, s / tex->getSize().y);
    back.setPosition(m_center.x * 0.2, m_center.y * 0.2);
    back.setOrigin(tex->getSize().x / 2 * backTiles, tex->getSize().y / 2 * backTiles);

    auto levelColor = {
        sf::Color(100, 20, 0),
        sf::Color(100, 120, 200),
        sf::Color(250, 200, 0),
        sf::Color(255, 0, 128)
    };
    back.setColor(*(levelColor.begin() + (m_currentLevel) % levelColor.size()));
    t.draw(back);

    s = 8.0;
    tex = Root().resources.getTexture("perlin");
    tex->setRepeated(true);
    back.setTexture(*tex.get(), false);
    back.setTextureRect(sf::IntRect(0, 0, tex->getSize().x * backTiles, tex->getSize().y * backTiles));
    back.setScale(s / tex->getSize().x, s / tex->getSize().y);
    back.setOrigin(tex->getSize().x / 2 * backTiles, tex->getSize().y / 2 * backTiles);
    back.setColor(sf::Color(128, 128, 128));
    back.setPosition(m_center.x * 0.1, m_center.y * 0.1);
    t.draw(back, sf::BlendMultiply);

    s = 8.0;
    back.setScale(s / tex->getSize().x, s / tex->getSize().y);
    back.setPosition(0, 0);
    back.setColor(sf::Color(255, 255, 255, 80));
    back.setPosition(-m_center.x * 0.2, -m_center.y * 0.2);
    t.draw(back, sf::BlendAdd);

    s = 8.0;
    back.setScale(s / tex->getSize().x, s / tex->getSize().y);
    back.setPosition(-m_center.x * 0.3, -m_center.y * 0.3);
    back.setColor(sf::Color(255, 255, 255, 255));
    t.draw(back, sf::BlendMultiply);

    // draw
    setView(t);
    drawEntities(t);

    setView(m_renderTextures[1]);
    float f = - 0.2;
    back.setColor(sf::Color(255, 255, 255, 150));
    back.setPosition(m_center.x * f + m_time * f * 1.5, m_center.y * f);
    m_renderTextures[1].draw(back, sf::BlendAdd);

    sf::Sprite sprite;
    sprite = sf::Sprite(m_renderTextures[1].getTexture());
    Root().resources.getShader("fog")->setParameter("size", sf::Vector2f(m_renderTextures[1].getSize()));
    t.setView(sf::View(sf::FloatRect(0, h, w, -h)));
    t.draw(sprite, sf::RenderStates(sf::BlendAdd, sf::RenderStates::Default.transform, sf::RenderStates::Default.texture, Root().resources.getShader("fog").get()));

    // post-processing
    target.setView(sf::View(sf::FloatRect(0, h, w, -h)));
 
    auto pixel          = Root().resources.getShader("pixel");
    auto verticalBlur   = Root().resources.getShader("blur-vertical");
    auto horizontalBlur = Root().resources.getShader("blur-horizontal");

    horizontalBlur->setParameter("blurSize", 2.5 / w);
    verticalBlur->setParameter("blurSize", 2.5 / h);
    // pixel->setParameter("center", m_center.x, m_center.y);
    pixel->setParameter("size", w, h);

    m_renderTextures[0].setView(m_renderTextures[0].getDefaultView());
    m_renderTextures[1].setView(m_renderTextures[1].getDefaultView());
    m_renderTextures[0].setSmooth(true);
    m_renderTextures[1].setSmooth(true);

    if(m_shadersEnabled) {
        sprite = sf::Sprite(m_renderTextures[0].getTexture());
        m_renderTextures[1].draw(sprite, horizontalBlur.get());

        sprite = sf::Sprite(m_renderTextures[1].getTexture());
        m_renderTextures[0].draw(sprite, verticalBlur.get());

        sprite = sf::Sprite(m_renderTextures[0].getTexture());
        target.draw(sprite, pixel.get());
    } else {
        sprite = sf::Sprite(m_renderTextures[0].getTexture());
        target.draw(sprite);
    }

    // help
    setView(target);
    if(m_currentHelp != "" && m_helpProgress > 0 && m_helpProgress < 1) {
        float fade = glm::smoothstep(0.f, 0.1f, m_helpProgress) - glm::smoothstep(0.9f, 1.f, m_helpProgress);
        float wobble = sin(m_time * 5);

        float alpha = fade;
        float angle = tween::Cubic().easeIn(1 - fade, 0, 1, 1) * 0.2;
        float scale = (0.6 + 0.01 * wobble) * m_pixelSize;

        std::string texture = "help-" + m_currentHelp;
        auto tex = Root().resources.getTexture(texture);
        if(tex) {
            sf::Sprite sprite(*tex.get());
            glm::vec2 ang(-1, 0);
            glm::vec2 pos = m_player->position() - glm::vec2(0, 1.1f) + ang - glm::rotate(ang, angle);
            sprite.setPosition(pos.x, pos.y);
            sprite.setOrigin(tex->getSize().x / 2, tex->getSize().y / 2);
            sprite.setColor(sf::Color(255, 255, 255, 255 * alpha));
            sprite.setScale(scale, scale);
            sprite.setRotation(wobble + thor::toDegree(angle));
            target.draw(sprite);
        }
    }

    // message
    target.setView(target.getDefaultView());
    if(m_message != "") {
        float alpha = fmin(1, fmax(0, m_messageTime)) * fmin(1, fmax(0, 4 - m_messageTime));
        alpha = tween::Cubic().easeOut(alpha, 0, 1, 1);

        sf::Text text;
        text.setFont(* Root().resources.getFont("default"));
        text.setCharacterSize(36);
        text.setString(m_message);
        text.setStyle(sf::Text::Bold);
        text.setPosition(sf::Vector2f(target.getSize().x / 2 - text.getLocalBounds().width / 2, target.getSize().y * 0.8 - fabs(sin(m_time)) * 20));
        text.setColor(sf::Color(255, 255, 255, 255 * alpha));

        sf::Vector2f b(10, 5);
        sf::RectangleShape rect(sf::Vector2f(text.getLocalBounds().width + 2 * b.x, text.getLocalBounds().height * 1.5 + 2 * b.y));
        rect.setPosition(text.getPosition() - b);
        rect.setFillColor(sf::Color(0, 0, 0, 100 * alpha));

        target.draw(rect);
        target.draw(text);
    }

    if(Root().debug) {
        sf::Text text;
        text.setFont(* Root().resources.getFont("mono"));
        text.setCharacterSize(20);
        text.setString(std::to_string(getFPS()) + " FPS");
        text.setPosition(sf::Vector2f(10, 10));
        text.setColor(sf::Color(255, 255, 255, 100));
        target.draw(text);
    }

    if(m_levelFade) {
        sf::RectangleShape rect(sf::Vector2f(target.getSize()));
        rect.setFillColor(sf::Color(0, 0, 0, 255 * m_levelFade));
        target.draw(rect);
    }
}