-
Notifications
You must be signed in to change notification settings - Fork 0
/
Hero.cpp
363 lines (291 loc) · 8.29 KB
/
Hero.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
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
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
#include "Hero.h"
Hero::Hero()
{
//inicializace zakladnich atributu
getDefault();
next_experience=100;
m_orb = new Item;
m_orblight= new Lights;
experience=0;
infotext="";
level=0;
show_counter=0;
attack_counter=0;
show=false;
mounted=false;
krok=2.0;
svetlo = new Lights();
m_weapon= new Weapon();
m_mount = new Mount();
//loading modelů
m_cape= new Model3ds(4,"data/models/cape.3DS","data/textures/black.bmp");
m_cape->loadModel();
m_body= new Model3ds(4,"data/models/body.3DS","data/textures/black.bmp");
m_body->loadModel();
m_foot= new Model3ds(4,"data/models/nohy.3DS","data/textures/black.bmp");
m_foot->loadModel();
m_secondary_cape= new Model3ds(9,"data/models/second_cape.3DS","data/textures/black.bmp");
m_secondary_cape->loadModel();
m_head=new Model3ds(10,"data/models/head.3DS","data/textures/skin.bmp");
m_head->loadModel();
//defaultni kolizni vzdalenost
collisionSize=10;
}
void Hero::getDefault()
{
//reset pro novou mapu
m_x=0;
m_y=0;
m_z=0;
m_rotation=0;
rotace_orbu=0;
CollectedItems=0;
killedEnemies=0;
questComplete=false;
}
void Hero::QuestCheck(GLint max_items,GLint max_kills){
//test splneni ukolu
if((killedEnemies==max_kills) && (CollectedItems==max_items) && (questComplete==false))
{
infotext="Quest complete";
show=true;
killedEnemies=0;
CollectedItems=0;
questComplete=true;
PlaySound("data/sounds/Battle_Victory.wav", NULL, SND_ASYNC);
};
}
void Hero::calculate_leveling()
{
//vypocet xp, next xp, a levelu
show_counter=0;
if(experience>=next_experience)
{
level++;
infotext="Level up";
next_experience=1.5*next_experience;
show=true;
}
}
//zvyseni zkusenostnich bodu
void Hero::xp(int howmany)
{
infotext="+50XP";
show=true;
experience=this->experience+howmany;
calculate_leveling();
}
//vykresleni hrdiny
void Hero::draw()
{
Material::getBlueGlass();
//vykreslení orbu okolo hrdiny
glPushMatrix();
glTranslatef(m_x,m_y,m_z);
glPushMatrix();
glRotatef(rotace_orbu,0,1,0);
glTranslated(15,0,0);
m_orb->draw();
glPopMatrix();
glPopMatrix();
Material::getBlueGlass();
glPushMatrix();
if(!mounted){glTranslatef(0,0,m_z-5);}
else{glTranslatef(0,25,m_z-5);}
if(show==true) info(infotext,GLUT_BITMAP_HELVETICA_12,m_x,m_y+show_counter,1,1,1);
glPopMatrix();
//vykresleni hrdiny
Material::getBronze();
glPushMatrix();
glTranslatef(m_x,m_y,m_z);
// Rust hrdiny s levelem
glScaled(level*0.00000009+1,level*0.009+1,level*0.009+1);
glRotatef(m_rotation,0.0,1.0,0.0);
//mount
if(mounted==true)
{
m_mount->draw() ;
glTranslatef(0,20,0);
}
glRotatef(-90,0.0,1.0,0.0);
glScaled(0.4,0.4,0.4);
m_cape->drawModel();
glPushMatrix();
glTranslated(-10,60,-10);
glRotated(30,0,0,1);
glScaled(0.6,0.6,0.6);
glRotated(20,1,0,0);
//sword on back
m_weapon->draw();
glPopMatrix();
//ruce
glPushMatrix();
glScaled(1.2,1.2,1.2);
glTranslated(0,15,0);
m_foot->drawModel();
glPopMatrix();
//nohy a telo
m_foot->drawModel();
m_body->drawModel();
m_secondary_cape->drawModel();
//hlava a jeji uprava
glPushMatrix();
glTranslated(-7,4.5,0);
m_head->drawModel();
glPopMatrix();
//attack
drawAttack();
glPopMatrix();
svetlo->getDefault();
}
//jizda na zvireti, aktivace a deaktivace, zmena kolizini velikosti
void Hero::mount()
{
if(mounted==true)
{
mounted=false;
krok=krok/2;
collisionSize=collisionSize/3.5;
}
else
{
mounted=true;
krok=krok*2;
collisionSize=collisionSize*3.5;
infotext="Blackhorn mounted";
show=true;
PlaySound("data/sounds/bear-roar.wav", NULL, SND_ASYNC);
};
}
//vypis infa nad hracem
void Hero::info(char * string, void * font, int x, int y,float r, float g, float b)
{
glDisable(GL_TEXTURE_2D);
Material::getGold();
glColor3f(1.0,1.0,1.0);
glRasterPos2i(x,y);
while (*string)glutBitmapCharacter(font, *string++);
glEnable(GL_TEXTURE_2D);
}
//vykrelseni utoku
void Hero::drawAttack()
{
quadratic=gluNewQuadric();// Vrátí ukazatel na nový kvadrik
Material::getGold();
glTranslated(0,10,0);
glRotatef(90,1,0,0);
glScaled(2,2,2);
gluDisk(quadratic,size-3,size,32,32);
}
//animace utoku
void Hero::playAttack()
{
if(attack_counter<15 && active_attack==true)
{
attack_counter++;
size=size+3;
}
else{
active_attack=false;
attack_counter=0;
size=0;
}
}
//animace informaci nad hracem
void Hero::PlayInfo()
{
if(show_counter<50 && show==true){
show_counter++;
} else {
show_counter=0;show=false;
}
}
//detekce kolizi
void Hero::onCollision(int x1,int z1, int x2, int z2)
{
if(abs(x1-x2)<collisionSize && abs(z1-z2)<collisionSize && orientation=='u'){Transform(+krok,0);}
if(abs(x1-x2)<collisionSize && abs(z1-z2)<collisionSize && orientation=='d'){Transform(-krok,0);}
if(abs(x1-x2)<collisionSize && abs(z1-z2)<collisionSize && orientation=='l'){Transform(0,-krok);}
if(abs(x1-x2)<collisionSize && abs(z1-z2)<collisionSize && orientation=='r'){Transform(0,+krok);}
}
//nalezeni itemu
bool Hero::CollisionItemDetection(int x1,int z1, int x2, int z2)
{
if(abs(x1-x2)<collisionSize && abs(z1-z2)<collisionSize)
{
return true;
}
else {return false;}
}
//detekce kolize se stenou
bool Hero::CollisionWallDetection(int x1,int z1, int x2, int z2,int collisionSize)
{
if(abs(x1-x2)<collisionSize && abs(z1-z2)<collisionSize && orientation=='u'){Transform(+krok,0);}
if(abs(x1-x2)<collisionSize && abs(z1-z2)<collisionSize && orientation=='d'){Transform(-krok,0);}
if(abs(x1-x2)<collisionSize && abs(z1-z2)<collisionSize && orientation=='l'){Transform(0,-krok);}
if(abs(x1-x2)<collisionSize && abs(z1-z2)<collisionSize && orientation=='r'){Transform(0,+krok);}
}
//zabity nepritel
void Hero::onKilledEnemy()
{
killedEnemies++;
}
//sebrany item
void Hero::onCollectedItem()
{
CollectedItems++;
}
//stret s nepritelem
bool Hero::CollisionEnemyDetection(int x1,int z1, int x2, int z2)
{
if(abs(x1-x2)<collisionSize+10 && abs(z1-z2)<collisionSize+10)
{
return true;
}
else{return false;}
}
//animace rotace orbu
void Hero::rotateOrb()
{
rotace_orbu=rotace_orbu+5;
if(rotace_orbu==360)rotace_orbu=0;
}
//pohyb doleva
void Hero::left()
{
Transform(0,krok);
m_rotation=90.0;
orientation='l';
}
//pohyb doprava
void Hero::right()
{
Transform(0,-krok);
m_rotation=-90.0;
orientation='r';
}
//pohyb nahoru
void Hero::up()
{
Transform(-krok,0);
m_rotation=0.0;
orientation='u';
}
//pohyb dolu
void Hero::down()
{
Transform(krok,0);
m_rotation=180.0;
orientation='d';
}
Hero::~Hero()
{
//dtor
delete m_orb;
delete m_cape;
delete m_foot;
delete m_body;
delete m_weapon;
delete m_secondary_cape;
delete m_head;
}