Guest User

Ball.cpp

a guest
Mar 23rd, 2016
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.41 KB | None | 0 0
  1. #include "Ball.hpp"
  2.  
  3. Ball::Ball(std::string texturePath, sf::Vector2f position, double scale, bool filled, int ballNumber, double rotation)
  4. {
  5. pTexture = new sf::Texture;
  6. pSprite = new sf::Sprite;
  7.  
  8. pTexture->loadFromFile(texturePath);
  9. pSprite->setTexture(*pTexture);
  10.  
  11. pSprite->setScale(scale, scale);
  12. pSprite->setPosition(position);
  13. pSprite->setOrigin(25, 25);
  14. pSprite->setRotation(rotation);
  15.  
  16. alive = true;
  17. }
  18.  
  19. Ball::~Ball()
  20. {
  21. delete pTexture;
  22. delete pSprite;
  23.  
  24. pTexture = nullptr;
  25. pSprite = nullptr;
  26. }
  27.  
  28. void Ball::update(float frametime)
  29. {
  30. collisionWall();
  31. getsInWhole();
  32.  
  33. float ballSpeedX = 700;
  34. float ballSpeedY = 700;
  35.  
  36. float ballDirectionX = (cos((pSprite->getRotation()) * 3.14/180) * ballSpeedX) * frametime;
  37. float ballDirectionY = (sin((pSprite->getRotation()) * 3.14/180) * ballSpeedY) * frametime;
  38.  
  39. pSprite->move(ballDirectionX, ballDirectionY);
  40.  
  41. }
  42.  
  43. void Ball::handle()
  44. {
  45. }
  46.  
  47. void Ball::render(sf::RenderWindow *rw)
  48. {
  49. rw->draw(*pSprite);
  50. }
  51.  
  52. void Ball::collisionWall()
  53. {
  54. if (pSprite->getPosition().x > 1525)
  55. {
  56.  
  57. }
  58. if (pSprite->getPosition().x < 75)
  59. {
  60.  
  61. }
  62. if (pSprite->getPosition().y > 725)
  63. {
  64.  
  65. }
  66. if (pSprite->getPosition().y < 75)
  67. {
  68.  
  69. }
  70. }
  71. void Ball::getsInWhole()
  72. {
  73. //Whole bottom-middle
  74. if (pSprite->getPosition().x > 760 && pSprite->getPosition().x < 840 && pSprite->getPosition().y > 710)
  75. {
  76. alive = false;
  77. }
  78. }
Add Comment
Please, Sign In to add comment