-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBall.cpp
More file actions
47 lines (38 loc) · 756 Bytes
/
Copy pathBall.cpp
File metadata and controls
47 lines (38 loc) · 756 Bytes
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
#include "Ball.h"
Ball::Ball(float startX, float startY) : m_Position(startX, 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::reboundTopOrBottom()
{
m_DirectionY = -m_DirectionY;
}
void Ball::reboundBat()
{
m_DirectionX = -m_DirectionX;
}
void Ball::reboundSide()
{
m_Position.y = 540;
m_Position.x = 960;
m_DirectionX = -m_DirectionX;
}
void Ball::update(Time dt)
{
m_Position.y += m_DirectionY * m_Speed * dt.asSeconds();
m_Position.x += m_DirectionX * m_Speed * dt.asSeconds();
m_Shape.setPosition(m_Position);
}