Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "Ball.hpp"
- Ball::Ball(std::string texturePath, sf::Vector2f position, double scale, bool filled, int ballNumber, double rotation)
- {
- pTexture = new sf::Texture;
- pSprite = new sf::Sprite;
- pTexture->loadFromFile(texturePath);
- pSprite->setTexture(*pTexture);
- pSprite->setScale(scale, scale);
- pSprite->setPosition(position);
- pSprite->setOrigin(25, 25);
- pSprite->setRotation(rotation);
- alive = true;
- }
- Ball::~Ball()
- {
- delete pTexture;
- delete pSprite;
- pTexture = nullptr;
- pSprite = nullptr;
- }
- void Ball::update(float frametime)
- {
- collisionWall();
- getsInWhole();
- float ballSpeedX = 700;
- float ballSpeedY = 700;
- float ballDirectionX = (cos((pSprite->getRotation()) * 3.14/180) * ballSpeedX) * frametime;
- float ballDirectionY = (sin((pSprite->getRotation()) * 3.14/180) * ballSpeedY) * frametime;
- pSprite->move(ballDirectionX, ballDirectionY);
- }
- void Ball::handle()
- {
- }
- void Ball::render(sf::RenderWindow *rw)
- {
- rw->draw(*pSprite);
- }
- void Ball::collisionWall()
- {
- if (pSprite->getPosition().x > 1525)
- {
- }
- if (pSprite->getPosition().x < 75)
- {
- }
- if (pSprite->getPosition().y > 725)
- {
- }
- if (pSprite->getPosition().y < 75)
- {
- }
- }
- void Ball::getsInWhole()
- {
- //Whole bottom-middle
- if (pSprite->getPosition().x > 760 && pSprite->getPosition().x < 840 && pSprite->getPosition().y > 710)
- {
- alive = false;
- }
- }
Add Comment
Please, Sign In to add comment