-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathball.cpp
More file actions
35 lines (26 loc) · 1.04 KB
/
Copy pathball.cpp
File metadata and controls
35 lines (26 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include "ball.h"
Ball::Ball(float startX, float startY) {
this->m_position.x = startX;
this->m_position.y = startY;
this->m_shape.setSize(sf::Vector2f(10, 10));
this->m_shape.setPosition(this->m_position);
}
sf::FloatRect Ball::getGlobalBounds() {
return this->m_shape.getGlobalBounds();
}
sf::RectangleShape Ball::getShape() { return this->m_shape; }
sf::Vector2f Ball::getPosition() { return this->m_shape.getPosition(); }
sf::Vector2f Ball::getSize() { return this->m_shape.getSize(); }
float Ball::getXVelocity() { return this->m_directionX; }
void Ball::reboundSides() { this->m_directionX = -this->m_directionX; }
void Ball::reboundBatOrTop() { this->m_directionY = -this->m_directionY; }
void Ball::reboundBottom() {
this->m_position.y = 0;
this->m_position.x = 500;
this->m_directionY = -this->m_directionY;
}
void Ball::update(sf::Time dt) {
this->m_position.y += this->m_directionY * m_speed * dt.asSeconds();
this->m_position.x += this->m_directionX * m_speed * dt.asSeconds();
this->m_shape.setPosition(m_position);
}