Created
January 24, 2013 21:38
-
-
Save hovatterz/4628036 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
// Move a rotated sprite forward/backward | |
double radians = (M_PI / 180) * _player.getRotation(); | |
float dx = std::cos(radians) * _player.getSpeed() * deltaTime; | |
float dy = std::sin(radians) * _player.getSpeed() * deltaTime; | |
Vector2f position = _player.getPosition(); | |
if (direction == DIRECTION_FORWARD) { | |
position.x += dx; | |
position.y += dy; | |
} else if (direction == DIRECTION_BACKWARD) { | |
position.x -= dx; | |
position.y -= dy; | |
} | |
_player.setPosition(position); | |
// Face a sprite towards a point | |
Vector2f direction = point - _player.getPosition(); | |
_player.setRotation(std::atan2(direction.y, direction.x) * (180 / M_PI)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment