|
@@ -1,12 +1,25 @@
|
|
|
+/**
|
|
|
+ * Triangles
|
|
|
+ * Copyright (C) 2016 POSITIVE MENTAL ATTITUDE
|
|
|
+ *
|
|
|
+ * This program is free software: you can redistribute it and/or modify
|
|
|
+ * it under the terms of the GNU General Public License as published by
|
|
|
+ * the Free Software Foundation, version 3 of the License.
|
|
|
+ *
|
|
|
+ * This program is distributed in the hope that it will be useful,
|
|
|
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
+ * GNU General Public License for more details.
|
|
|
+ *
|
|
|
+ * You should have received a copy of the GNU General Public License
|
|
|
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
+ */
|
|
|
+
|
|
|
#include "IngameState.hpp"
|
|
|
#include "Player.hpp"
|
|
|
#include <thread>
|
|
|
|
|
|
-IngameState::IngameState(): State(), _player(), _paused(false), _blurSize(0.f), _frameAlpha(0.f)
|
|
|
-{
|
|
|
-
|
|
|
-}
|
|
|
-
|
|
|
+IngameState::IngameState(): State(), _player(), _paused(false), _blurSize(0.f), _frameAlpha(0.f) {}
|
|
|
|
|
|
Rect Player::getBounds()
|
|
|
{
|
|
@@ -25,31 +38,33 @@ Rect Player::getBounds()
|
|
|
|
|
|
void IngameState::init()
|
|
|
{
|
|
|
- _background.setTexture(_context->assets->loadTexture("data/background/Background.png"));
|
|
|
- _context->assets->loadTexture("data/background/Background.png").setRepeated(true);
|
|
|
+ _background.setTexture(_context->assets->loadTexture("data/background/Background.jpg"));
|
|
|
+ _context->assets->loadTexture("data/background/Background.jpg").setRepeated(true);
|
|
|
|
|
|
_player.setContext(_context);
|
|
|
- _player.setTexture(_context->assets->loadTexture("data/triangle/Texture.png"));
|
|
|
+ _player.setTexture(_context->assets->loadTexture(rand() % 10 == 0 ? "data/triangle/Illuminati.png" : "data/triangle/Texture.png"));
|
|
|
_player.setPosition(400.f, 400.f);
|
|
|
|
|
|
- _foreground.create("data/background/Foreground.png", "data/background/75pxjitter03.png");
|
|
|
+ _foreground.create("data/background/Foreground.jpg", "data/background/Foreground_normal.jpg", "data/background/75pxjitter03.png");
|
|
|
_context->foreground = &_foreground;
|
|
|
|
|
|
+ _background.setTextureRect(sf::IntRect(0, 0, _foreground.getSize().x, _foreground.getSize().y));
|
|
|
+
|
|
|
_pauseFrame.setFillColor(sf::Color(0, 0, 0, 155));
|
|
|
_pauseFrame.setPosition(0, 0);
|
|
|
|
|
|
- /*_unshadowShader.loadFromFile("assets/unshadowShader.frag", sf::Shader::Fragment);
|
|
|
- _lightOverShapeShader.loadFromFile("assets/lightOverShapeShader.frag", sf::Shader::Fragment);
|
|
|
- _normalsShader.loadFromFile("assets/normalsShader.frag", sf::Shader::Fragment);
|
|
|
+ _unshadowShader.loadFromFile("data/light/unshadowShader.frag", sf::Shader::Fragment);
|
|
|
+ _lightOverShapeShader.loadFromFile("data/light/lightOverShapeShader.frag", sf::Shader::Fragment);
|
|
|
+ _normalsShader.loadFromFile("data/light/normalsShader.frag", sf::Shader::Fragment);
|
|
|
_penumbraTexture.loadFromFile("data/light/penumbraTexture.png");
|
|
|
- _penumbraTexture.setSmooth(true);*/
|
|
|
+ _penumbraTexture.setSmooth(true);
|
|
|
|
|
|
- /*_light = std::make_shared<ltbl::LightPointEmission>();
|
|
|
- _light->_emissionSprite.setOrigin(330.f, 871.f);
|
|
|
+ _light = std::make_shared<ltbl::LightPointEmission>();
|
|
|
_light->_emissionSprite.setPosition(0.f, 0.f);
|
|
|
- _light->_emissionSprite.setTexture(_context->assets->loadTexture("data/background/texture.png"));
|
|
|
+ _light->_emissionSprite.setTexture(_context->assets->loadTexture("data/background/Light.png"));
|
|
|
+ _light->_emissionSprite.setOrigin(sf::Vector2f(_context->assets->loadTexture("data/background/Light.png").getSize() / 2u));
|
|
|
_light->_emissionSprite.setColor(sf::Color::White);
|
|
|
- _light->_localCastCenter = sf::Vector2f(0.0f, 0.0f); // This is where the shadows emanate from relative to the sprite*/
|
|
|
+ _light->_localCastCenter = sf::Vector2f(0.0f, 0.0f); // This is where the shadows emanate from relative to the sprite
|
|
|
|
|
|
_blurV.loadFromFile("data/shaders/old_pi_blur/blur.vert", "data/shaders/old_pi_blur/blur-v.frag");
|
|
|
_blurH.loadFromFile("data/shaders/old_pi_blur/blur.vert", "data/shaders/old_pi_blur/blur-h.frag");
|
|
@@ -65,7 +80,7 @@ void IngameState::init()
|
|
|
void IngameState::refresh()
|
|
|
{
|
|
|
sf::Vector2u res = _context->window->getSize();
|
|
|
- _background.setTextureRect(sf::IntRect(0, 0, _context->window->getSize().x, _context->window->getSize().y));
|
|
|
+ //_background.setTextureRect(sf::IntRect(0, 0, _context->window->getSize().x, _context->window->getSize().y));
|
|
|
_camera.setSize(static_cast<sf::Vector2f>(_context->window->getSize()));
|
|
|
_camera.setTwilightViewport(_context->window->getSize().x / 2.f - 240.f/* * (bool) _czyWOgóleTwilightViewportMaByć*/, _context->window->getSize().y / 2.f - 240.f);
|
|
|
_camera.setCenter(_player.getPosition());
|
|
@@ -78,10 +93,10 @@ void IngameState::refresh()
|
|
|
|
|
|
_backgroundH.create(_context->window->getSize().x, _context->window->getSize().y);
|
|
|
_backgroundV.create(_context->window->getSize().x, _context->window->getSize().y);
|
|
|
-
|
|
|
- //_lightSystem.create(sf::FloatRect{{0.f, 0.f}, {0.f, 0.f}}, {1920, 1080}, _penumbraTexture, _unshadowShader, _lightOverShapeShader, _normalsShader);
|
|
|
- //_lightSystem.normalsEnabled(true);
|
|
|
- //_lightSystem.addLight(_light);
|
|
|
+
|
|
|
+ _lightSystem.create(sf::FloatRect{{0.f, 0.f}, {0.f, 0.f}}, {_context->window->getSize().x, _context->window->getSize().y}, _penumbraTexture, _unshadowShader, _lightOverShapeShader, _normalsShader);
|
|
|
+ _lightSystem.normalsEnabled(true);
|
|
|
+ _lightSystem.addLight(_light);
|
|
|
}
|
|
|
|
|
|
void IngameState::coreThink(const sf::Event& event)
|
|
@@ -133,8 +148,7 @@ void IngameState::coreUpdate(sf::Time delta)
|
|
|
const sf::Vector2f pos = _player.getPosition();
|
|
|
_player.update(delta);
|
|
|
_camera.move(_player.getPosition() - pos);
|
|
|
- //_light->_emissionSprite.setPosition(_player.getPosition());
|
|
|
- //_light->_emissionSprite.setRotation(_player.getRotation());
|
|
|
+ _light->_emissionSprite.setPosition(_player.getPosition());
|
|
|
_foreground.setPosition(_camera.getCenter() - _camera.getSize() / 2.f);
|
|
|
|
|
|
if(_player.checkCollision(_foreground)) /// True if the target died.
|
|
@@ -147,19 +161,22 @@ void IngameState::coreRender(const bool shaders)
|
|
|
{
|
|
|
if(_player.isDead())
|
|
|
{
|
|
|
- // _blurH.setParameter("RTScene", backgroundH.getTexture());
|
|
|
- // _blurV.setParameter("RTBlurH", backgroundV.getTexture());
|
|
|
-
|
|
|
- _background.setTexture(_context->assets->loadTexture("data/background/Background.png"));
|
|
|
_backgroundH.draw(_background);
|
|
|
_backgroundH.setView(*_camera.getView());
|
|
|
_backgroundH.draw(_foreground);
|
|
|
_backgroundH.draw(_player);
|
|
|
+ sf::Sprite sprite3(_lightSystem.getLightingTexture());
|
|
|
+ sf::RenderStates lightRenderStates;
|
|
|
+ lightRenderStates.blendMode = sf::BlendMultiply;
|
|
|
+ _backgroundH.setView(_context->window->getDefaultView());
|
|
|
+ _backgroundH.draw(sprite3, lightRenderStates);
|
|
|
+
|
|
|
sf::Sprite sprite(_backgroundH.getTexture());
|
|
|
sprite.setScale(1.f, -1.f);
|
|
|
sprite.setOrigin(0, _context->window->getSize().y);
|
|
|
sprite.setPosition(0.f, 0.f);
|
|
|
_backgroundV.draw(sprite, &_blurH);
|
|
|
+
|
|
|
sf::Sprite sprite2(_backgroundV.getTexture());
|
|
|
sprite2.setScale(1.f, -1.f);
|
|
|
sprite2.setOrigin(0, _context->window->getSize().y);
|
|
@@ -170,25 +187,30 @@ void IngameState::coreRender(const bool shaders)
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
-
|
|
|
- //_lightSystem.normalsTargetClear();
|
|
|
- _background.setTexture(_context->assets->loadTexture("data/background/Background.png"));
|
|
|
- _context->window->draw(_background);//, &_normalBackground);
|
|
|
- //_background.setTexture(_context->assets->loadTexture("data/background/normal.JPG"));
|
|
|
- //_lightSystem.normalsTargetDraw(_background);
|
|
|
- //_lightSystem.normalsTargetDraw(_foreground);
|
|
|
- _context->window->setView(_camera.getView());
|
|
|
- _context->window->draw(_foreground);
|
|
|
- //_context->window->draw(_foreground);
|
|
|
- _context->window->draw(_player);
|
|
|
- //_lightSystem.normalsTargetDisplay();
|
|
|
- //_lightSystem.render(*_camera.getView(), _unshadowShader, _lightOverShapeShader, _normalsShader);
|
|
|
- //sf::Sprite sprite(_lightSystem.getLightingTexture());
|
|
|
- //sf::RenderStates lightRenderStates;
|
|
|
- //lightRenderStates.blendMode = sf::BlendMultiply;
|
|
|
- //_context->window->draw(sprite, lightRenderStates);
|
|
|
- _context->window->setView();
|
|
|
- if(_paused)
|
|
|
- _context->window->draw(_pauseFrame);
|
|
|
+ _context->window->setView(_camera.getView());
|
|
|
+ _context->window->draw(_background);
|
|
|
+
|
|
|
+
|
|
|
+ _foreground.renderNormals(true);
|
|
|
+ _lightSystem.normalsTargetSetView(*_camera.getView());
|
|
|
+ _lightSystem.normalsTargetClear();
|
|
|
+ _lightSystem.normalsTargetDraw(_foreground);
|
|
|
+ _lightSystem.normalsTargetDisplay();
|
|
|
+ _lightSystem.render(*_camera.getView(), _unshadowShader, _lightOverShapeShader, _normalsShader);
|
|
|
+
|
|
|
+
|
|
|
+ _foreground.renderNormals(false);
|
|
|
+ _context->window->draw(_foreground);
|
|
|
+ _context->window->draw(_player);
|
|
|
+
|
|
|
+
|
|
|
+ _context->window->setView();
|
|
|
+ sf::Sprite sprite(_lightSystem.getLightingTexture());
|
|
|
+ sf::RenderStates lightRenderStates;
|
|
|
+ lightRenderStates.blendMode = sf::BlendMultiply;
|
|
|
+ _context->window->draw(sprite, lightRenderStates);
|
|
|
+
|
|
|
+ if(_paused)
|
|
|
+ _context->window->draw(_pauseFrame);
|
|
|
}
|
|
|
}
|