-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPaddle.cpp
More file actions
39 lines (31 loc) · 770 Bytes
/
Paddle.cpp
File metadata and controls
39 lines (31 loc) · 770 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
#include "Paddle.h"
#include "Constants.h"
const float Paddle::SPEED = 400.f;
const sf::Vector2f Paddle::SIZE = sf::Vector2f(5.f, 60.f);
Paddle::Paddle(sf::Vector2f position)
{
setPosition(position);
velocity = 0.f;
}
void Paddle::moveUp(const float DT)
{
velocity = -SPEED * DT;
if (getPosition().y >= 0.f)
move(sf::Vector2f(0, velocity));
}
void Paddle::moveDown(const float DT)
{
velocity = SPEED * DT;
if (getPosition().y <= WINDOW_HEIGHT - SIZE.y)
move(sf::Vector2f(0, velocity));
}
void Paddle::reset(sf::Vector2f position)
{
setPosition(position);
}
void Paddle::draw(sf::RenderTarget& target, sf::RenderStates states) const
{
sf::RectangleShape paddle(sf::Vector2f(SIZE.x, SIZE.y));
paddle.setPosition(getPosition());
target.draw(paddle);
}