-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPaddle.cpp
47 lines (35 loc) · 913 Bytes
/
Paddle.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
#include "StdAfx.h"
#include "Paddle.h"
Paddle::Paddle(void) : m_Speed(0.0f)
{
}
Paddle::~Paddle(void)
{
}
void Paddle::initialize()
{
m_Sprite.setPosition((SCREENWIDTH / 2) - (m_Sprite.getLocalBounds().width / 2), PADDLEYPOS);
m_Speed = 0.0f;
}
void Paddle::resetLives()
{
m_Lives = 5;
}
void Paddle::loseLife()
{
m_Lives -= 1;
/*if ( m_Lives < 0 )
m_Lives = 0;*/
}
int Paddle::livesLeft()
{
return m_Lives;
}
void Paddle::update(float deltaTime)
{
m_Sprite.move(m_Speed * deltaTime, 0.0f);
if (m_Sprite.getPosition().x < 0.0f) // If the sprite goes past the bounds of the window
m_Sprite.setPosition(sf::Vector2f(0.0f, PADDLEYPOS)); // the position is reset to keep it inside the window
else if (m_Sprite.getPosition().x + m_Sprite.getLocalBounds().width > (float)SCREENWIDTH)
m_Sprite.setPosition(sf::Vector2f((float)SCREENWIDTH - m_Sprite.getLocalBounds().width , PADDLEYPOS));
}