-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunctions.h
More file actions
379 lines (306 loc) · 11 KB
/
functions.h
File metadata and controls
379 lines (306 loc) · 11 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
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
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
int tamBloco=32;
int tela[19][19];
BITMAP* buffer;
BITMAP* blocoVerm;
BITMAP* blocoAzul;
BITMAP* blocoVerde;
BITMAP* blocoCinza;
BITMAP* blocoAmarelo;
BITMAP* blocoRoxo;
BITMAP* blocoLaranja;
BITMAP* blocoRosa;
BITMAP* logo;
BITMAP* spiderman;
BITMAP* spiderman_meme;
BITMAP* spiderman_intro;
BITMAP* shield;
BITMAP* spiderlost;
FONT *letra;
FONT *fontCordia48;
FONT *fontCordia28;
Glow glow;
//class for simple map object
class objeto
{
public:
int x;
int y;
BITMAP* imagem;
};
//class for a player
class jogador
{
public:
int x;
int y;
BITMAP* imagem;
int artefatos;
int combustivel;
};
objeto artefato;
objeto combustivel;
jogador jogador_spiderman;
inline void init()
{ //allegro 4.2 initialization function
allegro_init();
set_color_depth(32);
set_gfx_mode(GFX_AUTODETECT_WINDOWED, 20*tamBloco, 20*tamBloco, 0, 0);
install_timer();
install_keyboard();
install_mouse();
}
inline void deinit()
{ //allegro deinit function
clear_keybuf();
allegro_exit();
}
void loadAll()
{ //class that loads all extern images and fonts
set_window_title("TictacKode - Mini-Game do Pirralho - Linguagem C com Allegro 4");
buffer=create_bitmap(20*tamBloco,20*tamBloco);
fontCordia28=load_font("fonts/cordia28.pcx",NULL,NULL);
if(!fontCordia28) { exit(1); }
letra=load_font("fonts/cordia36.pcx",NULL,NULL);
if(!letra) { exit(1); }
fontCordia48=load_font("fonts/cordia48.pcx",NULL,NULL);
if(!fontCordia48) { exit(1); }
logo=create_bitmap(640,640);
logo=load_bitmap("img/tictackode.bmp",0);
if(!logo) { exit(1); }
spiderman=create_bitmap(32,32);
spiderman=load_bitmap("img/spider_man_head.bmp",0);
if(!spiderman) { exit(1); }
shield=create_bitmap(32,32);
shield=load_bitmap("img/shield.bmp",0);
if(!shield) { exit(1); }
spiderman_meme=create_bitmap(640,640);
spiderman_meme=load_bitmap("img/spiderman_meme.bmp",0);
if(!spiderman_meme) { exit(1); }
spiderman_intro=create_bitmap(640,640);
spiderman_intro=load_bitmap("img/spiderman_intro.bmp",0);
if(!spiderman_intro) { exit(1); }
spiderlost=create_bitmap(640,640);
spiderlost=load_bitmap("img/spiderlost.bmp",0);
if(!spiderlost) { exit(1); }
}
void freeAll()
{ //clear bitmaps from memory
destroy_bitmap(blocoVerm);
destroy_bitmap(blocoAzul);
destroy_bitmap(blocoVerde);
destroy_bitmap(blocoCinza);
destroy_bitmap(blocoAmarelo);
destroy_bitmap(blocoRoxo);
destroy_bitmap(blocoLaranja);
destroy_bitmap(blocoRosa);
}
void criaBloco(BITMAP* bmp, int red, int green, int blue)
{ //this function generates the color for the square bitmaps
int escuroR = 30,escuroG=30,escuroB=30;
if (red < 30) { escuroR = 0; }
if (green < 30) { escuroG = 0; }
if (blue < 30) { escuroB = 0; }
rectfill(bmp, 0, 0, tamBloco - (tamBloco / 10), tamBloco - (tamBloco / 10), makecol(red, green, blue));
rectfill(bmp, 0, tamBloco - (tamBloco / 10), tamBloco, tamBloco, makecol(red - escuroR, green - escuroG, blue - escuroB));
rectfill(bmp, tamBloco - (tamBloco / 10), 0, tamBloco, tamBloco, makecol(red - escuroR, green - escuroG, blue - escuroB));
}
void initBlockColor()
{
// tamBloco é a variavel que guarda o tamanho dos blocos
// tamBloco=size of the square in pixels
blocoAzul=create_bitmap(tamBloco, tamBloco);
criaBloco(blocoAzul, 32, 32, 192);
blocoVerde = create_bitmap(tamBloco, tamBloco);
criaBloco(blocoVerde, 32, 192, 32);
blocoVerm = create_bitmap(tamBloco, tamBloco);
criaBloco(blocoVerm, 192, 32, 32);
blocoAmarelo = create_bitmap(tamBloco, tamBloco);
criaBloco(blocoAmarelo, 255,215,0);
blocoRoxo = create_bitmap(tamBloco, tamBloco);
criaBloco(blocoRoxo, 139, 0, 204);
blocoCinza = create_bitmap(tamBloco, tamBloco);
criaBloco(blocoCinza, 92, 92, 92);
blocoLaranja = create_bitmap(tamBloco, tamBloco);
criaBloco(blocoLaranja, 255, 153, 0);
blocoRosa = create_bitmap(tamBloco, tamBloco);
criaBloco(blocoRosa, 255, 0, 128);
}
void initGame()
{ //do the game initializations
srand(time(0));
jogador_spiderman.x=rand()%19;
jogador_spiderman.y=rand()%19;
artefato.x=rand()%19;
artefato.y=rand()%19;
combustivel.x=rand()%19;
combustivel.y=rand()%19;
jogador_spiderman.combustivel=(rand()%40)+15;
initBlockColor();
jogador_spiderman.imagem=spiderman;
textout_ex(jogador_spiderman.imagem, font, "P1", 5, 5,makecol(0, 0, 0), -1);
artefato.imagem=shield;
combustivel.imagem=blocoRosa;
textout_ex(combustivel.imagem, font, "GAS", 0, 5,makecol(0, 0, 0), -1);
jogador_spiderman.artefatos=0;
}
void tela_inicial()
{ //initial screen
key[KEY_ESC]=false;
int loop_count=0;
while(loop_count<250)
{
draw_sprite(buffer, spiderman_intro, 0, 0);
textprintf_ex(buffer, fontCordia48, 50,250 ,makecol(glow.fontaux,0,0),-1,"Ajude o Spidey a pegar");
textprintf_ex(buffer, fontCordia48, 80,300 ,makecol(glow.fontaux,0,0),-1,"o escudo do Captain");
loop_count++;
glow.glow();
rest(10);
blit(buffer,screen,0,0,0,0,20*tamBloco,20*tamBloco);
if(key[KEY_ESC]) { freeAll(); deinit(); exit(0); }
}
}
void desenhaBlocoRandomico(int i, int j)
{ //draws grayscale squares with random color
BITMAP* temp;
temp=create_bitmap(tamBloco,tamBloco);
int aux=64+rand()%191;
criaBloco(temp,aux,aux,aux);
blit(temp,buffer,0,0,i*tamBloco,j*tamBloco,(i*tamBloco)+tamBloco,(j*tamBloco)+tamBloco);
}
void reinicia_posicoes()
{ //reinit mob positions
combustivel.x=rand()%19;
combustivel.y=rand()%19;
artefato.x=rand()%19;
artefato.y=rand()%19;
}
void confere_se_jogador_pegou_o_artefato()
{ // checks if player got the shield
if ((jogador_spiderman.x==artefato.x)&&(jogador_spiderman.y==artefato.y))
{
jogador_spiderman.artefatos++;
int loop_count=0;
while(loop_count<50)
{
textprintf_ex(buffer, fontCordia48, 15,250 ,makecol(glow.fontaux,0,0), -1,"Pegou o escudo! contagem: %d ", jogador_spiderman.artefatos);
loop_count++;
glow.glow();
rest(10);
blit(buffer,screen,0,0,0,0,20*tamBloco,20*tamBloco);
}
artefato.x=rand()%19;
artefato.y=rand()%19;
}
}
void confere_se_jogador_pegou_o_combustivel()
{ //checks if player got the fuel/gas
if ((jogador_spiderman.x==combustivel.x)&&(jogador_spiderman.y==combustivel.y))
{
int upgradeCombustivel=6+(rand()%5);
jogador_spiderman.combustivel+=upgradeCombustivel;
int loop_count=0;
while(loop_count<50)
{
textprintf_ex(buffer, fontCordia48, 80,250 ,makecol(glow.fontaux,0,0), -1,"Pegou %d Combustivel", upgradeCombustivel);
loop_count++;
glow.glow();
rest(10);
blit(buffer,screen,0,0,0,0,20*tamBloco,20*tamBloco);
}
combustivel.x=rand()%19;
combustivel.y=rand()%19;
}
}
void confere_se_jogador_venceu()
{ //checks if player won
key[KEY_ESC]=false;
if (jogador_spiderman.artefatos==3)
{
int loop_count=0;
while(loop_count<1000)
{
draw_sprite(buffer, spiderman_meme, 0, 0);
textprintf_ex(buffer, fontCordia48, 15,300 ,makecol(glow.fontaux,0,0),-1,"VOCE VENCEU E MITOU!");
textprintf_ex(buffer, fontCordia28, 20,480 ,makecol(0,glow.fontaux,0),-1,"https://www.facebook.com/groups/ProgDesafios/");
textprintf_ex(buffer, fontCordia28, 20,540 ,makecol(0,glow.fontaux,0),-1,"https://www.youtube.com/user/tictacKode/playlists");
loop_count++;
glow.glow();
rest(10);
blit(buffer,screen,0,0,0,0,20*tamBloco,20*tamBloco);
if(key[KEY_ESC]) { freeAll(); deinit(); exit(0); }
}
freeAll(); deinit(); exit(0);
}
}
void paint()
{ //função que desenha o estado atual do jogo
//draws the current game state
int i, j;
for(i=0; i<20; i++)
{
for(j=0; j<20; j++)
{
desenhaBlocoRandomico(i,j);
}
}
blit(jogador_spiderman.imagem,buffer,0,0,jogador_spiderman.x*tamBloco,jogador_spiderman.y*tamBloco,(jogador_spiderman.x*tamBloco)+tamBloco,(jogador_spiderman.y*tamBloco)+tamBloco);
blit(artefato.imagem,buffer,0,0,artefato.x*tamBloco,artefato.y*tamBloco,(artefato.x*tamBloco)+tamBloco,(artefato.y*tamBloco)+tamBloco);
blit(combustivel.imagem,buffer,0,0,combustivel.x*tamBloco,combustivel.y*tamBloco,(combustivel.x*tamBloco)+tamBloco,(combustivel.y*tamBloco)+tamBloco);
textprintf_ex(buffer, fontCordia48, 10,tamBloco ,makecol(0,glow.fontaux,0), -1,"Combustivel: %d ",jogador_spiderman.combustivel);
textprintf_ex(buffer, fontCordia48, 10,tamBloco+50 ,makecol(0,glow.fontaux,0), -1,"Artefatos %d ",jogador_spiderman.artefatos);
blit(buffer,screen,0,0,0,0,20*tamBloco,20*tamBloco);
}
void fim_de_jogo()
{ //Game over screen
key[KEY_ESC]=false;
int loop_count=0;
while(loop_count<1000)
{
draw_sprite(buffer, spiderlost, 0, 0);
textprintf_ex(buffer, fontCordia48, 180,150 ,makecol(glow.fontaux,0,0),-1,"Game Over!",jogador_spiderman.artefatos);
textprintf_ex(buffer, fontCordia48, 50,200 ,makecol(0,glow.fontaux,0),-1,"Pegou %d vezes o escudo",jogador_spiderman.artefatos);
textprintf_ex(buffer, fontCordia48, 180,250 ,makecol(0,glow.fontaux,0),-1,"Esc para sair");
textprintf_ex(buffer, fontCordia28, 20,480 ,makecol(0,glow.fontaux,0),-1,"https://www.facebook.com/groups/ProgDesafios/");
textprintf_ex(buffer, fontCordia28, 20,540 ,makecol(0,glow.fontaux,0),-1,"https://www.youtube.com/user/tictacKode/playlists");
loop_count++;
glow.glow();
rest(10);
blit(buffer,screen,0,0,0,0,20*tamBloco,20*tamBloco);
if(key[KEY_ESC]) { freeAll(); deinit(); exit(0); }
}
freeAll(); deinit(); exit(0);
}
void controle()
{ // handles the keys that controls the application
bool ativou=false;
readkey();
if (key[KEY_UP]) { if(jogador_spiderman.y>0) { jogador_spiderman.y-=1; ativou=true; } else { } }
if (key[KEY_DOWN]) { if(jogador_spiderman.y<20) { jogador_spiderman.y+=1; ativou=true; } else { } }
if (key[KEY_LEFT]) { if(jogador_spiderman.x>0) { jogador_spiderman.x-=1; ativou=true; } else { } }
if (key[KEY_RIGHT]) { if(jogador_spiderman.x<20) { jogador_spiderman.x+=1; ativou=true; } else { } }
if (key[KEY_ESC]) { freeAll(); deinit(); exit(0); }
//checks if player got the shield
confere_se_jogador_pegou_o_artefato();
//checks if player got the fuel/gas
confere_se_jogador_pegou_o_combustivel();
//checks if player got the shield 3 times
confere_se_jogador_venceu();
key[KEY_UP]=false;
key[KEY_DOWN]=false;
key[KEY_LEFT]=false;
key[KEY_RIGHT]=false;
key[KEY_ESC]=false;
// testa se combustível acabou
//checks if player is out of fuel
if((ativou==true))
{
if(jogador_spiderman.combustivel>0)
{
jogador_spiderman.combustivel-=1;
}
else if (jogador_spiderman.combustivel<=0)
{
fim_de_jogo();
}
}
}