Advertisement
Guest User

Untitled

a guest
May 28th, 2015
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. void Player::EnemyMoved(sf::RenderWindow &window){
  2. this->enemyPosition = enemyImage.getPosition();
  3. //this->mouse = window.mapPixelToCoords(sf::Mouse::getPosition(window));
  4.  
  5. const float PI = 3.14159265;
  6.  
  7. float d = enemyPosition.x - playerPosition.x + 50;
  8. float e = enemyPosition.y - playerPosition.y + 50;
  9.  
  10. enemyAngle = (atan2(e, d)) * 180 / PI;
  11.  
  12. enemyImage.setRotation(enemyAngle + 270);
  13.  
  14. if (abs(sqrt(((playerPosition.x - enemyPosition.x + 200) * (playerPosition.x - enemyPosition.x + 200)) + ((playerPosition.y - enemyPosition.y + 200) * (playerPosition.y - enemyPosition.y + 200))))){
  15. enemyImage.move(std::cos(3.14159265 * enemyAngle / 180.f) * 1.0f *-1, std::sin(3.14159265 * enemyAngle / 180.f) * 1.0f *-1);
  16. }
  17. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement