Skip to content

Instantly share code, notes, and snippets.

@Groogy
Last active December 14, 2015 09:29
Show Gist options
  • Save Groogy/5065150 to your computer and use it in GitHub Desktop.
Save Groogy/5065150 to your computer and use it in GitHub Desktop.
void Player::fire(const sf::Vector2f& direction)
{
if(myFireCooldown <= sf::Time::Zero)
{
float angle = std::atan2(direction.y, direction.x);
sf::Vector2f centerPosition = getCenterPosition();
myFireCooldown = Player::FireCooldown;
myMuzzleTimer = Player::MuzzleTime;
myProjectiles->createProjectile(centerPosition + direction * Size / 2.f, rad2Degrees(angle), sf::Color::White);
myMuzzleFlash->setPosition(centerPosition + direction * Size / 2.f);
myMuzzleFlash->setEnabledFlag(true);
}
}
void Player::updateLights(sf::Time elapsedTime, const sf::Vector2f& mousePosition)
{
if(myMuzzleTimer <= sf::Time::Zero)
myMuzzleFlash->setEnabledFlag(false);
else
myMuzzleTimer -= elapsedTime;
sf::Vector2f centerPosition = getCenterPosition();
sf::Vector2f toMouseVector = normalize(mousePosition - centerPosition);
float toMouseAngle = rad2Degrees(std::atan2(toMouseVector.y, toMouseVector.x));
myFlashLight->setPosition(centerPosition + toMouseVector * Size / 2.f);
myFlashLight->setRotation(toMouseAngle);
myLightOccluder->setPosition(centerPosition);
}
Vector2f directionToTarget = Normalize(targetPosition - myPosition);
Vector2f direction = Normalize(myVelocity + directionToTarget * elapsedTime)
myVelocity = direction * myVelocity.length();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment