|  | @@ -21,12 +21,12 @@
 | 
	
		
			
				|  |  |  #include "IngameState.hpp"
 | 
	
		
			
				|  |  |  #include "Player.hpp"
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -IngameState::IngameState(): State(), _player(), _paused(false), _blurSize(0.f), _frameAlpha(0.f), _wormhole() {}
 | 
	
		
			
				|  |  | +IngameState::IngameState(): State(), _player(), _paused(false), _blurSize(0.f), _frameAlpha(0.f), _wormhole(), _starsCollected(0) {}
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  IngameState::~IngameState()
 | 
	
		
			
				|  |  |  {
 | 
	
		
			
				|  |  |  	Echo::debug("Flushing state");
 | 
	
		
			
				|  |  | -	_lightSystem.removeLight(_light);
 | 
	
		
			
				|  |  | +	_lightSystem.removeLight(_player.light());
 | 
	
		
			
				|  |  |  	_lightSystem.removeLight(_wormhole.light());
 | 
	
		
			
				|  |  |  }
 | 
	
		
			
				|  |  |  
 | 
	
	
		
			
				|  | @@ -50,16 +50,14 @@ void IngameState::init()
 | 
	
		
			
				|  |  |  	_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(rand() % 10 == 0 ? "data/triangle/Illuminati.png" : "data/triangle/Texture.png"));
 | 
	
		
			
				|  |  | +	bool illuminati = (rand() % 10 == 0);
 | 
	
		
			
				|  |  | +	_player.setIlluminati(illuminati);
 | 
	
		
			
				|  |  | +	_player.setContext(_context); 
 | 
	
		
			
				|  |  | +	_player.setTexture(_context->assets->loadTexture(illuminati ? "data/triangle/Illuminati.png" : "data/triangle/Texture.png"));
 | 
	
		
			
				|  |  |  	_player.setPosition(556.f, 2200.f);
 | 
	
		
			
				|  |  | -	
 | 
	
		
			
				|  |  | +	 
 | 
	
		
			
				|  |  |  	_foreground.create("data/background/Foreground.jpg", "data/background/Foreground_normal.jpg", "data/background/75pxjitter03.png");
 | 
	
		
			
				|  |  |  	_context->foreground = &_foreground;
 | 
	
		
			
				|  |  | -	_spike.create("data/background/Foreground.jpg", "data/background/Foreground_normal.jpg", "data/background/Spikes16px.png");
 | 
	
		
			
				|  |  | -	_spike.setResolution(sf::Vector2u(0, 0));
 | 
	
		
			
				|  |  | -	_spike.move(sf::Vector2f(1020, 2310));
 | 
	
		
			
				|  |  | -	_spike.rotate(332.f);
 | 
	
		
			
				|  |  |  	
 | 
	
		
			
				|  |  |  	_background.setTextureRect(sf::IntRect(0, 0, _foreground.getSize().x, _foreground.getSize().y));
 | 
	
		
			
				|  |  |  	
 | 
	
	
		
			
				|  | @@ -72,13 +70,6 @@ void IngameState::init()
 | 
	
		
			
				|  |  |  	_penumbraTexture.loadFromFile("data/light/penumbraTexture.png");
 | 
	
		
			
				|  |  |  	_penumbraTexture.setSmooth(true);
 | 
	
		
			
				|  |  |  	
 | 
	
		
			
				|  |  | -	_light = std::make_shared<ltbl::LightPointEmission>();
 | 
	
		
			
				|  |  | -	_light->_emissionSprite.setPosition(0.f, 0.f);
 | 
	
		
			
				|  |  | -	_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
 | 
	
		
			
				|  |  | -	
 | 
	
		
			
				|  |  |  	_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");
 | 
	
		
			
				|  |  |  	
 | 
	
	
		
			
				|  | @@ -86,15 +77,25 @@ void IngameState::init()
 | 
	
		
			
				|  |  |  	_dotaSound.setBuffer(_context->assets->loadSound("data/audio/Victory.ogg"));
 | 
	
		
			
				|  |  |  	
 | 
	
		
			
				|  |  |  	_wormhole.load(_context->assets->loadTexture("data/triangle/Wormhole.png"), _context->assets->loadTexture("data/triangle/Wormhole_light.png"));
 | 
	
		
			
				|  |  | -	_wormhole.setPosition(400.f, 400.f);
 | 
	
		
			
				|  |  | +	_wormhole.setPosition(_foreground.getWormholePosition());
 | 
	
		
			
				|  |  | +	
 | 
	
		
			
				|  |  | +	sf::Vector2f starPosition;
 | 
	
		
			
				|  |  | +	while(_foreground.getStarPosition(starPosition))
 | 
	
		
			
				|  |  | +		_star.emplace_back(_context->assets->loadTexture("data/triangle/Star.png"), _context->assets->loadTexture("data/light/Star.png"), starPosition);
 | 
	
		
			
				|  |  | +	_starsCount = _star.size();
 | 
	
		
			
				|  |  |  	
 | 
	
		
			
				|  |  |  	_statsTime.setFont(_context->assets->loadFont("data/ttf/canonical/Ubuntu-L.ttf"));
 | 
	
		
			
				|  |  |  	_statsHull.setFont(_context->assets->loadFont("data/ttf/canonical/Ubuntu-L.ttf"));
 | 
	
		
			
				|  |  | +	_statsStars.setFont(_context->assets->loadFont("data/ttf/canonical/Ubuntu-L.ttf"));
 | 
	
		
			
				|  |  |  	_statsTime.setCharacterSize(30);
 | 
	
		
			
				|  |  |  	_statsHull.setCharacterSize(30);
 | 
	
		
			
				|  |  | +	_statsStars.setCharacterSize(30);
 | 
	
		
			
				|  |  |  	
 | 
	
		
			
				|  |  |  	// Global window is not initialized yet in this method. If you need _context->window->getSize(), go to refresh() instead.
 | 
	
		
			
				|  |  |  	
 | 
	
		
			
				|  |  | +	_music.openFromFile("data/audio/Ossuary 6 - Air.ogg");
 | 
	
		
			
				|  |  | +	_music.setLoop(true);
 | 
	
		
			
				|  |  | +	_music.play();
 | 
	
		
			
				|  |  |  	_totalTime.restart();
 | 
	
		
			
				|  |  |  	_status = State::Ongoing;
 | 
	
		
			
				|  |  |  }
 | 
	
	
		
			
				|  | @@ -105,6 +106,7 @@ void IngameState::refresh()
 | 
	
		
			
				|  |  |  	//_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.setTwilightViewport(0, 0);
 | 
	
		
			
				|  |  |  	_camera.setCenter(_player.getPosition());
 | 
	
		
			
				|  |  |  	_foreground.setResolution(res);
 | 
	
		
			
				|  |  |  	
 | 
	
	
		
			
				|  | @@ -114,14 +116,18 @@ void IngameState::refresh()
 | 
	
		
			
				|  |  |  	_wasted.setPosition(_context->window->getSize().x / 2.f, _context->window->getSize().y * 1.5f);
 | 
	
		
			
				|  |  |  	_statsTime.setPosition(_wasted.getPosition().x, _wasted.getPosition().y + 100.f);
 | 
	
		
			
				|  |  |  	_statsHull.setPosition(_wasted.getPosition().x, _wasted.getPosition().y + 100.f);
 | 
	
		
			
				|  |  | +	_statsStars.setPosition(_wasted.getPosition().x, _wasted.getPosition().y + 100.f);
 | 
	
		
			
				|  |  |  	
 | 
	
		
			
				|  |  |  	_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}}, {_context->window->getSize().x, _context->window->getSize().y}, _penumbraTexture, _unshadowShader, _lightOverShapeShader, _normalsShader);
 | 
	
		
			
				|  |  |  	_lightSystem.normalsEnabled(true);
 | 
	
		
			
				|  |  | -	_lightSystem.addLight(_light);
 | 
	
		
			
				|  |  | +	_lightSystem.addLight(_player.light());
 | 
	
		
			
				|  |  |  	_lightSystem.addLight(_wormhole.light());
 | 
	
		
			
				|  |  | +	unsigned k = _star.size();
 | 
	
		
			
				|  |  | +	for(unsigned i = 0; i < k; ++i)
 | 
	
		
			
				|  |  | +		_lightSystem.addLight(_star[i].light());
 | 
	
		
			
				|  |  |  }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  void IngameState::coreThink(const sf::Event& event)
 | 
	
	
		
			
				|  | @@ -163,11 +169,12 @@ void IngameState::coreUpdate(sf::Time delta)
 | 
	
		
			
				|  |  |  		|| (_wasted.getPosition().y < -_context->window->getSize().y / 2.f 
 | 
	
		
			
				|  |  |  		&& _marioSound.getStatus() == sf::Sound::Status::Stopped && !_player.hasWon()))
 | 
	
		
			
				|  |  |  		{
 | 
	
		
			
				|  |  | -			_wasted.move(0.f, -250.f * delta.asSeconds());
 | 
	
		
			
				|  |  | +			_wasted.move(0.f, -400.f * delta.asSeconds() * (_context->window->getSize().y / 1080.f));
 | 
	
		
			
				|  |  |  			if(_player.hasWon())
 | 
	
		
			
				|  |  |  			{
 | 
	
		
			
				|  |  |  				_statsTime.setPosition(_wasted.getPosition().x, _wasted.getPosition().y + 100.f);
 | 
	
		
			
				|  |  |  				_statsHull.setPosition(_wasted.getPosition().x, _wasted.getPosition().y + 100.f);
 | 
	
		
			
				|  |  | +				_statsStars.setPosition(_wasted.getPosition().x, _wasted.getPosition().y + 100.f);
 | 
	
		
			
				|  |  |  			}
 | 
	
		
			
				|  |  |  		}
 | 
	
		
			
				|  |  |  	}
 | 
	
	
		
			
				|  | @@ -181,7 +188,6 @@ 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());
 | 
	
		
			
				|  |  |  	_foreground.setPosition(_camera.getCenter() - _camera.getSize() / 2.f);
 | 
	
		
			
				|  |  |  	
 | 
	
		
			
				|  |  |  	if(_player.checkCollision(_foreground)) /// True if the target died.
 | 
	
	
		
			
				|  | @@ -189,6 +195,7 @@ void IngameState::coreUpdate(sf::Time delta)
 | 
	
		
			
				|  |  |  		_paused = true;
 | 
	
		
			
				|  |  |  		_wasted.setTexture(_context->assets->loadTexture("data/background/Wasted.png"));
 | 
	
		
			
				|  |  |  		_wasted.setOrigin(sf::Vector2f(_context->assets->loadTexture("data/background/Wasted.png").getSize() / 2u));
 | 
	
		
			
				|  |  | +		_music.stop();
 | 
	
		
			
				|  |  |  		_marioSound.play();
 | 
	
		
			
				|  |  |  	}
 | 
	
		
			
				|  |  |  	else if(_player.isDead() && _player.hasWon())
 | 
	
	
		
			
				|  | @@ -205,8 +212,14 @@ void IngameState::coreUpdate(sf::Time delta)
 | 
	
		
			
				|  |  |  		oss.clear();
 | 
	
		
			
				|  |  |  		oss << "Hull: " << int(_player.getHullLeft()) << "%";
 | 
	
		
			
				|  |  |  		_statsHull.setString(oss.str());
 | 
	
		
			
				|  |  | -		_statsTime.setOrigin(_statsTime.getLocalBounds().width / 2.f, _statsTime.getLocalBounds().height / 2.f - 30.f);
 | 
	
		
			
				|  |  | -		_statsHull.setOrigin(_statsTime.getLocalBounds().width / 2.f, _statsTime.getLocalBounds().height + _statsHull.getLocalBounds().height / 2.f);
 | 
	
		
			
				|  |  | +		oss.str(std::string());
 | 
	
		
			
				|  |  | +		oss.clear();
 | 
	
		
			
				|  |  | +		oss << "Stars: " << _starsCollected << '/' << _starsCount;
 | 
	
		
			
				|  |  | +		_statsStars.setString(oss.str());
 | 
	
		
			
				|  |  | +		_statsTime.setOrigin(_statsTime.getLocalBounds().width / 2.f, _statsTime.getLocalBounds().height / 2.f + 60.f);
 | 
	
		
			
				|  |  | +		_statsHull.setOrigin(_statsTime.getLocalBounds().width / 2.f, _statsTime.getLocalBounds().height / 2.f - _statsHull.getLocalBounds().height + 30.f);
 | 
	
		
			
				|  |  | +		_statsStars.setOrigin(_statsTime.getLocalBounds().width / 2.f, _statsTime.getLocalBounds().height / 2.f - _statsHull.getLocalBounds().height  - _statsStars.getLocalBounds().height);
 | 
	
		
			
				|  |  | +		_music.stop();
 | 
	
		
			
				|  |  |  		_dotaSound.play();
 | 
	
		
			
				|  |  |  	}
 | 
	
		
			
				|  |  |  	
 | 
	
	
		
			
				|  | @@ -228,6 +241,30 @@ void IngameState::coreUpdate(sf::Time delta)
 | 
	
		
			
				|  |  |  		else
 | 
	
		
			
				|  |  |  			_player.setScale(1.f, 1.f);
 | 
	
		
			
				|  |  |  	}
 | 
	
		
			
				|  |  | +	
 | 
	
		
			
				|  |  | +	for(unsigned i = 0; i < _star.size(); ++i)
 | 
	
		
			
				|  |  | +	{
 | 
	
		
			
				|  |  | +		if(_star[i].gravity(_player.getPosition(), delta))
 | 
	
		
			
				|  |  | +		{
 | 
	
		
			
				|  |  | +			_lightSystem.removeLight(_star[i].light());
 | 
	
		
			
				|  |  | +			_star.erase(_star.begin() + i);
 | 
	
		
			
				|  |  | +			_starsCollected++;
 | 
	
		
			
				|  |  | +		}
 | 
	
		
			
				|  |  | +	}
 | 
	
		
			
				|  |  | +	
 | 
	
		
			
				|  |  | +	{
 | 
	
		
			
				|  |  | +		const double degree = 3.14159265358 / 180.;
 | 
	
		
			
				|  |  | +		static float offset = 0.f;
 | 
	
		
			
				|  |  | +		static bool direction = false;
 | 
	
		
			
				|  |  | +		sf::Vector2f movement;
 | 
	
		
			
				|  |  | +		movement.x = std::sin((direction ? 152.f : 332.f) * degree) * (direction ? 1500.f : 100.f) * seconds;
 | 
	
		
			
				|  |  | +		movement.y = -std::cos((direction ? 152.f : 332.f) * degree) * (direction ? 1500.f : 100.f) * seconds;
 | 
	
		
			
				|  |  | +		offset += movement.y;
 | 
	
		
			
				|  |  | +		if(offset < -256.f)
 | 
	
		
			
				|  |  | +			direction = true;
 | 
	
		
			
				|  |  | +		if(offset >= 0.f)
 | 
	
		
			
				|  |  | +			direction = false;
 | 
	
		
			
				|  |  | +	}
 | 
	
		
			
				|  |  |  }
 | 
	
		
			
				|  |  |  void IngameState::coreRender(const bool shaders)
 | 
	
		
			
				|  |  |  {
 | 
	
	
		
			
				|  | @@ -259,6 +296,7 @@ void IngameState::coreRender(const bool shaders)
 | 
	
		
			
				|  |  |  		_context->window->draw(_wasted);
 | 
	
		
			
				|  |  |  		_context->window->draw(_statsTime);
 | 
	
		
			
				|  |  |  		_context->window->draw(_statsHull);
 | 
	
		
			
				|  |  | +		_context->window->draw(_statsStars);
 | 
	
		
			
				|  |  |  	}
 | 
	
		
			
				|  |  |  	else
 | 
	
		
			
				|  |  |  	{
 | 
	
	
		
			
				|  | @@ -267,19 +305,17 @@ void IngameState::coreRender(const bool shaders)
 | 
	
		
			
				|  |  |  		
 | 
	
		
			
				|  |  |  		
 | 
	
		
			
				|  |  |  		_foreground.renderNormals(true);
 | 
	
		
			
				|  |  | -		_spike.renderNormals(true);
 | 
	
		
			
				|  |  |  		_lightSystem.normalsTargetSetView(*_camera.getView());
 | 
	
		
			
				|  |  |  		_lightSystem.normalsTargetClear();
 | 
	
		
			
				|  |  | -		_lightSystem.normalsTargetDraw(_spike);
 | 
	
		
			
				|  |  |  		_lightSystem.normalsTargetDraw(_foreground);
 | 
	
		
			
				|  |  |  		_lightSystem.normalsTargetDisplay();
 | 
	
		
			
				|  |  |  		_lightSystem.render(*_camera.getView(), _unshadowShader, _lightOverShapeShader, _normalsShader);
 | 
	
		
			
				|  |  |  		
 | 
	
		
			
				|  |  |  		
 | 
	
		
			
				|  |  |  		_foreground.renderNormals(false);
 | 
	
		
			
				|  |  | -		_spike.renderNormals(false);
 | 
	
		
			
				|  |  | -		_context->window->draw(_spike);
 | 
	
		
			
				|  |  |  		_context->window->draw(_foreground);
 | 
	
		
			
				|  |  | +		for(unsigned i = 0; i < _star.size(); ++i)
 | 
	
		
			
				|  |  | +			_context->window->draw(_star[i]);
 | 
	
		
			
				|  |  |  		_context->window->draw(_wormhole);
 | 
	
		
			
				|  |  |  		_context->window->draw(_player);
 | 
	
		
			
				|  |  |  		
 |