-
Notifications
You must be signed in to change notification settings - Fork 0
/
PlayerPaddle.cpp
106 lines (91 loc) · 1.76 KB
/
PlayerPaddle.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 "PlayerPaddle.h"
#include "Game.h"
float veloRange1 = 200;
float scalePad1 = 1;
PlayerPaddle::PlayerPaddle() :
_velocity(0),
_maxVelocity(400.0f)
{
Load("images/paddle.png");
assert(IsLoaded());
GetSprite().setOrigin(GetSprite().getLocalBounds().width /2, GetSprite().getLocalBounds().height / 2);
GetSprite().scale(scalePad1, 1);
}
PlayerPaddle::~PlayerPaddle()
{
}
void PlayerPaddle::Draw(sf::RenderWindow & rw)
{
VisibleGameObject::Draw(rw);
}
float PlayerPaddle::GetVelocity() const
{
return _velocity;
}
void PlayerPaddle::updPlyVelo(int modID) {
if (modID == 0) {
veloRange1 = 200.0f;
}
else if (modID == 1) {
veloRange1 = 400.0f;
}
else if (modID == 2) {
veloRange1 = 1000.0f;
}
_maxVelocity = veloRange1 * 2;
}
void PlayerPaddle::sclPad1(int modID) {
if (modID == 0) {
scalePad1 = 2;
}
else if (modID == 1) {
scalePad1 = 1;
}
else if (modID == 2) {
scalePad1 = 0.5;
}
GetSprite().scale(scalePad1, 1);
}
void PlayerPaddle::Update(float elapsedTime)
{
if (sf::Keyboard::isKeyPressed(sf::Keyboard::S))
{
_fast = 2;
}
else
{
_fast = 1;
}
if(sf::Keyboard::isKeyPressed(sf::Keyboard::A)&&!maxLeft)
{
_velocity= -veloRange1 * _fast;
}
else if(sf::Keyboard::isKeyPressed(sf::Keyboard::D)&&!maxRight)
{
_velocity= veloRange1 * _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);
}