-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathPlayer.cpp
94 lines (77 loc) · 1.77 KB
/
Player.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
#include "Player.h"
Player::Player(string n, int initialR, int initialC, string imagename) :Object(n, initialR, initialC, imagename)
{
score = 0;
lifeIncrements = 0;
lives = 3;
dir = Right;
}
string Player::getScore()
{
string str = to_string(score);
return str;
}
int Player::getScoreInt()
{
return score;
}
int Player::getLives()
{
return lives;
}
bool Player::loseLive() //returns false if player lost all lives
{
--lives;
if (lives == 0) //checks if the player lost all lives
return false;
else {
curColumn = initialColumn;
curRow = initialRow;
updatePosition();
return true;
}
}
void Player::move(int horizontal, int vertical)
{
curColumn = vertical;
curRow = horizontal;
updatePosition();
}
void Player::increaseScore(int n)
{
score += n;
if (checkLiveBonus()) //checks if score is high enough to increase lives
lives++;
}
bool Player::checkLiveBonus() //checks if score is high enough to increase lives
{
if (score > (lifeIncrements + 1) * 10000) { //so that every time the player earns 10000 points, lives are incremented
++lifeIncrements;
return true;
}
return false;
}
void Player::restart() {
curColumn = initialColumn;
curRow = initialRow;
updatePosition();
score = 0;
lifeIncrements = 0;
lives = 3;
}
void Player::setImage(string s) {
texture.loadFromFile(s);
shape.setTexture(&texture);
}
void Player::addSnapshots(string str[12]) {
snapshot.clear();
snapshot.resize(16);
for (int i = 0; i < 4; i++)
{
snapshot[0 + 4 * i].loadFromFile(str[0 + 3 * i]);
snapshot[1 + 4 * i].loadFromFile(str[1 + 3 * i]);
snapshot[2 + 4 * i].loadFromFile(str[2 + 3 * i]);
snapshot[3 + 4 * i].loadFromFile(str[1 + 3 * i]);
}
snapshotIndex = 0;
}