Mercurial > hg > pub > prymula > com
comparison trix/src/menu.c @ 0:2787f5e749ae
INIT
author | prymula <prymula76@outlook.com> |
---|---|
date | Thu, 21 Sep 2023 22:33:57 +0200 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:2787f5e749ae |
---|---|
1 #include "trix.h" | |
2 /* | |
3 * Trix - klikanie po klockach | |
4 * Przemysław R. Pietraszczyk | |
5 * | |
6 * paźdżiernik 2006 r. | |
7 * | |
8 * licencja: Public Domain | |
9 */ | |
10 /* | |
11 #if WINDOWS | |
12 //#include "img\\about.xpm" | |
13 #include "xpm//about.xpm" | |
14 #elif LINUX | |
15 #include "xpm//about.xpm" | |
16 #endif | |
17 */ | |
18 #define Y_RETURN 400 | |
19 | |
20 | |
21 #define X_START X_CENTER(white_start_inscription->w) | |
22 #define X_HISCORES X_CENTER(white_hiscores_inscription->w) | |
23 #define X_ABOUT X_CENTER(white_about_inscription->w) | |
24 #define X_OPTIONS X_CENTER(white_options_inscription->w) | |
25 | |
26 #define X_RETURN X_CENTER(white_return_inscription->w) | |
27 | |
28 #define X_START_LEVEL X_CENTER(start_level_inscription->w) | |
29 #define X_TOPICAL_LEVEL 150 | |
30 #define X_MINUS 165 | |
31 #define X_PLUS 250 | |
32 #define X_NET 165 | |
33 | |
34 #define Y_START_LEVEL 100 | |
35 #define Y_TOPICAL_LEVEL 150 | |
36 #define Y_NET 250 | |
37 | |
38 // z trix.h begin | |
39 SDL_Surface * block[8]; | |
40 SDL_Surface * explode; | |
41 SDL_Surface * bomb; | |
42 SDL_Surface * wall; | |
43 SDL_Surface * smoke; | |
44 | |
45 SDL_Surface * net; | |
46 SDL_Surface * banner; | |
47 SDL_Surface * bg; | |
48 SDL_Surface * screen; | |
49 TTF_Font* font; | |
50 | |
51 SDL_Renderer * renderer; | |
52 SDL_Texture * tex_screen; | |
53 | |
54 SDL_Rect source, dest; | |
55 //int use_net; // zmienna wyswietlania siatki | |
56 //int start_level; // start gry od poziomu ... | |
57 //int score; | |
58 //int bonus; // nalicza premie | |
59 | |
60 //char * hifile; // path do hiscore | |
61 | |
62 | |
63 int use_net; // zmienna wyswietlania siatki | |
64 int start_level; // start gry od poziomu ... | |
65 int score; | |
66 int bonus; // nalicza premie | |
67 | |
68 char * hifile; // path do hiscore | |
69 struct tab tab_hiscores[5]; | |
70 char catalogue[N_PIC][40]; | |
71 struct FIELD field[23][26]; | |
72 // z trix.h end | |
73 | |
74 | |
75 SDL_Surface * prepare_text(int r, int b, int g, char *buffer); | |
76 void draw_text (int x, int y, SDL_Surface * image); | |
77 void save_settings(void); | |
78 void print_inscription(char * buffor, int desx, int desy); | |
79 void save_hiscores_to_file (void); | |
80 | |
81 /* sortuje tabele wynikiow i umieszcza | |
82 nowy wpis na odpowiednim miejscu */ | |
83 void prepare_new_place(char *new_name) { | |
84 | |
85 int i, j, hi = -1; | |
86 | |
87 /* szukamy miejsca na wpis */ | |
88 for (i=4; i>=0; --i) { | |
89 if (tab_hiscores[i].score < score)hi = i; | |
90 } | |
91 | |
92 /* przesowamy gorsze wyniki o miejsce w dol */ | |
93 for (i=4; i>hi; --i) { | |
94 tab_hiscores[i].score = tab_hiscores[i-1].score; | |
95 strcpy(tab_hiscores[i].name, tab_hiscores[i-1].name); | |
96 } | |
97 | |
98 /* nowy wpis */ | |
99 tab_hiscores[hi].score = score; | |
100 strcpy(tab_hiscores[hi].name, new_name); | |
101 | |
102 | |
103 /* zapamietanie wpisu */ | |
104 save_hiscores_to_file(); | |
105 | |
106 } | |
107 | |
108 | |
109 /* pobiera imie gracza */ | |
110 void get_name_of_player(void) { | |
111 | |
112 int i, done, p; | |
113 SDL_Rect srcrect, destrect; | |
114 SDL_Surface * enter = NULL; | |
115 SDL_Surface * enter_name_inscription; | |
116 char buffor[20]; | |
117 | |
118 destrect = set_rect(0,0,screen->w,screen->h); | |
119 SDL_FillRect(screen,&destrect,0); | |
120 | |
121 #define MAX 20 | |
122 | |
123 /* wypisanie informacji o wprowadzeniu danych */ | |
124 enter_name_inscription = (SDL_Surface *) prepare_text(255, 255, 255, "ENTER YOUR NAME"); | |
125 draw_text(X_CENTER(enter_name_inscription->w) , 100, enter_name_inscription); | |
126 | |
127 //SDL_Flip(screen); | |
128 | |
129 p = done = 0; | |
130 while (!done) | |
131 { | |
132 SDL_Event event; | |
133 | |
134 /* Check for events */ | |
135 while (SDL_PollEvent (&event)) | |
136 { | |
137 switch (event.type) | |
138 { | |
139 case SDL_KEYDOWN: | |
140 // printf("Nacini�o klawisz: %s\n", | |
141 // SDL_GetKeyName(event.key.keysym.sym)); | |
142 | |
143 if (event.key.keysym.sym==SDLK_ESCAPE) | |
144 done = 1; | |
145 | |
146 /* kasowanie ostatniej litery */ | |
147 if (event.key.keysym.sym==SDLK_BACKSPACE) | |
148 { | |
149 if (p) { | |
150 /* skracamy bufor */ | |
151 --p; | |
152 buffor[p] = '\0'; | |
153 | |
154 /* najperw czyscimy miejsce wpisu */ | |
155 destrect = set_rect(0, 150, screen->w,enter->h); | |
156 SDL_FillRect(screen,&destrect,0); | |
157 //SDL_UpdateRect(screen, 0, 150, screen->w, enter->h); | |
158 | |
159 SDL_FreeSurface(enter); | |
160 | |
161 if (strlen(buffor)) { | |
162 enter = (SDL_Surface *) prepare_text(255, 255, 255, buffor); | |
163 draw_text(X_CENTER(enter->w), 150, enter); | |
164 // SDL_UpdateRect(screen, X_CENTER(enter->w), 150, | |
165 // enter->w, enter->h); | |
166 } | |
167 /* jesli bufor jest pusty to koniecznie */ | |
168 else enter = NULL; | |
169 } | |
170 break; | |
171 } | |
172 /* zatwierdzanie */ | |
173 if (event.key.keysym.sym==SDLK_RETURN) | |
174 { | |
175 /* tylko wtedy gdy jest jakis podpis */ | |
176 if (p) | |
177 prepare_new_place(buffor); | |
178 | |
179 done = 1; | |
180 break; | |
181 } | |
182 /* dopisywanie litery na koncu */ | |
183 if (p < 20 && event.key.keysym.sym >= 97 && | |
184 event.key.keysym.sym <= 122) { | |
185 | |
186 /* najperw czyscimy miejsce wpisu */ | |
187 destrect = set_rect(0, 150, screen->w,32); | |
188 SDL_FillRect(screen,&destrect,0); | |
189 //SDL_UpdateRect(screen, 0, 150, screen->w, 32); | |
190 | |
191 SDL_FreeSurface(enter); | |
192 sprintf(&buffor[p], "%s", SDL_GetKeyName(event.key.keysym.sym)); | |
193 ++p; | |
194 enter = (SDL_Surface *) prepare_text(255, 255, 255, buffor); | |
195 draw_text(X_CENTER(enter->w), 150, enter); | |
196 //SDL_UpdateRect(screen, X_CENTER(enter->w), 150, | |
197 // enter->w, enter->h); | |
198 } | |
199 | |
200 break; | |
201 case SDL_QUIT: | |
202 exit(0); | |
203 break; | |
204 } | |
205 } | |
206 | |
207 dest = set_rect(0, 0, screen->w, screen->h); | |
208 //SDL_FillRect(screen, &dest, SDL_MapRGB(screen->format, 255, 255, 255)); | |
209 | |
210 source = set_rect(0, 0, screen->w, screen->h); | |
211 | |
212 tex_screen = SDL_CreateTextureFromSurface(renderer, screen); | |
213 SDL_RenderClear ( renderer ); | |
214 SDL_RenderCopy(renderer, tex_screen,&source,&dest); | |
215 SDL_RenderPresent(renderer); | |
216 SDL_DestroyTexture(tex_screen); | |
217 | |
218 } | |
219 | |
220 SDL_FreeSurface(enter); | |
221 SDL_FreeSurface(enter_name_inscription); | |
222 | |
223 } | |
224 | |
225 /* opcje */ | |
226 void options (void) { | |
227 | |
228 SDL_Surface * start_level_inscription; | |
229 SDL_Surface * white_net_inscription; | |
230 SDL_Surface * yellow_net_inscription; | |
231 SDL_Surface * white_minus_inscription; | |
232 SDL_Surface * yellow_minus_inscription; | |
233 SDL_Surface * white_plus_inscription; | |
234 SDL_Surface * yellow_plus_inscription; | |
235 SDL_Surface * yes_inscription; | |
236 SDL_Surface * no_inscription; | |
237 SDL_Surface * white_return_inscription; | |
238 SDL_Surface * yellow_return_inscription; | |
239 | |
240 | |
241 int done; | |
242 SDL_Rect srcrect, destrect; | |
243 char buffor[10]; | |
244 | |
245 start_level_inscription = (SDL_Surface *) prepare_text(255, 255, 255, "START LEVEL"); | |
246 white_net_inscription = (SDL_Surface *) prepare_text(255, 255, 255, "NET:"); | |
247 yellow_net_inscription = (SDL_Surface *) prepare_text(237, 0, 255, "NET:"); | |
248 white_minus_inscription = (SDL_Surface *) prepare_text(255, 255, 255, "<<"); | |
249 yellow_minus_inscription = (SDL_Surface *) prepare_text(237, 0, 255, "<<"); | |
250 white_plus_inscription = (SDL_Surface *) prepare_text(255, 255, 255, ">>"); | |
251 yellow_plus_inscription = (SDL_Surface *) prepare_text(237, 0, 255, ">>"); | |
252 yes_inscription = (SDL_Surface *) prepare_text(255, 255, 255, "YES"); | |
253 no_inscription = (SDL_Surface *) prepare_text(255, 255, 255, "NO "); | |
254 | |
255 white_return_inscription = (SDL_Surface *) prepare_text(255, 255, 255, "RETURN TO MENU"); | |
256 yellow_return_inscription = (SDL_Surface *) prepare_text(237, 0, 255, "RETURN TO MENU"); | |
257 | |
258 /* czysci ekran */ | |
259 destrect = set_rect(0,0,screen->w,screen->h); | |
260 SDL_FillRect(screen,&destrect,0); | |
261 | |
262 draw_text(X_START_LEVEL, Y_START_LEVEL, start_level_inscription); | |
263 draw_text(X_MINUS, Y_TOPICAL_LEVEL, white_minus_inscription); | |
264 draw_text(X_PLUS, Y_TOPICAL_LEVEL, white_plus_inscription); | |
265 | |
266 sprintf(buffor, "%2d", start_level); | |
267 print_inscription(buffor, X_MINUS+47, Y_TOPICAL_LEVEL); | |
268 | |
269 draw_text(X_NET, Y_NET, white_net_inscription); | |
270 | |
271 if (!use_net) draw_text(X_NET+60, Y_NET, no_inscription); | |
272 else draw_text(X_NET+60, Y_NET, yes_inscription); | |
273 | |
274 draw_text(X_RETURN, Y_RETURN, white_return_inscription); | |
275 | |
276 ////SDL_Flip(screen); | |
277 | |
278 done = 0; | |
279 while (!done) | |
280 { | |
281 SDL_Event event; | |
282 | |
283 /* Check for events */ | |
284 while (SDL_PollEvent (&event)) | |
285 { | |
286 switch (event.type) | |
287 { | |
288 case SDL_KEYDOWN: | |
289 // printf("Nacini�o klawisz: %s\n", | |
290 // SDL_GetKeyName(event.key.keysym.sym)); | |
291 | |
292 if (event.key.keysym.sym==SDLK_ESCAPE) | |
293 done = 1; | |
294 break; | |
295 case SDL_QUIT: | |
296 exit(0); | |
297 break; | |
298 case SDL_MOUSEMOTION: | |
299 | |
300 case SDL_MOUSEBUTTONDOWN: | |
301 // printf("Nacini�o przycisk o numerze %d na " | |
302 // "punkcie o wsp�rz�nych %d,%d\n", event.button.button, | |
303 // event.button.x, event.button.y); | |
304 /* Kursor na << */ | |
305 if (!event.button.button && event.button.x >= X_MINUS && | |
306 event.button.y >= Y_TOPICAL_LEVEL && | |
307 event.button.x <= X_MINUS + yellow_minus_inscription->w && | |
308 event.button.y <= Y_TOPICAL_LEVEL + yellow_minus_inscription->h) { | |
309 | |
310 draw_text(X_MINUS, Y_TOPICAL_LEVEL, yellow_minus_inscription); | |
311 // SDL_UpdateRect(screen, X_MINUS, Y_TOPICAL_LEVEL, | |
312 // yellow_minus_inscription->w, yellow_minus_inscription->h); | |
313 | |
314 } | |
315 /* gdy wcisnieto << */ | |
316 else if (event.button.button && event.button.x >= X_MINUS && | |
317 event.button.y >= Y_TOPICAL_LEVEL && | |
318 event.button.x <= X_MINUS + yellow_minus_inscription->w && | |
319 event.button.y <= Y_TOPICAL_LEVEL + yellow_minus_inscription->h) { | |
320 | |
321 if (start_level > 1) start_level -= 1; | |
322 | |
323 /* wymazuje wpis */ | |
324 destrect = set_rect(212,Y_TOPICAL_LEVEL, 28, 32); | |
325 SDL_FillRect(screen,&destrect,0); | |
326 // SDL_UpdateRect(screen, 212, Y_TOPICAL_LEVEL, 28, 32); | |
327 | |
328 /* nowy wpis */ | |
329 sprintf(buffor, "%2d", start_level); | |
330 print_inscription(buffor, X_MINUS+47, Y_TOPICAL_LEVEL); | |
331 //SDL_UpdateRect(screen, X_MINUS+47, Y_TOPICAL_LEVEL, 28, 32); | |
332 | |
333 /* << na zolto */ | |
334 draw_text(X_MINUS, Y_TOPICAL_LEVEL, yellow_minus_inscription); | |
335 //SDL_UpdateRect(screen, X_MINUS, Y_TOPICAL_LEVEL, | |
336 // yellow_minus_inscription->w, yellow_minus_inscription->h); | |
337 } | |
338 else { | |
339 /* << na bialo */ | |
340 draw_text(X_MINUS, Y_TOPICAL_LEVEL, white_minus_inscription); | |
341 // SDL_UpdateRect(screen, X_MINUS, Y_TOPICAL_LEVEL, | |
342 // white_minus_inscription->w, white_minus_inscription->h); | |
343 } | |
344 /* kursor na >> */ | |
345 if (!event.button.button && event.button.x >= X_PLUS && | |
346 event.button.y >= Y_TOPICAL_LEVEL && | |
347 event.button.x <= X_PLUS + yellow_plus_inscription->w && | |
348 event.button.y <= Y_TOPICAL_LEVEL + yellow_plus_inscription->h) { | |
349 | |
350 draw_text(X_PLUS, Y_TOPICAL_LEVEL, yellow_plus_inscription); | |
351 //SDL_UpdateRect(screen, X_PLUS, Y_TOPICAL_LEVEL, | |
352 // yellow_plus_inscription->w, yellow_plus_inscription->h); | |
353 | |
354 } | |
355 /* gdy wcisnieto >> */ | |
356 else if (event.button.button && event.button.x >= X_PLUS && | |
357 event.button.y >= Y_TOPICAL_LEVEL && | |
358 event.button.x <= X_PLUS + yellow_plus_inscription->w && | |
359 event.button.y <= Y_TOPICAL_LEVEL + yellow_plus_inscription->h) { | |
360 | |
361 if (start_level<10) start_level += 1; | |
362 | |
363 /* wymazuje wpis */ | |
364 destrect = set_rect(212,Y_TOPICAL_LEVEL, 28, 32); | |
365 SDL_FillRect(screen,&destrect,0); | |
366 //SDL_UpdateRect(screen, 212, Y_TOPICAL_LEVEL, 28, 32); | |
367 | |
368 /* nowy wpis */ | |
369 sprintf(buffor, "%2d", start_level); | |
370 print_inscription(buffor, X_MINUS+47, Y_TOPICAL_LEVEL); | |
371 //SDL_UpdateRect(screen, X_MINUS+47, Y_TOPICAL_LEVEL, 28, 32); | |
372 | |
373 /* >> na zolto */ | |
374 draw_text(X_PLUS, Y_TOPICAL_LEVEL, yellow_plus_inscription); | |
375 // SDL_UpdateRect(screen, X_PLUS, Y_TOPICAL_LEVEL, | |
376 // yellow_plus_inscription->w, yellow_plus_inscription->h); | |
377 } | |
378 else { | |
379 /* >> na bialo */ | |
380 draw_text(X_PLUS, Y_TOPICAL_LEVEL, white_plus_inscription); | |
381 // SDL_UpdateRect(screen, X_PLUS, Y_TOPICAL_LEVEL, | |
382 // white_plus_inscription->w, white_plus_inscription->h); | |
383 // printf ("nie wcisnieto \n"); | |
384 } | |
385 /* kursor na NET */ | |
386 if (!event.button.button && event.button.x >= X_NET && | |
387 event.button.y >= Y_NET && | |
388 event.button.x <= X_NET + yellow_net_inscription->w && | |
389 event.button.y <= Y_NET + yellow_net_inscription->h) { | |
390 | |
391 draw_text(X_NET, Y_NET, yellow_net_inscription); | |
392 //SDL_UpdateRect(screen, X_NET, Y_NET, | |
393 // yellow_net_inscription->w, yellow_net_inscription->h); | |
394 | |
395 } | |
396 /* gdy wcisnieto NET */ | |
397 else if (event.button.button && event.button.x >= X_NET && | |
398 event.button.y >= Y_NET && | |
399 event.button.x <= X_NET + yellow_net_inscription->w && | |
400 event.button.y <= Y_NET + yellow_net_inscription->h) { | |
401 | |
402 if (use_net) use_net =0; | |
403 else use_net =1; | |
404 | |
405 /* wymazuje wpis */ | |
406 destrect = set_rect(X_NET+60,Y_NET, | |
407 yes_inscription->w,yes_inscription->h); | |
408 SDL_FillRect(screen,&destrect,0); | |
409 | |
410 /* ustawia odpowiedni tekst */ | |
411 if (!use_net) draw_text(X_NET+60, Y_NET, no_inscription); | |
412 else draw_text(X_NET+60, Y_NET, yes_inscription); | |
413 | |
414 // SDL_UpdateRect(screen, X_NET+60, Y_NET, | |
415 // yes_inscription->w, yes_inscription->h); | |
416 | |
417 draw_text(X_NET, Y_NET, yellow_net_inscription); | |
418 // SDL_UpdateRect(screen, X_NET, Y_NET, | |
419 // yellow_net_inscription->w, yellow_net_inscription->h); | |
420 } | |
421 else { | |
422 | |
423 draw_text(X_NET, Y_NET, white_net_inscription); | |
424 //SDL_UpdateRect(screen, X_NET, Y_NET, | |
425 // white_net_inscription->w, white_net_inscription->h); | |
426 // printf ("nie wcisnieto \n"); | |
427 } | |
428 | |
429 /* Kursor na powrot do menu */ | |
430 if (!event.button.button && event.button.x >= X_RETURN && | |
431 event.button.y >= Y_RETURN && | |
432 event.button.x <= X_RETURN + yellow_return_inscription->w && | |
433 event.button.y <= Y_RETURN + yellow_return_inscription->h) { | |
434 | |
435 draw_text(X_RETURN, Y_RETURN, yellow_return_inscription); | |
436 // SDL_UpdateRect(screen, X_RETURN, Y_RETURN, | |
437 // yellow_return_inscription->w, yellow_return_inscription->h); | |
438 | |
439 } | |
440 | |
441 /* gdy wcisnieto powrot do menu */ | |
442 else if (event.button.button && event.button.x >= X_RETURN && | |
443 event.button.y >= Y_RETURN && | |
444 event.button.x <= X_RETURN + yellow_return_inscription->w && | |
445 event.button.y <= Y_RETURN + yellow_return_inscription->h) { | |
446 | |
447 done = 1; | |
448 save_settings(); | |
449 draw_text(X_RETURN, Y_RETURN, yellow_return_inscription); | |
450 // SDL_UpdateRect(screen, X_RETURN, Y_RETURN, | |
451 // yellow_return_inscription->w, yellow_return_inscription->h); | |
452 } | |
453 else { | |
454 /* powrot do menu na bialo */ | |
455 draw_text(X_RETURN, Y_RETURN, white_return_inscription); | |
456 // SDL_UpdateRect(screen, X_RETURN, Y_RETURN, | |
457 // white_return_inscription->w, white_return_inscription->h); | |
458 } | |
459 | |
460 break; | |
461 } | |
462 } | |
463 // //SDL_Flip(screen); | |
464 dest = set_rect(0, 0, screen->w, screen->h); | |
465 //SDL_FillRect(screen, &dest, SDL_MapRGB(screen->format, 255, 255, 255)); | |
466 | |
467 source = set_rect(0, 0, screen->w, screen->h); | |
468 | |
469 tex_screen = SDL_CreateTextureFromSurface(renderer, screen); | |
470 SDL_RenderClear ( renderer ); | |
471 SDL_RenderCopy(renderer, tex_screen,&source,&dest); | |
472 SDL_RenderPresent(renderer); | |
473 SDL_DestroyTexture(tex_screen); | |
474 } | |
475 | |
476 | |
477 | |
478 // czyscimy ekran przed powrotem | |
479 destrect = set_rect(0,0,screen->w,screen->h); | |
480 SDL_FillRect(screen,&destrect,0); | |
481 //SDL_Flip(screen); | |
482 | |
483 | |
484 | |
485 SDL_FreeSurface(start_level_inscription); | |
486 SDL_FreeSurface(white_net_inscription); | |
487 SDL_FreeSurface(yellow_net_inscription); | |
488 SDL_FreeSurface(white_minus_inscription); | |
489 SDL_FreeSurface(yellow_minus_inscription); | |
490 SDL_FreeSurface(white_plus_inscription); | |
491 SDL_FreeSurface(yellow_plus_inscription); | |
492 SDL_FreeSurface(yes_inscription); | |
493 SDL_FreeSurface(no_inscription); | |
494 SDL_FreeSurface(white_return_inscription); | |
495 SDL_FreeSurface(yellow_return_inscription); | |
496 | |
497 } | |
498 | |
499 void wait_for_return (void) { | |
500 | |
501 int done; | |
502 SDL_Surface * white_return_inscription; | |
503 SDL_Surface * yellow_return_inscription; | |
504 | |
505 white_return_inscription = (SDL_Surface *) prepare_text(255, 255, 255, "RETURN TO MENU"); | |
506 yellow_return_inscription = (SDL_Surface *) prepare_text(237, 0, 255, "RETURN TO MENU"); | |
507 | |
508 draw_text(X_RETURN, Y_RETURN, white_return_inscription); | |
509 | |
510 // //SDL_Flip(screen); | |
511 // SDL_UpdateRect(screen, X_RETURN, Y_RETURN, | |
512 // white_return_inscription->w, white_return_inscription->h); | |
513 | |
514 | |
515 done = 0; | |
516 while (!done) | |
517 { | |
518 SDL_Event event; | |
519 | |
520 /* Check for events */ | |
521 while (SDL_PollEvent (&event)) | |
522 { | |
523 switch (event.type) | |
524 { | |
525 case SDL_KEYDOWN: | |
526 // printf("Nacini�o klawisz: %s\n", | |
527 // SDL_GetKeyName(event.key.keysym.sym)); | |
528 | |
529 if (event.key.keysym.sym==SDLK_ESCAPE) | |
530 done = 1; | |
531 break; | |
532 case SDL_QUIT: | |
533 exit(0); | |
534 break; | |
535 case SDL_MOUSEMOTION: | |
536 | |
537 case SDL_MOUSEBUTTONDOWN: | |
538 // printf("Nacini�o przycisk o numerze %d na " | |
539 // "punkcie o wsp�rz�nych %d,%d\n", event.button.button, | |
540 // event.button.x, event.button.y); | |
541 | |
542 /* Kursor na powrot do menu */ | |
543 if (!event.button.button && event.button.x >= X_RETURN && | |
544 event.button.y >= Y_RETURN && | |
545 event.button.x <= X_RETURN + yellow_return_inscription->w && | |
546 event.button.y <= Y_RETURN + yellow_return_inscription->h) { | |
547 | |
548 draw_text(X_RETURN, Y_RETURN, yellow_return_inscription); | |
549 // SDL_UpdateRect(screen, X_RETURN, Y_RETURN, | |
550 // yellow_return_inscription->w, yellow_return_inscription->h); | |
551 | |
552 } | |
553 | |
554 /* gdy wcisnieto powrot do menu */ | |
555 else if (event.button.button && event.button.x >= X_RETURN && | |
556 event.button.y >= Y_RETURN && | |
557 event.button.x <= X_RETURN + yellow_return_inscription->w && | |
558 event.button.y <= Y_RETURN + yellow_return_inscription->h) { | |
559 | |
560 done = 1; | |
561 draw_text(X_RETURN, Y_RETURN, yellow_return_inscription); | |
562 // SDL_UpdateRect(screen, X_RETURN, Y_RETURN, | |
563 // yellow_return_inscription->w, yellow_return_inscription->h); | |
564 } | |
565 else { | |
566 /* powrot do manu na bialo */ | |
567 draw_text(X_RETURN, Y_RETURN, white_return_inscription); | |
568 // SDL_UpdateRect(screen, X_RETURN, Y_RETURN, | |
569 // white_return_inscription->w, white_return_inscription->h); | |
570 } | |
571 | |
572 break; | |
573 } | |
574 } | |
575 | |
576 | |
577 dest = set_rect(0, 0, screen->w, screen->h); | |
578 //SDL_FillRect(screen, &dest, SDL_MapRGB(screen->format, 255, 255, 255)); | |
579 | |
580 source = set_rect(0, 0, screen->w, screen->h); | |
581 | |
582 tex_screen = SDL_CreateTextureFromSurface(renderer, screen); | |
583 SDL_RenderClear ( renderer ); | |
584 SDL_RenderCopy(renderer, tex_screen,&source,&dest); | |
585 SDL_RenderPresent(renderer); | |
586 SDL_DestroyTexture(tex_screen); | |
587 | |
588 } | |
589 | |
590 SDL_FreeSurface(white_return_inscription); | |
591 SDL_FreeSurface(yellow_return_inscription); | |
592 } | |
593 | |
594 | |
595 void about (void) { | |
596 | |
597 SDL_Surface * about; | |
598 SDL_Rect srcrect, destrect; | |
599 | |
600 about=IMG_ReadXPMFromArray(about_xpm); | |
601 if(!about) { | |
602 printf("IMG_ReadXPMFromArray: %s\n", IMG_GetError()); | |
603 exit(1); | |
604 } | |
605 | |
606 /* czysci ekran */ | |
607 destrect = set_rect(0,0,screen->w,screen->h); | |
608 SDL_FillRect(screen,&destrect,0); | |
609 | |
610 /* umieszcza inskrypcje na ekranie */ | |
611 destrect = set_rect(X_CENTER(about->w),50,about->w,about->h); | |
612 srcrect = set_rect(0, 0, about->w, about->h); | |
613 SDL_BlitSurface(about,&srcrect, screen,&destrect); | |
614 // SDL_UpdateRect(screen, X_CENTER(about->w), 50, about->w, about->h); | |
615 | |
616 //SDL_Flip(screen); | |
617 | |
618 wait_for_return(); | |
619 | |
620 SDL_FreeSurface(about); | |
621 | |
622 /* czyscimy ekran przed powrotem */ | |
623 destrect = set_rect(0,0,screen->w,screen->h); | |
624 SDL_FillRect(screen,&destrect,0); | |
625 //SDL_Flip(screen); | |
626 | |
627 } | |
628 | |
629 | |
630 | |
631 | |
632 void hiscores(void) { | |
633 | |
634 SDL_Surface * place_inscription[5]; | |
635 SDL_Rect srcrect, destrect; | |
636 int done, i, y_place; | |
637 char buffor[50]; | |
638 | |
639 | |
640 destrect = set_rect(0,0,screen->w,screen->h); | |
641 SDL_FillRect(screen,&destrect,0); | |
642 | |
643 /* tworzenie obrazkow z wynikami */ | |
644 for (i=0; i<5; ++i) { | |
645 sprintf(buffor, "%d %s %d", i+1, tab_hiscores[i].name, tab_hiscores[i].score); | |
646 place_inscription[i]= (SDL_Surface *) prepare_text(255, 255, 255, buffor); | |
647 } | |
648 | |
649 | |
650 /* wypisuje ranking */ | |
651 y_place = 50; | |
652 for (i=0; i<5; ++i) { | |
653 draw_text(X_CENTER(place_inscription[i]->w), y_place, place_inscription[i]); | |
654 y_place += 50; | |
655 } | |
656 //SDL_Flip(screen); | |
657 | |
658 wait_for_return(); | |
659 | |
660 /* usuwanie obrazkow*/ | |
661 for (i=0; i<5; ++i) | |
662 SDL_FreeSurface(place_inscription[i]); | |
663 | |
664 | |
665 // czyscimy ekran przed powrotem | |
666 destrect = set_rect(0,0,screen->w,screen->h); | |
667 SDL_FillRect(screen,&destrect,0); | |
668 //SDL_Flip(screen); | |
669 | |
670 | |
671 } | |
672 | |
673 | |
674 int menu() { | |
675 | |
676 int done; | |
677 SDL_Rect srcrect, destrect; | |
678 SDL_Surface * white_start_inscription; | |
679 SDL_Surface * yellow_start_inscription; | |
680 SDL_Surface * white_hiscores_inscription; | |
681 SDL_Surface * yellow_hiscores_inscription; | |
682 SDL_Surface * white_about_inscription; | |
683 SDL_Surface * yellow_about_inscription; | |
684 SDL_Surface * white_options_inscription; | |
685 SDL_Surface * yellow_options_inscription; | |
686 | |
687 | |
688 white_start_inscription = (SDL_Surface *) prepare_text(255, 255, 255, "START"); | |
689 white_hiscores_inscription = (SDL_Surface *) prepare_text(255, 255, 255, "HiSCORES"); | |
690 white_about_inscription = (SDL_Surface *) prepare_text(255, 255, 255, "ABOUT"); | |
691 white_options_inscription = (SDL_Surface *) prepare_text(255, 255, 255, "OPTIONS"); | |
692 yellow_start_inscription = (SDL_Surface *) prepare_text(237, 0, 255, "START"); | |
693 yellow_hiscores_inscription = (SDL_Surface *) prepare_text(237, 0, 255, "HiSCORES"); | |
694 yellow_about_inscription = (SDL_Surface *) prepare_text(237, 0, 255, "ABOUT"); | |
695 yellow_options_inscription = (SDL_Surface *) prepare_text(237, 0, 255, "OPTIONS"); | |
696 | |
697 /* czysci ekran */ | |
698 destrect = set_rect(0,0,screen->w,screen->h); | |
699 SDL_FillRect(screen,&destrect,0); | |
700 | |
701 /* rysuje banner */ | |
702 destrect = set_rect(X_CENTER(banner->w),50,banner->w,banner->h); | |
703 srcrect = set_rect(0, 0, banner->w, banner->h); | |
704 SDL_BlitSurface(banner,&srcrect, screen,&destrect); | |
705 // SDL_UpdateRect(screen, X_CENTER(banner->w), 50, banner->w, banner->h); | |
706 | |
707 | |
708 draw_text(X_START, Y_START, white_start_inscription); | |
709 draw_text(X_HISCORES, Y_HISCORES, white_hiscores_inscription); | |
710 draw_text(X_OPTIONS, Y_OPTIONS, white_options_inscription); | |
711 draw_text(X_ABOUT, Y_ABOUT, white_about_inscription); | |
712 | |
713 //SDL_Flip(screen); | |
714 | |
715 done = 0; | |
716 while (!done) | |
717 { | |
718 SDL_Event event; | |
719 | |
720 /* Check for events */ | |
721 while (SDL_PollEvent (&event)) | |
722 { | |
723 switch (event.type) | |
724 { | |
725 case SDL_KEYDOWN: | |
726 // printf("Nacini�o klawisz: %s\n", | |
727 // SDL_GetKeyName(event.key.keysym.sym)); | |
728 | |
729 if (event.key.keysym.sym==SDLK_ESCAPE) | |
730 done = QUIT_GAME; | |
731 break; | |
732 case SDL_QUIT: | |
733 done = QUIT_GAME; | |
734 break; | |
735 case SDL_MOUSEMOTION: | |
736 case SDL_MOUSEBUTTONDOWN: | |
737 /* kursor na starcie */ | |
738 if (!event.button.button && event.button.x >= X_START && | |
739 event.button.y >= Y_START && | |
740 event.button.x <= X_START + yellow_start_inscription->w && | |
741 event.button.y <= Y_START + yellow_start_inscription->h) { | |
742 | |
743 draw_text(X_START, Y_START, yellow_start_inscription); | |
744 // SDL_UpdateRect(screen, X_START, Y_START, | |
745 // yellow_start_inscription->w, yellow_start_inscription->h); | |
746 } | |
747 /* gdy wcisnieto start */ | |
748 else if (event.button.button && event.button.x >= X_START && | |
749 event.button.y >= Y_START && | |
750 event.button.x <= X_START + yellow_start_inscription->w && | |
751 event.button.y <= Y_START + yellow_start_inscription->h) { | |
752 | |
753 done = START_GAME; | |
754 | |
755 draw_text(X_START, Y_START, yellow_start_inscription); | |
756 // SDL_UpdateRect(screen, X_START, Y_START, | |
757 // yellow_start_inscription->w, yellow_start_inscription->h); | |
758 } | |
759 else { | |
760 /* kursor poza napisem start */ | |
761 draw_text(X_START, Y_START, white_start_inscription); | |
762 // SDL_UpdateRect(screen, X_START, Y_START, | |
763 // white_start_inscription->w, white_start_inscription->h); | |
764 } | |
765 /* kursor na hiscores */ | |
766 if (!event.button.button && event.button.x >= X_HISCORES && | |
767 event.button.y >= Y_HISCORES && | |
768 event.button.x <= X_HISCORES + yellow_hiscores_inscription->w && | |
769 event.button.y <= Y_HISCORES + yellow_hiscores_inscription->h) { | |
770 | |
771 draw_text(X_HISCORES, Y_HISCORES, yellow_hiscores_inscription); | |
772 // SDL_UpdateRect(screen, X_HISCORES, Y_HISCORES, | |
773 // yellow_hiscores_inscription->w, yellow_hiscores_inscription->h); | |
774 } | |
775 /* gdy wcisnieto hiscores */ | |
776 else if (event.button.button && event.button.x >= X_HISCORES && | |
777 event.button.y >= Y_HISCORES && | |
778 event.button.x <= X_HISCORES + yellow_hiscores_inscription->w && | |
779 event.button.y <= Y_HISCORES + yellow_hiscores_inscription->h) { | |
780 | |
781 done = HISCORES; | |
782 | |
783 draw_text(X_HISCORES, Y_HISCORES, yellow_hiscores_inscription); | |
784 // SDL_UpdateRect(screen, X_HISCORES, Y_HISCORES, | |
785 // yellow_hiscores_inscription->w, yellow_hiscores_inscription->h); | |
786 } | |
787 else { | |
788 /* kursor poza napisem hiscore */ | |
789 draw_text(X_HISCORES, Y_HISCORES, white_hiscores_inscription); | |
790 // SDL_UpdateRect(screen, X_HISCORES, Y_HISCORES, | |
791 // white_hiscores_inscription->w, white_hiscores_inscription->h); | |
792 } | |
793 /* kursor na options */ | |
794 if (!event.button.button && event.button.x >= X_OPTIONS && | |
795 event.button.y >= Y_OPTIONS && | |
796 event.button.x <= X_OPTIONS + yellow_options_inscription->w && | |
797 event.button.y <= Y_OPTIONS + yellow_options_inscription->h) { | |
798 | |
799 draw_text(X_OPTIONS, Y_OPTIONS, yellow_options_inscription); | |
800 // SDL_UpdateRect(screen, X_OPTIONS, Y_OPTIONS, | |
801 // yellow_options_inscription->w, yellow_options_inscription->h); | |
802 } | |
803 /* gdy wcisnieto options */ | |
804 else if (event.button.button && event.button.x >= X_OPTIONS && | |
805 event.button.y >= Y_OPTIONS && | |
806 event.button.x <= X_OPTIONS + yellow_options_inscription->w && | |
807 event.button.y <= Y_OPTIONS + yellow_options_inscription->h) { | |
808 | |
809 done = OPTIONS; | |
810 | |
811 draw_text(X_OPTIONS, Y_OPTIONS, yellow_options_inscription); | |
812 // SDL_UpdateRect(screen, X_OPTIONS, Y_OPTIONS, | |
813 // yellow_options_inscription->w, yellow_options_inscription->h); | |
814 } | |
815 else { | |
816 /* kursor poza napisem options */ | |
817 draw_text(X_OPTIONS, Y_OPTIONS, white_options_inscription); | |
818 // SDL_UpdateRect(screen, X_OPTIONS, Y_OPTIONS, | |
819 // white_options_inscription->w, white_options_inscription->h); | |
820 } | |
821 | |
822 | |
823 /* kursor na about */ | |
824 if (!event.button.button && event.button.x >= X_ABOUT && | |
825 event.button.y >= Y_ABOUT && | |
826 event.button.x <= X_ABOUT + yellow_about_inscription->w && | |
827 event.button.y <= Y_ABOUT + yellow_about_inscription->h) { | |
828 | |
829 draw_text(X_ABOUT, Y_ABOUT, yellow_about_inscription); | |
830 // SDL_UpdateRect(screen, X_ABOUT, Y_ABOUT, | |
831 // yellow_about_inscription->w, yellow_about_inscription->h); | |
832 } | |
833 /* gdy wcisnieto about */ | |
834 else if (event.button.button && event.button.x >= X_ABOUT && | |
835 event.button.y >= Y_ABOUT && | |
836 event.button.x <= X_ABOUT + yellow_about_inscription->w && | |
837 event.button.y <= Y_ABOUT + yellow_about_inscription->h) { | |
838 | |
839 done = ABOUT; | |
840 | |
841 draw_text(X_ABOUT, Y_ABOUT, yellow_about_inscription); | |
842 // SDL_UpdateRect(screen, X_ABOUT, Y_ABOUT, | |
843 // yellow_about_inscription->w, yellow_about_inscription->h); | |
844 } | |
845 else { | |
846 /* kursor poza napisem about */ | |
847 draw_text(X_ABOUT, Y_ABOUT, white_about_inscription); | |
848 // SDL_UpdateRect(screen, X_ABOUT, Y_ABOUT, | |
849 // white_about_inscription->w, white_about_inscription->h); | |
850 } | |
851 | |
852 break; | |
853 default: | |
854 break; | |
855 | |
856 } | |
857 } | |
858 | |
859 dest = set_rect(0, 0, screen->w, screen->h); | |
860 source = set_rect(0, 0, screen->w, screen->h); | |
861 | |
862 tex_screen = SDL_CreateTextureFromSurface(renderer, screen); | |
863 SDL_RenderClear ( renderer ); | |
864 SDL_RenderCopy(renderer, tex_screen,&source,&dest); | |
865 SDL_RenderPresent(renderer); | |
866 SDL_DestroyTexture(tex_screen); | |
867 | |
868 } | |
869 SDL_FreeSurface(white_start_inscription); | |
870 SDL_FreeSurface(yellow_start_inscription); | |
871 SDL_FreeSurface(white_hiscores_inscription); | |
872 SDL_FreeSurface(yellow_hiscores_inscription); | |
873 SDL_FreeSurface(white_about_inscription); | |
874 SDL_FreeSurface(yellow_about_inscription); | |
875 SDL_FreeSurface(white_options_inscription); | |
876 SDL_FreeSurface(yellow_options_inscription); | |
877 | |
878 return done; | |
879 } |