-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplayer.cpp
More file actions
142 lines (120 loc) · 1.9 KB
/
player.cpp
File metadata and controls
142 lines (120 loc) · 1.9 KB
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#include "player.h"
#include "weapon.h"
#include <iostream>
/*
void moveDown();
void moveUp();
void moveLeft();
void moveRight();
void fire();
void changeWeapon();
void loseLife();
void addPoints(int);
void addScore(int);
void setXdir(int);
void setYdir(int);
void setXpos(int);
void setYpos(int);
*/
UserPlayer::UserPlayer()
{
xpos = 150;
ypos = 300;
xdir = 0;
ydir = 0;
points = 0;
score = 0;
lives = 4;
isAlive = 1;
weaponIndex = 0;
Weapon newWeapon(0, *this);
weaponList.push_back(newWeapon);
image.load("player.png");
rect = image.rect();
rect.moveTo(xpos, ypos);
}
void UserPlayer::setUP()
{
image.load("up.png");
}
void UserPlayer::setRIGHT()
{
image.load("right.png");
}
void UserPlayer::setLEFT()
{
image.load("left.png");
}
void UserPlayer::setDOWN()
{
image.load("down.png");
}
void UserPlayer::moveDown()
{
rect.moveTo(xpos, ++ypos);
ypos++;
image.load("down.png");
}
void UserPlayer::moveUp()
{
rect.translate(0,-1);
ypos--;
image.load("up.png");
}
void UserPlayer::moveLeft()
{
rect.translate(-1,0);
xpos--;
image.load("left.png");
}
void UserPlayer::moveRight()
{
rect.translate(1,0);
xpos++;
image.load("right.png");
}
void UserPlayer::fire()
{
weaponList[weaponIndex].shoot();
}
void UserPlayer::changeWeapon()
{
weaponIndex++;
if (weaponIndex == weaponList.size())
{
weaponIndex = 0;
}
}
void UserPlayer::loseLife()
{
lives--;
if (lives == 0) isAlive = 0;
}
void UserPlayer::gainLife()
{
lives++;
}
void UserPlayer::addPoints(int addpoints)
{
points += addpoints;
}
void UserPlayer::addScore(int addscore)
{
score += addscore;
}
void UserPlayer::setXdir(int dir)
{
xdir = dir;
}
void UserPlayer::setYdir(int dir)
{
ydir = dir;
}
void UserPlayer::setXpos(int pos)
{
xpos = pos;
}
void UserPlayer::setYpos(int pos)
{
ypos = pos;
}