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