-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathentity.h
301 lines (248 loc) · 3.79 KB
/
entity.h
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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
class Entity{
protected:
int x;
int y;
int width;
int height;
bool dir;
bool dead;
int frame;
public:
void move(int x, int y){
this->x = x;
this->y = y;
}
int getX(){
return x;
}
int getY(){
return y;
}
int getWidth(){
return width;
}
int getHeight(){
return height;
}
bool getDir(){
return dir;
}
void setDir(bool direction){
dir = direction;
}
bool isDead(){
return dead;
}
void setDead(bool dead){
this->dead = dead;
}
int getFrame(){
return frame;
}
};
class Player: public Entity{
private:
bool running;
bool jumping;
bool landed;
int jumpStartY;
int jumpHeight;
int state;
public:
Player(int x, int y){
this->x = x;
this->y = y;
width = 8;
height = 8;
dir = true;
running = false;
jumping = false;
state = 0;
dead = false;
frame = 0;
}
~Player(){
}
void update(){
running = false;
if(jumping){
if(jumpHeight >= 50)jumpHeight = 50;
if(y <= jumpStartY - jumpHeight || y <= 5){
jumping = false;
landed = false;
}
}
}
void jump(){
jumping = true;
landed = false;
jumpHeight = 0;
jumpStartY = y;
}
bool getRunning(){
return running;
}
void setRunning(bool run){
running = run;
}
void setLanded(bool landed){
this->landed = landed;
}
bool getLanded(){
return landed;
}
bool getJumping(){
return jumping;
}
void setJumping(bool jump){
jumping = jump;
}
int getJumpHeight(){
return jumpHeight;
}
void setJumpHeight(int height){
jumpHeight = height;
}
int getState(){
return state;
}
void setState(int state){
this->state = state;
}
void updateFrame(){
frame++;
switch(state){
case 0:if(frame > 4)frame = 0;
break;
case 1:if(frame > 9 || frame < 5)frame = 5;
break;
case 2:if(frame > 13 || frame < 10)frame = 11;
break;
}
}
};
class Monster: public Entity{
private:
bool size;
int health;
public:
Monster(int x, int y, bool size){
this->x = x;
this->y = y;
this->size = size;
if(size){
width = 8;
height = 8;
health = 2;
}else{
width = 16;
height = 16;
health = 5;
}
dir = true;
dead = false;
frame = 0;
}
~Monster(){
}
void hurt(int amount){
health -= amount;
if(health <= 0)dead = true;
}
int getHealth(){
return health;
}
bool getSize(){
return size;
}
void updateFrame(){
if(size){
frame++;
if(frame > 21|| frame < 16)frame = 16;
}else {
frame+=2;
if(frame > 38|| frame < 32)frame = 32;
}
}
};
class Bullet: public Entity{
private:
int type;
int originWeapon;
int lift;
int charger;
int chargeTime;
bool bounce;
public:
Bullet(int x, int y, int type, int weapon){
this->x = x;
this->y = y;
this->type = type;
originWeapon = weapon;
lift = 0;
charger = 0;
if(type == 6)chargeTime = 60;
else chargeTime = 15;
bounce = false;
width = 4;
height = 4;
dead = false;
frame = 40+type;
}
~Bullet(){
}
int getType(){
return type;
}
void setType(int type){
type = type;
}
int getDamage(){
if(type == 0 || type == 4 || type == 5 || type == 6 || type == 7)return 5;
if(type == 1 || type == 3)return 1;
if(type == 2)return 3;
return 0;
}
int getOriginWeapon(){
return originWeapon;
}
int getLift(){
return lift;
}
void setLift(int lift){
this->lift = lift;
}
bool charge(){
charger++;
if(charger == chargeTime)return true;
return false;
}
bool getBounce(){
return bounce;
}
void setBounce(bool bounce){
this->bounce = bounce;
}
};
class Crate: public Entity{
private:
int weapon;
public:
Crate(int x, int y, int weapon){
this->x = x;
this->y = y;
this->weapon = weapon;
width = 8;
height = 8;
dead = true;
frame = 14;
}
~Crate(){
}
int getWeapon(){
return weapon;
}
void setWeapon(int weapon){
this->weapon = weapon;
}
};