-
Notifications
You must be signed in to change notification settings - Fork 0
/
PlayerPaddle2.cpp
106 lines (91 loc) · 1.8 KB
/
PlayerPaddle2.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#include "StdAfx.h"
#include "PlayerPaddle2.h"
#include "Game.h"
float veloRange2 = 200;
float scalePad2 = 1;
PlayerPaddle2::PlayerPaddle2() :
_velocity(0),
_maxVelocity(400.0f)
{
Load("images/paddle.png");
assert(IsLoaded());
GetSprite().setOrigin(GetSprite().getLocalBounds().width / 2, GetSprite().getLocalBounds().height / 2);
GetSprite().scale(scalePad2,1);
}
PlayerPaddle2::~PlayerPaddle2()
{
}
void PlayerPaddle2::Draw(sf::RenderWindow & rw)
{
VisibleGameObject::Draw(rw);
}
float PlayerPaddle2::GetVelocity() const
{
return _velocity;
}
void PlayerPaddle2::updPlyVelo(int modID) {
if (modID == 0) {
veloRange2 = 200.0f;
}
else if (modID == 1) {
veloRange2 = 400.0f;
}
else if (modID == 2) {
veloRange2 = 1000.0f;
}
_maxVelocity = veloRange2 * 2;
}
void PlayerPaddle2::sclPad2(int modID) {
if (modID == 0) {
scalePad2 = 2;
}
else if (modID == 1) {
scalePad2 = 1;
}
else if (modID == 2) {
scalePad2 = 0.5;
}
GetSprite().scale(scalePad2, 1);
}
void PlayerPaddle2::Update(float elapsedTime)
{
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Down))
{
_fast = 2;
}
else
{
_fast = 1;
}
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left) && !maxLeft)
{
_velocity = -veloRange2 * _fast;
}
else if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right) && !maxRight)
{
_velocity = veloRange2 * _fast;
}
else
{
_velocity = 0.0f;
}
if (_velocity > _maxVelocity)
_velocity = _maxVelocity;
if (_velocity < -_maxVelocity)
_velocity = -_maxVelocity;
sf::Vector2f pos = this->GetPosition();
if (pos.x < GetSprite().getLocalBounds().width / 2)
{
maxLeft = true;
}
else {
maxLeft = false;
}
if (pos.x >(Game::SCREEN_WIDTH - GetSprite().getLocalBounds().width / 2)) {
maxRight = true;
}
else {
maxRight = false;
}
GetSprite().move(_velocity * elapsedTime, 0);
}