-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBall.cpp
54 lines (43 loc) · 860 Bytes
/
Ball.cpp
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include "Ball.h"
// This the constructor function
Ball::Ball(float startX, float startY)
{
m_Position.x = startX;
m_Position.y = startY;
m_Shape.setSize(sf::Vector2f(10, 10));
m_Shape.setPosition(m_Position);
}
FloatRect Ball::getPosition()
{
return m_Shape.getGlobalBounds();
}
RectangleShape Ball::getShape()
{
return m_Shape;
}
float Ball::getXVelocity()
{
return m_DirectionX;
}
void Ball::reboundSides()
{
m_DirectionX = -m_DirectionX;
}
void Ball::reboundBatOrTop()
{
m_DirectionY = -m_DirectionY;
}
void Ball::reboundBottom()
{
m_Position.y = 0;
m_Position.x = 500;
m_DirectionY = -m_DirectionY;
}
void Ball::update(Time dt)
{
// Update the ball's position
m_Position.y += m_DirectionY * m_Speed * dt.asSeconds();
m_Position.x += m_DirectionX * m_Speed * dt.asSeconds();
// Move the ball
m_Shape.setPosition(m_Position);
}