Browse Source

v-0.9.8 update

POSITIVE-MENTAL-ATTITUDE 8 years ago
parent
commit
c86c28ac59

BIN
data/audio/Victory.ogg


+ 4 - 0
data/audio/about.txt

@@ -30,3 +30,7 @@ Shotgun Blast sound by Jim Rogers
 Licensed under Creative Commons: Attribution 3.0 License
 Licensed under Creative Commons: Attribution 3.0 License
 http://creativecommons.org/licenses/by/3.0/
 http://creativecommons.org/licenses/by/3.0/
 Received from soundbible.com/1919-Shotgun-Blast.html
 Received from soundbible.com/1919-Shotgun-Blast.html
+
+Victory.ogg:
+Stolen from Dota 2.
+Temporary placeholder; definitely to be replaced.

BIN
data/background/Victory.png


BIN
data/background/Wasted.png


+ 65 - 7
src/IngameState.cpp

@@ -15,9 +15,11 @@
  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
  */
 
 
+#include <cmath>
+#include <thread>
+#include <sstream>
 #include "IngameState.hpp"
 #include "IngameState.hpp"
 #include "Player.hpp"
 #include "Player.hpp"
-#include <thread>
 
 
 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() {}
 
 
@@ -50,7 +52,7 @@ void IngameState::init()
 
 
 	_player.setContext(_context);
 	_player.setContext(_context);
 	_player.setTexture(_context->assets->loadTexture(rand() % 10 == 0 ? "data/triangle/Illuminati.png" : "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);
+	_player.setPosition(556.f, 2200.f);
 	
 	
 	_foreground.create("data/background/Foreground.jpg", "data/background/Foreground_normal.jpg", "data/background/75pxjitter03.png");
 	_foreground.create("data/background/Foreground.jpg", "data/background/Foreground_normal.jpg", "data/background/75pxjitter03.png");
 	_context->foreground = &_foreground;
 	_context->foreground = &_foreground;
@@ -77,13 +79,19 @@ void IngameState::init()
 	_blurH.loadFromFile("data/shaders/old_pi_blur/blur.vert", "data/shaders/old_pi_blur/blur-h.frag");
 	_blurH.loadFromFile("data/shaders/old_pi_blur/blur.vert", "data/shaders/old_pi_blur/blur-h.frag");
 	
 	
 	_marioSound.setBuffer(_context->assets->loadSound("data/audio/Mario.ogg"));
 	_marioSound.setBuffer(_context->assets->loadSound("data/audio/Mario.ogg"));
-	_wasted.setTexture(_context->assets->loadTexture("data/background/Wasted.png"));
+	_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.load(_context->assets->loadTexture("data/triangle/Wormhole.png"), _context->assets->loadTexture("data/triangle/Wormhole_light.png"));
 	_wormhole.setPosition(400.f, 400.f);
 	_wormhole.setPosition(400.f, 400.f);
 	
 	
+	_statsTime.setFont(_context->assets->loadFont("data/ttf/canonical/Ubuntu-L.ttf"));
+	_statsHull.setFont(_context->assets->loadFont("data/ttf/canonical/Ubuntu-L.ttf"));
+	_statsTime.setCharacterSize(30);
+	_statsHull.setCharacterSize(30);
+	
 	// Global window is not initialized yet in this method. If you need _context->window->getSize(), go to refresh() instead.
 	// Global window is not initialized yet in this method. If you need _context->window->getSize(), go to refresh() instead.
 	
 	
+	_totalTime.restart();
 	_status = State::Ongoing;
 	_status = State::Ongoing;
 }
 }
 
 
@@ -99,7 +107,9 @@ void IngameState::refresh()
 	_pauseFrame.setSize((sf::Vector2f)res);
 	_pauseFrame.setSize((sf::Vector2f)res);
 	
 	
 	_wasted.setScale(_context->window->getSize().x / 1920.f,  _context->window->getSize().y / 1080.f);
 	_wasted.setScale(_context->window->getSize().x / 1920.f,  _context->window->getSize().y / 1080.f);
-	_wasted.setPosition(0, _context->window->getSize().y);
+	_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);
 	
 	
 	_backgroundH.create(_context->window->getSize().x, _context->window->getSize().y);
 	_backgroundH.create(_context->window->getSize().x, _context->window->getSize().y);
 	_backgroundV.create(_context->window->getSize().x, _context->window->getSize().y);
 	_backgroundV.create(_context->window->getSize().x, _context->window->getSize().y);
@@ -127,6 +137,7 @@ void IngameState::coreInput()
 }
 }
 void IngameState::coreUpdate(sf::Time delta)
 void IngameState::coreUpdate(sf::Time delta)
 {
 {
+	float seconds = delta.asSeconds();
 	if(_player.isDead())
 	if(_player.isDead())
 	{
 	{
 		if(_blurSize < 4.f)
 		if(_blurSize < 4.f)
@@ -144,10 +155,17 @@ void IngameState::coreUpdate(sf::Time delta)
 		_blurH.setParameter("blurSize", _blurSize / _context->window->getSize().x);
 		_blurH.setParameter("blurSize", _blurSize / _context->window->getSize().x);
 		_blurV.setParameter("blurSize", _blurSize / _context->window->getSize().y);
 		_blurV.setParameter("blurSize", _blurSize / _context->window->getSize().y);
 		
 		
-		if(_wasted.getPosition().y > 0.f)
+		if((_wasted.getPosition().y > _context->window->getSize().y / 2.f) 
+		|| (_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, -250.f * delta.asSeconds());
-		else if(_wasted.getPosition().y < 0.f)
-			_wasted.setPosition(0.f, 0.f);
+			if(_player.hasWon())
+			{
+				_statsTime.setPosition(_wasted.getPosition().x, _wasted.getPosition().y + 100.f);
+				_statsHull.setPosition(_wasted.getPosition().x, _wasted.getPosition().y + 100.f);
+			}
+		}
 	}
 	}
 
 
 	if(_paused)
 	if(_paused)
@@ -165,10 +183,47 @@ void IngameState::coreUpdate(sf::Time delta)
 	if(_player.checkCollision(_foreground)) /// True if the target died.
 	if(_player.checkCollision(_foreground)) /// True if the target died.
 	{
 	{
 		_paused = true;
 		_paused = true;
+		_wasted.setTexture(_context->assets->loadTexture("data/background/Wasted.png"));
+		_wasted.setOrigin(sf::Vector2f(_context->assets->loadTexture("data/background/Wasted.png").getSize() / 2u));
 		_marioSound.play();
 		_marioSound.play();
 	}
 	}
+	else if(_player.isDead() && _player.hasWon())
+	{
+		_paused = true;
+		_wasted.setTexture(_context->assets->loadTexture("data/background/Victory.png"));
+		_wasted.setOrigin(sf::Vector2f(_context->assets->loadTexture("data/background/Victory.png").getSize() / 2u));
+		std::ostringstream oss;
+		int minutesElapsed = int(_totalTime.getElapsedTime().asSeconds()) / 60;
+		int secondsElapsed = int(_totalTime.getElapsedTime().asSeconds()) % 60;
+		oss << "Time: " << minutesElapsed << ":" << (secondsElapsed < 10 ? "0" : "") << secondsElapsed;
+		_statsTime.setString(oss.str());
+		oss.str(std::string());
+		oss.clear();
+		oss << "Hull: " << int(_player.getHullLeft()) << "%";
+		_statsHull.setString(oss.str());
+		_statsTime.setOrigin(_statsTime.getLocalBounds().width / 2.f, _statsTime.getLocalBounds().height / 2.f);
+		_statsHull.setOrigin(_statsTime.getLocalBounds().width / 2.f, _statsTime.getLocalBounds().height + _statsHull.getLocalBounds().height / 2.f + 30.f);
+		_dotaSound.play();
+	}
 	
 	
 	_wormhole.update(delta);
 	_wormhole.update(delta);
+	
+	float gravity = _wormhole.gravity(_player.getPosition());
+	if(gravity < 1000.f)
+	{
+		float k = 1000000.f - gravity * gravity;
+		if(k > 0.f)
+		{
+			sf::Vector2f offset = k * seconds * 0.00025f * _wormhole.direction(_player.getPosition());
+			_camera.move(offset);
+			_player.move(offset);
+			_player.rotate(k * seconds * 0.0001f);
+		}
+		if(gravity < 200.f)
+			_player.setScale(gravity / 200.f, gravity / 200.f);
+		else
+			_player.setScale(1.f, 1.f);
+	}
 }
 }
 void IngameState::coreRender(const bool shaders)
 void IngameState::coreRender(const bool shaders)
 {
 {
@@ -177,6 +232,7 @@ void IngameState::coreRender(const bool shaders)
 		_backgroundH.draw(_background);
 		_backgroundH.draw(_background);
 		_backgroundH.setView(*_camera.getView());
 		_backgroundH.setView(*_camera.getView());
 		_backgroundH.draw(_foreground);
 		_backgroundH.draw(_foreground);
+		_backgroundH.draw(_wormhole);
 		_backgroundH.draw(_player);
 		_backgroundH.draw(_player);
 		sf::Sprite sprite3(_lightSystem.getLightingTexture());
 		sf::Sprite sprite3(_lightSystem.getLightingTexture());
 		sf::RenderStates lightRenderStates;
 		sf::RenderStates lightRenderStates;
@@ -197,6 +253,8 @@ void IngameState::coreRender(const bool shaders)
 		_context->window->draw(sprite2, &_blurH);
 		_context->window->draw(sprite2, &_blurH);
 		_context->window->draw(_pauseFrame);
 		_context->window->draw(_pauseFrame);
 		_context->window->draw(_wasted);
 		_context->window->draw(_wasted);
+		_context->window->draw(_statsTime);
+		_context->window->draw(_statsHull);
 	}
 	}
 	else
 	else
 	{
 	{

+ 6 - 0
src/IngameState.hpp

@@ -63,9 +63,15 @@ class IngameState: public State
 		float _frameAlpha;
 		float _frameAlpha;
 		
 		
 		sf::Sound _marioSound;
 		sf::Sound _marioSound;
+		sf::Sound _dotaSound;
 		sf::RenderTexture _backgroundH;
 		sf::RenderTexture _backgroundH;
 		sf::RenderTexture _backgroundV;
 		sf::RenderTexture _backgroundV;
 		
 		
+		sf::Text _statsTime;
+		sf::Text _statsHull;
+		
+		sf::Clock _totalTime;
+		
 		Wormhole _wormhole;
 		Wormhole _wormhole;
 };
 };
 
 

+ 23 - 4
src/Player.cpp

@@ -35,6 +35,7 @@ Player::Player():
 	_rotationSuppresion(20.f),
 	_rotationSuppresion(20.f),
 	_hit(false),
 	_hit(false),
 	_dead(false),
 	_dead(false),
+	_won(false),
 	_particleSystem(512, 512),
 	_particleSystem(512, 512),
 	_ammo(4),
 	_ammo(4),
 	_life(sf::Color::Red, 1.f),
 	_life(sf::Color::Red, 1.f),
@@ -139,6 +140,11 @@ bool Player::isDead()
 	return _dead;
 	return _dead;
 }
 }
 
 
+bool Player::hasWon()
+{
+	return _won;
+}
+
 void Player::setTexture(sf::Texture& texture)
 void Player::setTexture(sf::Texture& texture)
 {
 {
 	_innerTexture = texture;
 	_innerTexture = texture;
@@ -385,15 +391,28 @@ void Player::update(sf::Time delta)
 	_life.setPosition(position);
 	_life.setPosition(position);
 	_mana.setPosition(position);
 	_mana.setPosition(position);
 	
 	
-	_life.setSize(unsigned(((_pointCount * _durability - _cbanned.size()) / (_pointCount *  _durability)) * 100.f));
+	_life.setSize((unsigned)getHullLeft());
 	_mana.setSize(_ammo * 10);
 	_mana.setSize(_ammo * 10);
 	
 	
 	_life.update(delta);
 	_life.update(delta);
 	_mana.update(delta);
 	_mana.update(delta);
+	
+	if(getScale().x == 1.f)
+	{
+		_particleSystem.clear();
+		_particleSystem.update(delta);
+		_particleSystem.render();
+	}
+	if(getScale().x < 0.1f)
+	{
+		_dead = true;
+		_won = true;
+	}
+}
 
 
-	_particleSystem.clear();
-	_particleSystem.update(delta);
-	_particleSystem.render();
+float Player::getHullLeft()
+{
+	return ((_pointCount * _durability - _cbanned.size()) / (_pointCount *  _durability)) * 100.f;
 }
 }
 
 
 void Player::draw(sf::RenderTarget& target, sf::RenderStates states) const
 void Player::draw(sf::RenderTarget& target, sf::RenderStates states) const

+ 3 - 0
src/Player.hpp

@@ -49,10 +49,12 @@ class Player: public Triangle, public InputTarget<int>, public Collidable
 		 */
 		 */
 		bool checkCollision(Foreground& foreground);
 		bool checkCollision(Foreground& foreground);
 		bool isDead();
 		bool isDead();
+		bool hasWon();
 		Rect getBounds();
 		Rect getBounds();
 		sf::Image _image;
 		sf::Image _image;
 		sf::Texture _innerTexture;
 		sf::Texture _innerTexture;
 		void setContext(Context* context);
 		void setContext(Context* context);
+		float getHullLeft();
 
 
 	private:
 	private:
 		void keyboardControls(sf::Time delta);
 		void keyboardControls(sf::Time delta);
@@ -67,6 +69,7 @@ class Player: public Triangle, public InputTarget<int>, public Collidable
 		float _strafe;
 		float _strafe;
 		bool _hit;
 		bool _hit;
 		bool _dead;
 		bool _dead;
+		bool _won;
 		virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const final override;
 		virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const final override;
 		sf::Sound _glass;
 		sf::Sound _glass;
 		sf::Sound _deathSound;
 		sf::Sound _deathSound;

+ 1 - 1
src/Triangles.cpp

@@ -259,7 +259,7 @@ void Triangles::load(int stateType)
 int Triangles::run(unsigned count)
 int Triangles::run(unsigned count)
 {
 {
 	sf::Clock clock;
 	sf::Clock clock;
-	sf::Time delta, epsilon = sf::seconds(1.f / 60.f);
+	sf::Time delta, epsilon = sf::seconds(1.f / 30.f);
 	
 	
 	if(_context.running)
 	if(_context.running)
 	{
 	{

+ 41 - 0
src/Wormhole.cpp

@@ -1,3 +1,21 @@
+/**
+ *  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 <cmath>
 #include "Utility.hpp"
 #include "Utility.hpp"
 #include "Wormhole.hpp"
 #include "Wormhole.hpp"
 
 
@@ -44,6 +62,29 @@ std::shared_ptr<ltbl::LightPointEmission>& Wormhole::light()
 	return _light;
 	return _light;
 }
 }
 
 
+float Wormhole::gravity(sf::Vector2f position)
+{
+	sf::Vector2f delta = position - _sprite.getPosition();
+	if(delta.x < 1.f && delta.y < 1.f)
+		return 1.f;
+	return std::sqrt(delta.x * delta.x + delta.y * delta.y);
+}
+
+sf::Vector2f Wormhole::direction(sf::Vector2f position)
+{
+	sf::Vector2f f;
+	sf::Vector2f delta = _sprite.getPosition() - position;
+	float length = sqrt(delta.x * delta.x + delta.y * delta.y);
+
+	if(length > 0)
+	{
+		f.x = delta.x / length;
+		f.y = delta.y / length;
+	}
+
+	return f;
+}
+
 void Wormhole::draw(sf::RenderTarget& target, sf::RenderStates states) const
 void Wormhole::draw(sf::RenderTarget& target, sf::RenderStates states) const
 {
 {
 	target.draw(_sprite);
 	target.draw(_sprite);

+ 19 - 0
src/Wormhole.hpp

@@ -1,3 +1,20 @@
+/**
+ *  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/>.
+ */
+
 #pragma once
 #pragma once
 
 
 #include <SFML/Graphics.hpp>
 #include <SFML/Graphics.hpp>
@@ -22,6 +39,8 @@ class Wormhole: public sf::Drawable
 		void setPosition(float x, float y);
 		void setPosition(float x, float y);
 		sf::Vector2f getPosition();
 		sf::Vector2f getPosition();
 		std::shared_ptr<ltbl::LightPointEmission>& light();
 		std::shared_ptr<ltbl::LightPointEmission>& light();
+		float gravity(sf::Vector2f position);
+		sf::Vector2f direction(sf::Vector2f position);
 
 
 	private:
 	private:
 		virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const;
 		virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const;