Last active
December 14, 2015 09:29
-
-
Save Groogy/5065150 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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