-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplayer.cpp
More file actions
194 lines (161 loc) · 4.09 KB
/
Copy pathplayer.cpp
File metadata and controls
194 lines (161 loc) · 4.09 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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
#include "player.h"
Player player;
// player movement
void Player::moveUp() {
this->vtrl = -1;
}
void Player::moveDown() {
this->vtrl = 1;
}
void Player::moveLeft() {
this->hrz = -1;
}
void Player::moveRight() {
this->hrz = 1;
}
void Player::stopMovement() {
this->hrz = 0;
this->vtrl = 0;
}
// print movement with animation
void Player::player_move(int key, vector<vector<short> > ¤t_map) {
// Key check
bool left = ( key == KEY_LEFT ) ? 1 : 0;
bool right = ( key == KEY_RIGHT ) ? 1 : 0;
bool down = ( key == KEY_DOWN ) ? 1 : 0;
bool up = ( key == KEY_UP ) ? 1 : 0;
// Reset player movement
this->stopMovement();
if (this->color == font_blue) {
this->symbol = "|@|";
}
else {
this->symbol = "|%|";
}
if (right) {
//dir_shoot = 1;
if (this->color == font_blue) {
this->symbol = "|@>";
}
else {
this->symbol = "|%>";
}
}
if (left) {
//dir_shoot = -1;
if (this->color == font_blue) {
this->symbol = "<@|";
}
else {
this->symbol = "<%|";
}
}
if (up) {
//dir_shoot = -2;
if (this->color == font_blue) {
this->symbol = "/@\\";
}
else {
this->symbol = "/%\\";
}
}
if (down) {
//dir_shoot = 2;
if (this->color == font_blue) {
this->symbol = "\\@/";
}
else {
this->symbol = "\\%/";
}
}
// Move player
this->hrz = int(right) - int(left);
this->vtrl = int(down) - int(up);
// Check
if (this->hrz != 0) {
this->vtrl = 0;
}
else if (this->vtrl != 0) {
this->hrz = 0;
}
this->x += this->hrz;
this->y += this->vtrl;
}
// Collsiion
void Player::player_collision(vector<vector<short> > ¤t_map) {
switch(current_map[this->y][this->x]) {
// Treasure collision
case i_empty: case i_door: case i_leftdoor: case i_rightdoor: case i_stairs3: case i_stairs4: case i_stairs5: case i_stairs6: case i_stairs7:
break;
case i_treasure:
this->open_treasure = 1;
break;
case i_key:
this->touch_key = 1;
break;
case i_npc: // npc
this->x -= this->hrz;
this->y -= this->vtrl;
this->chat_npc = 1;
break;
case i_monster:
this->x -= this->hrz;
this->y -= this->vtrl;
this->touch_monster = 1;
break;
case i_oldman:
this->x -= this->hrz;
this->y -= this->vtrl;
this->touch_oldman = 1;
break;
case i_librarian:
this->x -= this->hrz;
this->y -= this->vtrl;
this->touch_librarian = 1;
break;
case i_penny:
this->x -= this->hrz;
this->y -= this->vtrl;
this->touch_penny = 1;
break;
case i_cooper:
this->x -= this->hrz;
this->y -= this->vtrl;
this->touch_cooper = 1;
break;
case i_robert:
this->x -= this->hrz;
this->y -= this->vtrl;
this->touch_robert = 1;
break;
case i_dragon:
this->x -= this->hrz;
this->y -= this->vtrl;
this->touch_dragon = 1;
break;
case i_dragonnpc:
this->x -= this->hrz;
this->y -= this->vtrl;
this->touch_dragonnpc = 1;
break;
default:
this->x -= this->hrz;
this->y -= this->vtrl;
break;
}
}
// reset status
void Player::reset_player() {
this->touch_cooper = 0;
this->touch_robert = 0;
this->touch_penny = 0;
this->touch_librarian = 0;
this->touch_oldman = 0;
this->touch_monster = 0;
this->touch_dragon = 0;
this->touch_dragonnpc = 0;
this->chat_npc = 0;
this->open_treasure = 0;
this->touch_key = 0;
this->reach_ending = 0;
}