annotate trix/src/menu.c @ 16:8fa14e28f099

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