|
@@ -24,47 +24,59 @@ Player::Player():
|
|
|
InputTarget(_inputMap),
|
|
|
Collidable(),
|
|
|
_movement(0.f),
|
|
|
- _movementSpeed(4.f),
|
|
|
+ _movementSpeed(2.f),
|
|
|
_movementMomentum(0.f),
|
|
|
_movementAcceleration(10.f),
|
|
|
- _movementSuppresion(5.f),
|
|
|
+ _movementSuppresion(10.f),
|
|
|
_rotation(0.f),
|
|
|
_rotationSpeed(0.6f),
|
|
|
_rotationMomentum(0.f),
|
|
|
_rotationAcceleration(38.f),
|
|
|
_rotationSuppresion(20.f),
|
|
|
_hit(false),
|
|
|
- _dead(false)
|
|
|
+ _dead(false),
|
|
|
+ _particleSystem(1920, 1080)
|
|
|
{
|
|
|
/**
|
|
|
- * Default binding
|
|
|
+ * Default binding
|
|
|
*/
|
|
|
- _inputMap.duoMap(1, Input(sf::Keyboard::Up), Input(sf::Keyboard::W));
|
|
|
- _inputMap.duoMap(2, Input(sf::Keyboard::Down), Input(sf::Keyboard::S));
|
|
|
- _inputMap.duoMap(3, Input(sf::Keyboard::Left), Input(sf::Keyboard::A));
|
|
|
- _inputMap.duoMap(4, Input(sf::Keyboard::Right), Input(sf::Keyboard::D));
|
|
|
- _inputMap.map(5, Input(sf::Keyboard::Space));
|
|
|
+ if(sf::Joystick::isConnected(0))
|
|
|
+ {
|
|
|
+ _inputMap.map(1, Input(sf::Joystick::Axis::Y, false));
|
|
|
+ _inputMap.map(2, Input(sf::Joystick::Axis::Y, true));
|
|
|
+ _inputMap.map(3, Input(sf::Joystick::Axis::Z, false));
|
|
|
+ _inputMap.map(4, Input(sf::Joystick::Axis::Z, true));
|
|
|
+ _inputMap.map(5, Input(7));
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ _inputMap.map(1, Input(sf::Keyboard::W));
|
|
|
+ _inputMap.map(2, Input(sf::Keyboard::S));
|
|
|
+ _inputMap.map(3, Input(sf::Keyboard::A));
|
|
|
+ _inputMap.map(4, Input(sf::Keyboard::D));
|
|
|
+ _inputMap.map(5, Input(sf::Keyboard::Space));
|
|
|
+ }
|
|
|
|
|
|
/**
|
|
|
- * Input lambdas
|
|
|
+ * Input lambdas
|
|
|
*/
|
|
|
- duoBind(1, [this](const sf::Event&)
|
|
|
+ bind(1, [this](const sf::Event&, float power)
|
|
|
{
|
|
|
- _movement += 1.f;
|
|
|
- });
|
|
|
- duoBind(2, [this](const sf::Event&)
|
|
|
+ _movement += power;
|
|
|
+ });
|
|
|
+ bind(2, [this](const sf::Event&, float power)
|
|
|
{
|
|
|
- _movement -= 0.8f;
|
|
|
+ _movement -= power * 0.8f;
|
|
|
});
|
|
|
- duoBind(3, [this](const sf::Event&)
|
|
|
+ bind(3, [this](const sf::Event&, float power)
|
|
|
{
|
|
|
- _rotation -= 1.f;
|
|
|
+ _rotation -= power;
|
|
|
});
|
|
|
- duoBind(4, [this](const sf::Event&)
|
|
|
+ bind(4, [this](const sf::Event&, float power)
|
|
|
{
|
|
|
- _rotation += 1.f;
|
|
|
+ _rotation += power;
|
|
|
});
|
|
|
- bind(5, [this](const sf::Event&)
|
|
|
+ bind(5, [this](const sf::Event&, float)
|
|
|
{
|
|
|
if(_bulletTimer.getElapsedTime().asMilliseconds() > 1500)
|
|
|
{
|
|
@@ -81,14 +93,20 @@ Player::Player():
|
|
|
});
|
|
|
|
|
|
/**
|
|
|
- * Technical
|
|
|
+ * Particles
|
|
|
+ */
|
|
|
+
|
|
|
+ _particleSystem.setDissolutionRate(255.f);
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Technical
|
|
|
*/
|
|
|
|
|
|
genCollisionBox("data/hitbox/Player.png", sf::Vector2f(71.f, 100.f));
|
|
|
|
|
|
_bullets.reserve(10);
|
|
|
_bulletTimer.restart();
|
|
|
-
|
|
|
+
|
|
|
_durability = 0.99f;
|
|
|
}
|
|
|
|
|
@@ -175,7 +193,7 @@ bool Player::checkCollision(Foreground& foreground)
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
-void Player::update(sf::Time delta)
|
|
|
+void Player::keyboardControls(sf::Time delta)
|
|
|
{
|
|
|
float seconds = delta.asSeconds();
|
|
|
const double degree = 3.14159265358 / 180.;
|
|
@@ -191,18 +209,24 @@ void Player::update(sf::Time delta)
|
|
|
|
|
|
_movementMomentum += _movementAcceleration * seconds * _movement;
|
|
|
|
|
|
- if(_movementMomentum > _movementSuppresion * seconds)
|
|
|
- _movementMomentum -= _movementSuppresion * seconds;
|
|
|
- else if(_movementMomentum < -_movementSuppresion * seconds)
|
|
|
- _movementMomentum += _movementSuppresion * seconds;
|
|
|
- else
|
|
|
- _movementMomentum = 0.f;
|
|
|
+ if(_movement == 0.f)
|
|
|
+ {
|
|
|
+ if(_movementMomentum > _movementSuppresion * seconds)
|
|
|
+ _movementMomentum -= _movementSuppresion * seconds;
|
|
|
+ else if(_movementMomentum < -_movementSuppresion * seconds)
|
|
|
+ _movementMomentum += _movementSuppresion * seconds;
|
|
|
+ else
|
|
|
+ _movementMomentum = 0.f;
|
|
|
+ }
|
|
|
|
|
|
sf::Vector2f movement;
|
|
|
movement.x = std::sin(getRotation() * degree) * 60.f * _movementSpeed * _movementMomentum * seconds;
|
|
|
movement.y = -std::cos(getRotation() * degree) * 60.f * _movementSpeed * _movementMomentum * seconds;
|
|
|
+
|
|
|
move(movement);
|
|
|
- //px.move(movement);
|
|
|
+
|
|
|
+ _particleSystem.fuel(movement.x * 20.f, getRotation());
|
|
|
+ _particleSystem.fuel(movement.y * 20.f, getRotation());
|
|
|
|
|
|
_movement = 0.f;
|
|
|
|
|
@@ -217,9 +241,108 @@ void Player::update(sf::Time delta)
|
|
|
|
|
|
float rotation = 90.f * _rotationSpeed * _rotationMomentum * seconds;
|
|
|
rotate(rotation);
|
|
|
- //px.rotate(rotation);
|
|
|
|
|
|
_rotation = 0.f;
|
|
|
+}
|
|
|
+
|
|
|
+void Player::padControls(sf::Time delta)
|
|
|
+{
|
|
|
+ float seconds = delta.asSeconds();
|
|
|
+ const double degree = 3.14159265358 / 180.;
|
|
|
+
|
|
|
+ sf::Vector2f v = sf::Vector2f(
|
|
|
+ sf::Joystick::getAxisPosition(0, sf::Joystick::Axis::X) / 100.f,
|
|
|
+ sf::Joystick::getAxisPosition(0, sf::Joystick::Axis::Y) / 100.f);
|
|
|
+
|
|
|
+ float curr = getRotation();
|
|
|
+ static float supposed;
|
|
|
+ if(v.x != 0 or v.y != 0)
|
|
|
+ supposed = atan2(v.x, -v.y) / degree;
|
|
|
+
|
|
|
+ if(supposed < 0.f)
|
|
|
+ supposed += 360.f;
|
|
|
+
|
|
|
+ float c = supposed - curr;
|
|
|
+ if(curr > 180.f && supposed < 180.f)
|
|
|
+ {
|
|
|
+ float a = (supposed - curr);
|
|
|
+ float b = (supposed - curr + 360.f);
|
|
|
+ if(std::fabs(a) < std::fabs(b))
|
|
|
+ c = a;
|
|
|
+ else
|
|
|
+ c = b;
|
|
|
+ }
|
|
|
+ if(curr < 180.f && supposed > 180.f)
|
|
|
+ {
|
|
|
+ float a = (supposed - curr);
|
|
|
+ float b = (supposed - curr - 360.f);
|
|
|
+ if(std::fabs(a) < std::fabs(b))
|
|
|
+ c = a;
|
|
|
+ else
|
|
|
+ c = b;
|
|
|
+ }
|
|
|
+
|
|
|
+ if(v.x != 0 or v.y != 0)
|
|
|
+ {
|
|
|
+ if(c > 0.f)
|
|
|
+ _rotationMomentum += _rotationAcceleration * seconds;
|
|
|
+ else if(c < 0.f)
|
|
|
+ _rotationMomentum -= _rotationAcceleration * seconds;
|
|
|
+ }
|
|
|
+
|
|
|
+ if(_rotationMomentum > _rotationSuppresion * seconds)
|
|
|
+ _rotationMomentum -= _rotationSuppresion * seconds;
|
|
|
+ else if(_rotationMomentum < -_rotationSuppresion * seconds)
|
|
|
+ _rotationMomentum += _rotationSuppresion * seconds;
|
|
|
+ else
|
|
|
+ _rotationMomentum = 0.f;
|
|
|
+
|
|
|
+ float rotation = 90.f * _rotationSpeed * _rotationMomentum * seconds;
|
|
|
+
|
|
|
+ rotate(rotation);
|
|
|
+
|
|
|
+ if((v.x != 0 || v.y != 0) && c < 1.f)
|
|
|
+ _movement = std::fabs(v.x + v.y);
|
|
|
+
|
|
|
+ if(_hit)
|
|
|
+ {
|
|
|
+ if(_movement > 0 || _movementMomentum > 0)
|
|
|
+ _movementMomentum -= seconds * 15.f;
|
|
|
+ if(_movement < 0 || _movementMomentum < 0)
|
|
|
+ _movementMomentum += seconds * 15.f;
|
|
|
+ _movement *= 0.6f;
|
|
|
+ }
|
|
|
+
|
|
|
+ _movementMomentum += _movementAcceleration * seconds * _movement;
|
|
|
+
|
|
|
+ if(_movement == 0.f)
|
|
|
+ {
|
|
|
+ if(_movementMomentum > _movementSuppresion * seconds)
|
|
|
+ _movementMomentum -= _movementSuppresion * seconds;
|
|
|
+ else if(_movementMomentum < -_movementSuppresion * seconds)
|
|
|
+ _movementMomentum += _movementSuppresion * seconds;
|
|
|
+ else
|
|
|
+ _movementMomentum = 0.f;
|
|
|
+ }
|
|
|
+
|
|
|
+ sf::Vector2f movement;
|
|
|
+ movement.x = std::sin(getRotation() * degree) * 60.f * _movementSpeed * _movementMomentum * seconds;
|
|
|
+ movement.y = -std::cos(getRotation() * degree) * 60.f * _movementSpeed * _movementMomentum * seconds;
|
|
|
+
|
|
|
+ move(movement);
|
|
|
+
|
|
|
+ _particleSystem.fuel(movement.x * 20.f, getRotation());
|
|
|
+ _particleSystem.fuel(movement.y * 20.f, getRotation());
|
|
|
+
|
|
|
+ _movement = 0.f;
|
|
|
+}
|
|
|
+
|
|
|
+void Player::update(sf::Time delta)
|
|
|
+{
|
|
|
+ //if(sf::Joystick::isConnected(0))
|
|
|
+ //padControls(delta);
|
|
|
+ //else
|
|
|
+ keyboardControls(delta);
|
|
|
|
|
|
for(unsigned i = 0; i < _bullets.size(); ++i)
|
|
|
{
|
|
@@ -227,10 +350,18 @@ void Player::update(sf::Time delta)
|
|
|
if(_bullets[i].isDead())
|
|
|
_bullets.erase(_bullets.begin() + i);
|
|
|
}
|
|
|
+
|
|
|
+ _particleSystem.setPosition(getPosition());
|
|
|
+
|
|
|
+ _particleSystem.clear();
|
|
|
+ _particleSystem.update(delta);
|
|
|
+ _particleSystem.render();
|
|
|
}
|
|
|
|
|
|
void Player::draw(sf::RenderTarget& target, sf::RenderStates states) const
|
|
|
-{
|
|
|
+{
|
|
|
+ target.draw(_particleSystem.getSprite());
|
|
|
+
|
|
|
for(unsigned i = 0; i < _bullets.size(); ++i)
|
|
|
target.draw(_bullets[i]);
|
|
|
|