Browse Source

Monday update

POSITIVE-MENTAL-ATTITUDE 8 years ago
parent
commit
0905201b6a

+ 89 - 0
Circle.cpp

@@ -0,0 +1,89 @@
+#include "Circle.hpp"
+
+Circle::Circle(sf::Color color, float scale): _size(10) 
+{
+	_arc.resize(100);
+	for(unsigned i = 0; i < 100; ++i)
+	{
+		_arc[i].setColor(color);
+		_arc[i].setRotation(3.6f * i);
+		_arc[i].setScale(scale, scale);
+	}
+}
+
+Circle::~Circle()
+{
+	_arc.clear();
+}
+
+void Circle::setTexture(sf::Texture& texture)
+{
+	for(unsigned i = 0; i < 100; ++i)
+	{
+		_arc[i].setOrigin(texture.getSize().x / 2.f, 205.f);
+		_arc[i].setTexture(texture);
+	}
+}
+
+void Circle::setPosition(sf::Vector2f position)
+{
+	for(unsigned i = 0; i < 100; ++i)
+		_arc[i].setPosition(position);
+}
+
+void Circle::setPosition(float x, float y)
+{
+	setPosition(sf::Vector2f(x, y));
+}
+
+void Circle::setRotation(float rotation)
+{
+	for(unsigned i = 0; i < 100; ++i)
+		_arc[i].setRotation(3.6f * i + rotation);
+}
+
+void Circle::rotate(float rotation)
+{
+	for(unsigned i = 0; i < 100; ++i)
+		_arc[i].rotate(rotation);
+}
+
+void Circle::setSize(unsigned size)
+{
+	if(size <= 100)
+		_size = size;
+}
+
+void Circle::show()
+{
+	_elapsedTime = sf::Time::Zero;
+}
+
+void Circle::update(sf::Time delta)
+{
+	_elapsedTime += delta;
+	float seconds = _elapsedTime.asSeconds();
+	if(seconds >= 2.75f && seconds < 3.f)
+	{
+		sf::Color color = _arc[0].getColor();
+		color.a = int((3.f - _elapsedTime.asSeconds()) * 255 * 4);
+		for(unsigned i = 0; i < _size; ++i)
+			_arc[i].setColor(color);
+	}
+	else if(seconds >= 3.f)
+	{
+		sf::Color color = _arc[0].getColor();
+		color.a = 255;
+		for(unsigned i = 0; i < _size; ++i)
+			_arc[i].setColor(color);
+	}
+}
+
+void Circle::draw(sf::RenderTarget& target, sf::RenderStates states) const
+{
+	if(_elapsedTime.asSeconds() >= 3.f)
+		return;
+
+	for(unsigned i = 0; i < _size; ++i)
+		target.draw(_arc[i]); 
+}

+ 26 - 0
Circle.hpp

@@ -0,0 +1,26 @@
+#pragma once
+
+#include <SFML/Graphics.hpp>
+
+class Circle: public sf::Drawable
+{
+	public:
+		Circle() = delete;
+		Circle(sf::Color color, float scale);
+		virtual ~Circle();
+		void setTexture(sf::Texture& texture);
+		void setPosition(sf::Vector2f position);
+		void setPosition(float x, float y);
+		void setRotation(float rotation);
+		void rotate(float rotation);
+		void setSize(unsigned size);
+		void update(sf::Time delta);
+		void show();
+		
+	private:
+		virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const;
+		std::vector<sf::Sprite> _arc;
+		unsigned _size;
+		sf::Time _elapsedTime;
+};
+

+ 0 - 1
Context.cpp

@@ -1 +0,0 @@
-#include "Context.hpp"

+ 1 - 1
IngameState.hpp

@@ -21,7 +21,7 @@
 #include "Player.hpp"
 #include "Foreground.hpp"
 #include "Camera.hpp"
-#include <ltbl/lighting/LightSystem.h>
+#include "ltbl/lighting/LightSystem.h"
 
 class IngameState: public State
 {

+ 32 - 6
Player.cpp

@@ -35,7 +35,10 @@ Player::Player():
 	_rotationSuppresion(20.f),
 	_hit(false),
 	_dead(false),
-	_particleSystem(512, 512)
+	_particleSystem(512, 512),
+	_ammo(4),
+	_life(sf::Color::Red, 1.f),
+	_mana(sf::Color::Blue, 0.942f)
 {
 	/**
 	 *  Default binding
@@ -79,10 +82,11 @@ Player::Player():
 	});
 	bind(5, [this](const sf::Event&, float)
 	{
-		if(_bulletTimer.getElapsedTime().asMilliseconds() > 750)
+		if(_bulletTimer.getElapsedTime().asMilliseconds() > 750 and _ammo > 0)
 		{
 			// Does not check if _context != nullptr
 			// so please do remember to call setContext().
+			--_ammo;
 			_bullets.emplace_back(getRotation(), getPosition(), 
 								_context->assets->loadSound("data/audio/Shotgun.ogg"), 
 								_context->assets->loadSound("data/audio/Bomb.ogg"),
@@ -90,6 +94,8 @@ Player::Player():
 			_bullets.back().setTexture(_innerTexture);
 			_bulletTimer.restart();
 			_movementMomentum -= (rand() % 2000 + 6000) / 1000.f;
+			_life.show();
+			_mana.show();
 		}
 	});
 	
@@ -115,7 +121,7 @@ Player::Player():
 	_bullets.reserve(10);
 	_bulletTimer.restart();
 	 
-	_durability = 0.99f; 
+	_durability = 0.25f; 
 }
 
 void Player::setContext(Context* context)
@@ -123,6 +129,9 @@ void Player::setContext(Context* context)
 	_context = context;
 	_glass.setBuffer(_context->assets->loadSound("data/audio/GlassHit.ogg"));
 	_deathSound.setBuffer(_context->assets->loadSound("data/audio/GlassRekt.ogg"));
+	_context->assets->loadTexture("data/triangle/Arc.png").setSmooth(true);
+	_life.setTexture(_context->assets->loadTexture("data/triangle/Arc.png"));
+	_mana.setTexture(_context->assets->loadTexture("data/triangle/Arc.png"));
 }
 
 bool Player::isDead()
@@ -192,6 +201,9 @@ bool Player::checkCollision(Foreground& foreground)
 	
 	_innerTexture.loadFromImage(_image);
 	_hit = true;
+	_life.show();
+	_mana.show();
+
 	if(_pointCount * _durability < _cbanned.size())
 	{
 		_dead = true;
@@ -352,11 +364,13 @@ void Player::update(sf::Time delta)
 		//padControls(delta);
 	//else
 		keyboardControls(delta);
+		
+	sf::Vector2f position = getPosition();
 	
 	bool all = false;
 	for(unsigned i = 0; i < _bullets.size(); ++i)
 	{
-		_bullets[i].update(delta, getPosition());
+		_bullets[i].update(delta, position);
 
 		if(!_bullets[i].isDead())
 			all = true;
@@ -364,9 +378,18 @@ void Player::update(sf::Time delta)
 	if(!all)
 		_bullets.clear();
 
-	_particleSystem.setPosition(getPosition());
+	_particleSystem.setPosition(position);
+	
+	sf::Listener::setPosition(position.x, position.y, 0);
 	
-	sf::Listener::setPosition(getPosition().x, getPosition().y, 0);
+	_life.setPosition(position);
+	_mana.setPosition(position);
+	
+	_life.setSize(unsigned(((_pointCount * _durability - _cbanned.size()) / (_pointCount *  _durability)) * 100.f));
+	_mana.setSize(_ammo * 10);
+	
+	_life.update(delta);
+	_mana.update(delta);
 
 	_particleSystem.clear();
 	_particleSystem.update(delta);
@@ -387,4 +410,7 @@ void Player::draw(sf::RenderTarget& target, sf::RenderStates states) const
 		states.texture = (_texture);
     
 	target.draw(_vertices, states);
+	
+	target.draw(_life);
+	target.draw(_mana);
 }

+ 4 - 0
Player.hpp

@@ -25,6 +25,7 @@
 #include "Collidable.hpp"
 #include "Context.hpp"
 #include "Particle.hpp"
+#include "Circle.hpp"
 
 /**
  * @class Player
@@ -70,4 +71,7 @@ class Player: public Triangle, public InputTarget<int>, public Collidable
 		sf::Sound _glass;
 		sf::Sound _deathSound;
 		ParticleSystem _particleSystem;
+		int _ammo;
+		Circle _life;
+		Circle _mana;
 };

+ 6 - 0
Triangles.cpp

@@ -211,8 +211,12 @@ void Triangles::refresh()
 
 void Triangles::load(int stateType)
 {
+	Echo::debug("Deleting current state.");
+
 	if(_current)
 		delete _current;
+		
+	Echo::debug("Loading state ID: ", stateType);
 	
 	switch(stateType)
 	{
@@ -243,6 +247,8 @@ void Triangles::load(int stateType)
 	_window.lockFramerate(false);
 	
 	_current->refresh();
+	
+	Echo::debug("Done.");
 }
 
 int Triangles::run(unsigned count)

BIN
data/light/star.png


BIN
data/light/star.xcf


BIN
data/triangle/Arc.png


+ 3 - 3
ltbl/lighting/LightDirectionEmission.cpp

@@ -1,6 +1,6 @@
-#include "ltbl/lighting/LightDirectionEmission.h"
-#include "ltbl/lighting/LightShape.h"
-#include "ltbl/lighting/LightSystem.h"
+#include "LightDirectionEmission.h"
+#include "LightShape.h"
+#include "LightSystem.h"
 #include <cassert>
 
 using namespace ltbl;

+ 2 - 2
ltbl/lighting/LightDirectionEmission.h

@@ -1,7 +1,7 @@
 #pragma once
 
 #include <SFML/Graphics.hpp>
-#include <ltbl/quadtree/QuadtreeOccupant.h>
+#include "../quadtree/QuadtreeOccupant.h"
 
 namespace ltbl {
 	class LightDirectionEmission {
@@ -19,4 +19,4 @@ namespace ltbl {
 
 		void render(const sf::View &view, sf::RenderTexture &lightTempTexture, sf::RenderTexture &antumbraTempTexture, const std::vector<QuadtreeOccupant*> &shapes, sf::Shader &unshadowShader, float shadowExtension);
 	};
-}
+}

+ 3 - 3
ltbl/lighting/LightPointEmission.cpp

@@ -1,6 +1,6 @@
-#include "ltbl/lighting/LightPointEmission.h"
-#include "ltbl/lighting/LightShape.h"
-#include "ltbl/lighting/LightSystem.h"
+#include "LightPointEmission.h"
+#include "LightShape.h"
+#include "LightSystem.h"
 #include <iostream>
 #include <cassert>
 #include <cmath>

+ 1 - 1
ltbl/lighting/LightPointEmission.h

@@ -1,6 +1,6 @@
 #pragma once
 
-#include <ltbl/quadtree/QuadtreeOccupant.h>
+#include "../quadtree/QuadtreeOccupant.h"
 
 namespace ltbl {
     class LightPointEmission : public QuadtreeOccupant {

+ 2 - 2
ltbl/lighting/LightShape.h

@@ -1,6 +1,6 @@
 #pragma once
 
-#include <ltbl/quadtree/QuadtreeOccupant.h>
+#include "../quadtree/QuadtreeOccupant.h"
 
 namespace ltbl {
 	class LightShape : public QuadtreeOccupant {
@@ -17,4 +17,4 @@ namespace ltbl {
 			return _shape.getGlobalBounds();
 		}
 	};
-}
+}

+ 1 - 1
ltbl/lighting/LightSystem.cpp

@@ -1,4 +1,4 @@
-#include "ltbl/lighting/LightSystem.h"
+#include "LightSystem.h"
 #include <cassert>
 #include <iostream>
 #include <cmath>

+ 6 - 7
ltbl/lighting/LightSystem.h

@@ -1,12 +1,11 @@
 #pragma once
 
-#include <ltbl/quadtree/DynamicQuadtree.h>
-#include <ltbl/lighting/LightPointEmission.h>
-#include <ltbl/lighting/LightDirectionEmission.h>
-#include <ltbl/lighting/LightShape.h>
-#include <ltbl/lighting/NormalsSprite.h>
-
-#include <ltbl/tools/pool.h>
+#include "../quadtree/DynamicQuadtree.h"
+#include "LightPointEmission.h"
+#include "LightDirectionEmission.h"
+#include "LightShape.h"
+#include "NormalsSprite.h"
+#include "../tools/pool.h"
 
 #include <unordered_set>
 

+ 1 - 1
ltbl/lighting/NormalsSprite.h

@@ -1,6 +1,6 @@
 #pragma once
 
-#include <ltbl/quadtree/QuadtreeOccupant.h>
+#include "../quadtree/QuadtreeOccupant.h"
 
 namespace ltbl
 {

+ 1 - 1
ltbl/quadtree/DynamicQuadtree.cpp

@@ -1,4 +1,4 @@
-#include "ltbl/quadtree/DynamicQuadtree.h"
+#include "DynamicQuadtree.h"
 #include <cassert>
 
 using namespace ltbl;

+ 1 - 1
ltbl/quadtree/DynamicQuadtree.h

@@ -1,6 +1,6 @@
 #pragma once
 
-#include <ltbl/quadtree/Quadtree.h>
+#include "Quadtree.h"
 
 namespace ltbl {
     class DynamicQuadtree : public Quadtree {

+ 1 - 1
ltbl/quadtree/Quadtree.cpp

@@ -1,4 +1,4 @@
-#include "ltbl/quadtree/Quadtree.h"
+#include "Quadtree.h"
 #include <algorithm>
 #include <assert.h>
 

+ 1 - 1
ltbl/quadtree/Quadtree.h

@@ -1,6 +1,6 @@
 #pragma once
 
-#include <ltbl/quadtree/QuadtreeNode.h>
+#include "QuadtreeNode.h"
 
 #include <memory>
 

+ 2 - 2
ltbl/quadtree/QuadtreeNode.cpp

@@ -1,5 +1,5 @@
-#include "ltbl/quadtree/QuadtreeNode.h"
-#include "ltbl/quadtree/Quadtree.h"
+#include "QuadtreeNode.h"
+#include "Quadtree.h"
 #include <cassert>
 
 using namespace ltbl;

+ 1 - 1
ltbl/quadtree/QuadtreeNode.h

@@ -1,6 +1,6 @@
 #pragma once
 
-#include <ltbl/quadtree/QuadtreeOccupant.h>
+#include "QuadtreeOccupant.h"
 
 #include <memory>
 #include <array>

+ 3 - 3
ltbl/quadtree/QuadtreeOccupant.cpp

@@ -1,6 +1,6 @@
-#include "ltbl/quadtree/QuadtreeOccupant.h"
-#include "ltbl/quadtree/QuadtreeNode.h"
-#include "ltbl/quadtree/Quadtree.h"
+#include "QuadtreeOccupant.h"
+#include "QuadtreeNode.h"
+#include "Quadtree.h"
 #include <cassert>
 
 using namespace ltbl;

+ 1 - 1
ltbl/quadtree/QuadtreeOccupant.h

@@ -3,7 +3,7 @@
 #include <SFML/System.hpp>
 #include <SFML/Graphics.hpp>
 
-#include <ltbl/tools/Math.h>
+#include "../tools/Math.h"
 
 #include <memory>
 #include <array>

+ 1 - 1
ltbl/quadtree/StaticQuadtree.cpp

@@ -1,4 +1,4 @@
-#include "ltbl/quadtree/StaticQuadtree.h"
+#include "StaticQuadtree.h"
 #include <cassert>
 
 using namespace ltbl;

+ 1 - 1
ltbl/quadtree/StaticQuadtree.h

@@ -1,6 +1,6 @@
 #pragma once
 
-#include <ltbl/quadtree/Quadtree.h>
+#include "ltbl/quadtree/Quadtree.h"
 
 namespace ltbl
 {

+ 1 - 1
ltbl/tools/Math.cpp

@@ -1,4 +1,4 @@
-#include "ltbl/tools/Math.h"
+#include "Math.h"
 #include <list>
 #include <assert.h>
 #include <cmath>