Rev 7341 | Rev 7345 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
7332 | leency | 1 | /* ------- KOSILKA FOR KOLIBI ------- |
2 | Written in C++ (MS Visual C++ 6.0+). |
||
3 | Version 1.16. |
||
968 | leency | 4 | |
5 | Andrey Mihaylovich aka Dron2004 |
||
3132 | leency | 6 | */ |
968 | leency | 7 | |
8 | |||
9 | #include "kosSyst.h" |
||
10 | #include "kosFile.h" |
||
3132 | leency | 11 | #include "images.cpp" |
968 | leency | 12 | |
13 | |||
7332 | leency | 14 | //External levels |
968 | leency | 15 | bool external_levels_available=false; |
16 | bool external_levels = false; |
||
17 | int level_read_result; |
||
18 | Byte * externallevels; |
||
19 | Byte external_levels_count[1] = {0}; |
||
20 | ///////////////// |
||
21 | |||
22 | int lastkosilkadirection=1; |
||
7332 | leency | 23 | int laststep=0; //Last step. 0-does not exists, 1-bottom, 2-up, 3-left, 4-right |
968 | leency | 24 | |
25 | |||
26 | Byte skindata[13824]; |
||
27 | int read_result=0; |
||
28 | bool skin_available=false; |
||
29 | bool w_redraw=true; |
||
30 | |||
7341 | leency | 31 | #define RUS 1 |
32 | #define ENG 2 |
||
33 | #ifndef LANG |
||
34 | #define LANG RUS |
||
35 | #endif |
||
36 | |||
37 | #if LANG == RUS |
||
7332 | leency | 38 | const char windowTitle[] = "Косилка для Колибри"; |
39 | const char version[] = "Версия 1.16"; |
||
40 | const char win[] = "Вы выиграли!"; |
||
41 | const char press_q[] = "<нажмитедля возврата в меню>"; |
||
42 | const char fail[] = "Игра окончена..."; |
||
43 | const char press_r[] = "<нажмите |
||
44 | const char k_o_s_i_l_k[] = "К О С И Л К А"; |
||
45 | const char for_kolibri[] = "для Колибри ОС"; |
||
46 | const char press_enter[] = "<для начала игры нажмите ENTER>"; |
||
47 | const char press_g[] = "<нажмите |
||
48 | const char press_a[] = "<нажмите для включения/выключения анимации>"; |
||
49 | const char press_h[] = "<нажмите |
||
50 | const char press_s[] = "<нажмите |
||
7333 | leency | 51 | const char level_label[] = "Уровень:"; |
7332 | leency | 52 | const char attempts_left[] = "Осталось попыток:"; |
53 | const char grass_left[] = "Осталось травы:"; |
||
7344 | leency | 54 | |
55 | const char level_select_1[] = "Выберите набор уровней (нажмите <1> или <2>):"; |
||
56 | const char level_select_2[] = "1. Встроенные уровни"; |
||
57 | const char level_select_3[] = "2. Внешний набор уровней"; |
||
58 | |||
59 | const char about1[] = "Коллектив разработчиков:"; |
||
60 | const char about2[] = "Андрей Михайлович aka Dron2004 - программирование, встроенная графика (без скина)"; |
||
61 | const char about3[] = "Mario79 - тестирование, помощь в разработке, важные идеи"; |
||
62 | const char about4[] = "Ataualpa - тестирование, помощь в разработке"; |
||
63 | const char about5[] = "Leency - тестирование, помощь в разработке, замечательные скины, важные идеи"; |
||
64 | const char about6[] = "Mike - тестирование, помощь в разработке"; |
||
65 | const char about7[] = "bw - тестирование, помощь в разработке, важные идеи"; |
||
66 | const char about8[] = "diamond - идея отмены хода, тестирование"; |
||
67 | const char about9[] = "Отдельное спасибо:"; |
||
68 | const char about10[] = "Всем, кто играет в эту игру :-) !"; |
||
69 | const char about11[] = "нажмите |
||
7332 | leency | 70 | #else |
71 | const char windowTitle[] = "Kosilka for Kolibri"; |
||
72 | const char version[] = " Ver. 1.16"; |
||
73 | const char win[] = " You won! "; |
||
74 | const char press_q[] = " |
||
75 | const char fail[] = " Game over. "; |
||
76 | const char press_r[] = " |
||
77 | const char k_o_s_i_l_k[] = "K O S I L K A"; |
||
78 | const char for_kolibri[] = "for Kolibri OS"; |
||
79 | const char press_enter[] = "press ENTER to start the game"; |
||
80 | const char press_g[] = " |
||
81 | const char press_a[] = " |
||
82 | const char press_h[] = " |
||
83 | const char press_s[] = " |
||
7333 | leency | 84 | const char level_label[] = "Level:"; |
7332 | leency | 85 | const char attempts_left[] = "Attempts left:"; |
86 | const char grass_left[] = "Grass left:"; |
||
7344 | leency | 87 | |
88 | const char level_select_1[] = "Shoose level pack (press <1> or <2>):"; |
||
89 | const char level_select_2[] = "1. Built-in levels"; |
||
90 | const char level_select_3[] = "2. External levels"; |
||
91 | |||
92 | const char about1[] = "Our team:"; |
||
93 | const char about2[] = "Andrei Mikhailovich aka Dron2004 - development, built-in graphics (excluding skin)"; |
||
94 | const char about5[] = "Leency - help in development and bugfixing, English translation, testing, beautiful skins"; |
||
95 | const char about3[] = "Mario79 - testing, help in development, ideas"; |
||
96 | const char about4[] = "Ataualpa - testing, help in development"; |
||
97 | const char about6[] = "Mike - testing, help in development"; |
||
98 | const char about7[] = "bw - testing, help in development, ideas"; |
||
99 | const char about8[] = "diamond - idea of turn back, testing"; |
||
100 | const char about9[] = "Special thanks to:"; |
||
101 | const char about10[] = "Everyone who plays this game :-) !"; |
||
102 | const char about11[] = "press |
||
7332 | leency | 103 | #endif |
968 | leency | 104 | |
7332 | leency | 105 | int levelcount=7; |
968 | leency | 106 | |
7332 | leency | 107 | char gamearea[20][20]; //The map |
968 | leency | 108 | |
7332 | leency | 109 | |
110 | short int kosilkax; // Kosilka position |
||
968 | leency | 111 | short int kosilkay; |
7332 | leency | 112 | short int kosilkadirection=1; //Last step direction. 1-bottom, 2-up, 3-left, 4-right |
113 | short int lives=2; |
||
114 | short int level=1; |
||
115 | short int status=0; //Where 0 - welcome screen |
||
116 | // 1 - the game |
||
117 | // 2 - win |
||
118 | // 3 - fail |
||
119 | // 4 - select the level (internal or external) |
||
120 | // -1 - about |
||
121 | bool gamestarted=false; //Key locker. If "false" then not possible to play |
||
968 | leency | 122 | |
7332 | leency | 123 | bool drawgraphics=true; //Draw detailed graphics or just colored rectangles |
124 | bool drawanimation=true; |
||
125 | int grassLeft(); //Notify about "Grass Left" function |
||
968 | leency | 126 | |
127 | RGB kosilka_d[576]; |
||
128 | RGB kosilka_l[576]; |
||
129 | RGB kosilka_r[576]; |
||
130 | RGB kosilka_u[576]; |
||
131 | RGB grass[576]; |
||
132 | RGB stone[576]; |
||
133 | RGB tree[576]; |
||
134 | RGB skos[576]; |
||
135 | |||
7332 | leency | 136 | //Palette. Decoding to 0xRRGGBB |
968 | leency | 137 | char * apppath; |
138 | char * levpath; |
||
139 | |||
140 | |||
141 | char * getLevelsPathName(){ |
||
142 | |||
143 | int lastslashindex=0; |
||
144 | static char levfilename[]="koslevel.pak"; |
||
145 | int tempslfnd=0; |
||
146 | |||
147 | for (tempslfnd=0; tempslfnd < strlen(kosExePath); tempslfnd++){ |
||
148 | if (kosExePath[tempslfnd]=='/'){lastslashindex=tempslfnd;} |
||
149 | } |
||
150 | |||
151 | levpath = new char[lastslashindex+strlen(levfilename)+1]; |
||
152 | |||
153 | for (tempslfnd=0; tempslfnd <= lastslashindex; tempslfnd++){ |
||
154 | levpath[tempslfnd]=kosExePath[tempslfnd]; |
||
155 | } |
||
156 | for (tempslfnd=0; tempslfnd < strlen(levfilename); tempslfnd++){ |
||
157 | levpath[tempslfnd+lastslashindex+1]=levfilename[tempslfnd]; |
||
158 | } |
||
159 | |||
160 | return levpath; |
||
161 | } |
||
162 | |||
163 | |||
7332 | leency | 164 | void interlevelpause(){ //The pause between levels |
968 | leency | 165 | Byte tempCode; |
166 | RGB tmprgb; |
||
167 | int tmpa=0; |
||
168 | laststep=0; |
||
169 | static int yellow_pal[] = {0xA8A93D,0xBEBF4C,0xD6D856,0xDFE15A,0xECEE5B, |
||
170 | 0xECEE5B,0xDFE15A,0xD6D856,0xBEBF4C,0xA8A93D}; |
||
171 | for (int iic=0;iic<240;iic++){ |
||
3137 | leency | 172 | kos_WaitForEvent(1); //Pause()? |
968 | leency | 173 | kos_GetKey(tempCode); |
174 | |||
175 | kos_DrawBar(iic*2,0,2,480,yellow_pal[tmpa]); |
||
176 | |||
177 | tmpa++; |
||
3132 | leency | 178 | if (tmpa>9) tmpa=0; |
968 | leency | 179 | } |
180 | } |
||
181 | |||
7332 | leency | 182 | void draw_element(int elx, int ely){ //Draw map element |
968 | leency | 183 | switch (gamearea[elx][ely]){ |
184 | case 'g': |
||
185 | if (drawgraphics==true){ |
||
186 | kos_PutImage((RGB*)grass,24,24,elx*24,ely*24); |
||
187 | } |
||
188 | else |
||
189 | { |
||
190 | kos_DrawBar(elx*24,ely*24,24,24,0xAAAA00); |
||
191 | } |
||
192 | |||
193 | break; |
||
194 | case 'k': |
||
195 | if (drawgraphics==true){ |
||
196 | switch(kosilkadirection){ |
||
197 | case 1: |
||
198 | kos_PutImage((RGB*)kosilka_d,24,24,elx*24,ely*24); |
||
199 | break; |
||
200 | case 2: |
||
201 | kos_PutImage((RGB*)kosilka_u,24,24,elx*24,ely*24); |
||
202 | break; |
||
203 | case 3: |
||
204 | kos_PutImage((RGB*)kosilka_l,24,24,elx*24,ely*24); |
||
205 | break; |
||
206 | case 4: |
||
207 | kos_PutImage((RGB*)kosilka_r,24,24,elx*24,ely*24); |
||
208 | break; |
||
209 | } |
||
210 | } |
||
211 | else |
||
212 | { |
||
213 | kos_DrawBar(elx*24,ely*24,24,24,0x00AAAA); |
||
214 | } |
||
215 | |||
216 | |||
217 | break; |
||
218 | case 'n': |
||
219 | if (drawgraphics==true){ |
||
220 | kos_PutImage((RGB*)skos,24,24,elx*24,ely*24); |
||
221 | } |
||
222 | else |
||
223 | { |
||
224 | kos_DrawBar(elx*24,ely*24,24,24,0xAAAAAA); |
||
225 | } |
||
226 | |||
227 | |||
228 | break; |
||
229 | case 's': |
||
230 | if (drawgraphics==true){ |
||
231 | kos_PutImage((RGB*)stone,24,24,elx*24,ely*24); |
||
232 | } |
||
233 | else |
||
234 | { |
||
235 | kos_DrawBar(elx*24,ely*24,24,24,0x555555); |
||
236 | } |
||
237 | |||
238 | |||
239 | break; |
||
240 | |||
241 | case 't': |
||
242 | if (drawgraphics==true){ |
||
243 | kos_PutImage((RGB*)tree,24,24,elx*24,ely*24); |
||
244 | } |
||
245 | else |
||
246 | { |
||
247 | kos_DrawBar(elx*24,ely*24,24,24,0x005500); |
||
248 | } |
||
249 | |||
250 | |||
251 | break; |
||
252 | } |
||
253 | |||
254 | } |
||
255 | |||
256 | |||
7332 | leency | 257 | void display_grass_left(){ |
968 | leency | 258 | kos_DrawBar(605,120,20,10,0xEEEEEE); |
259 | kos_DisplayNumberToWindow(grassLeft(),3,605,120,0x0000FF,nbDecimal,false); |
||
260 | } |
||
261 | |||
262 | |||
7332 | leency | 263 | void animate(int initcellx, int initcelly, int direction){ //kosilka movement animation |
968 | leency | 264 | int tmpp=0; |
265 | |||
3132 | leency | 266 | switch (direction){ |
968 | leency | 267 | case 1: |
268 | for (tmpp=0; tmpp<23;tmpp++){ |
||
269 | if (drawgraphics==true){ |
||
270 | kos_PutImage((RGB*)skos,24,24,initcellx*24,initcelly*24); |
||
271 | kos_PutImage((RGB*)kosilka_d,24,24,initcellx*24,initcelly*24+tmpp); |
||
272 | } else { |
||
273 | kos_DrawBar(initcellx*24,initcelly*24,24,24,0xAAAAAA); |
||
274 | kos_DrawBar(initcellx*24,initcelly*24+tmpp,24,24,0x00AAAA); |
||
275 | |||
276 | } |
||
277 | kos_Pause(1); |
||
278 | } |
||
279 | break; |
||
280 | case 2: |
||
281 | for (tmpp=0; tmpp<23;tmpp++){ |
||
282 | if (drawgraphics==true){ |
||
283 | kos_PutImage((RGB*)skos,24,24,initcellx*24,initcelly*24); |
||
284 | kos_PutImage((RGB*)kosilka_u,24,24,initcellx*24,initcelly*24-tmpp); |
||
285 | } else { |
||
286 | kos_DrawBar(initcellx*24,initcelly*24,24,24,0xAAAAAA); |
||
287 | kos_DrawBar(initcellx*24,initcelly*24-tmpp,24,24,0x00AAAA); |
||
288 | } |
||
289 | kos_Pause(1); |
||
290 | } |
||
291 | break; |
||
292 | case 3: |
||
293 | for (tmpp=0; tmpp<23;tmpp++){ |
||
294 | if (drawgraphics==true){ |
||
295 | kos_PutImage((RGB*)skos,24,24,initcellx*24,initcelly*24); |
||
296 | kos_PutImage((RGB*)kosilka_r,24,24,initcellx*24+tmpp,initcelly*24); |
||
297 | } else { |
||
298 | kos_DrawBar(initcellx*24,initcelly*24,24,24,0xAAAAAA); |
||
299 | kos_DrawBar(initcellx*24+tmpp,initcelly*24,24,24,0x00AAAA); |
||
300 | |||
301 | } |
||
302 | kos_Pause(1); |
||
303 | } |
||
304 | break; |
||
305 | case 4: |
||
306 | for (tmpp=0; tmpp<23;tmpp++){ |
||
307 | if (drawgraphics==true){ |
||
308 | kos_PutImage((RGB*)skos,24,24,initcellx*24,initcelly*24); |
||
309 | kos_PutImage((RGB*)kosilka_l,24,24,initcellx*24-tmpp,initcelly*24); |
||
310 | } else { |
||
311 | kos_DrawBar(initcellx*24,initcelly*24,24,24,0xAAAAAA); |
||
312 | kos_DrawBar(initcellx*24-tmpp,initcelly*24,24,24,0x00AAAA); |
||
313 | |||
314 | } |
||
315 | kos_Pause(1); |
||
316 | } |
||
317 | break; |
||
3132 | leency | 318 | } |
968 | leency | 319 | } |
320 | |||
321 | |||
7332 | leency | 322 | void draw_window(void){ |
2131 | leency | 323 | sProcessInfo sPI; |
324 | |||
968 | leency | 325 | if (w_redraw) |
326 | { |
||
7332 | leency | 327 | kos_WindowRedrawStatus(1); |
3132 | leency | 328 | kos_DefineAndDrawWindow(50,50,640,506-22+kos_GetSkinHeight(),0x74,0xEEEEEE,0,0,(Dword)windowTitle); |
7332 | leency | 329 | kos_WindowRedrawStatus(2); |
968 | leency | 330 | } |
331 | w_redraw=false; |
||
332 | |||
2131 | leency | 333 | kos_ProcessInfo( &sPI ); |
7332 | leency | 334 | if (sPI.rawData[70]&0x04) return; //do nothing if window is rolled-up into title |
968 | leency | 335 | |
7332 | leency | 336 | //Map redraw |
968 | leency | 337 | if ((status!=0)&&(status!=-1)&&(status!=4)) |
338 | { |
||
339 | kos_DrawBar(631-151,0,151,480,0xEEEEEE); |
||
340 | |||
7332 | leency | 341 | kos_WriteTextToWindow(500,30,0x80, 0, (char*)k_o_s_i_l_k,19); |
342 | kos_WriteTextToWindow(517,40,0x80, 0, (char*)for_kolibri,14); |
||
968 | leency | 343 | |
7333 | leency | 344 | kos_WriteTextToWindow(495,80,0x80, 0, (char*)level_label,6); |
968 | leency | 345 | kos_DisplayNumberToWindow(level,3,605,80,0x0000FF,nbDecimal,false); |
346 | |||
7332 | leency | 347 | kos_WriteTextToWindow(495,95,0x80, 0, (char*)attempts_left,11); |
968 | leency | 348 | kos_DisplayNumberToWindow(lives,1,605,95,0x0000FF,nbDecimal,false); |
349 | |||
7332 | leency | 350 | kos_WriteTextToWindow(495,120,0x80, 0, (char*)grass_left,11); |
968 | leency | 351 | display_grass_left(); |
352 | |||
7332 | leency | 353 | kos_WriteTextToWindow(526,450,0x80, 0,(char*)version,12); |
968 | leency | 354 | |
355 | for (int cy=0;cy<20;cy++) for (int cx=0;cx<20;cx++) draw_element(cx,cy); |
||
356 | } |
||
357 | |||
358 | if (status==0){ |
||
359 | kos_DrawBar(0,0,4,480,0x000000); |
||
360 | kos_DrawBar(628,0,3,480,0x000000); |
||
7332 | leency | 361 | |
968 | leency | 362 | |
363 | for (int tmpppy=0;tmpppy<20;tmpppy++){ |
||
364 | for (int tmpppx=0;tmpppx<26;tmpppx++){ |
||
365 | if ((tmpppx==0) || (tmpppx==25) || (tmpppy==0) || (tmpppy==19)){ |
||
366 | kos_PutImage((RGB*)stone,24,24,4+tmpppx*24,tmpppy*24); |
||
367 | } |
||
368 | else |
||
369 | { |
||
370 | kos_PutImage((RGB*)skos,24,24,4+tmpppx*24,tmpppy*24); |
||
371 | } |
||
372 | } |
||
373 | } |
||
374 | |||
375 | if (drawgraphics==true){ |
||
376 | kos_PutImage((RGB*)kosilka_d,24,24,305,150); |
||
377 | } |
||
378 | else |
||
379 | { |
||
380 | kos_DrawBar(305,150,24,24,0x00AAAA); |
||
381 | } |
||
382 | |||
383 | |||
384 | if (drawanimation==true){ |
||
385 | kos_DrawBar(335,150,24,24,0x00AA00); |
||
386 | } |
||
387 | else |
||
388 | { |
||
389 | kos_DrawBar(335,150,24,24,0xAA0000); |
||
390 | } |
||
391 | |||
7332 | leency | 392 | kos_WriteTextToWindow(255, 200,0x80, 0xFFFFFF, (char*)k_o_s_i_l_k, 19); |
393 | kos_WriteTextToWindow(290, 220,0x80, 0xFFFFFF, (char*)for_kolibri, 14); |
||
394 | kos_WriteTextToWindow(239, 240,0x80, 0xFFFFFF, (char*)press_enter, 30); |
||
395 | kos_WriteTextToWindow(30, 380,0x80, 0xFFFFFF, (char*)press_g, 53); |
||
396 | kos_WriteTextToWindow(30, 400,0x80, 0xFFFFFF, (char*)press_a, 41); |
||
397 | kos_WriteTextToWindow(30, 420,0x80, 0xFFFFFF, (char*)press_h, 32); |
||
398 | if (skin_available==true) kos_WriteTextToWindow(30, 440,0x80, 0xFFFFFF, (char*)press_s, 27); |
||
968 | leency | 399 | |
400 | // kos_WriteTextToWindow(470, 440,0x80, 0xFFFFFF ,"нажмите |
||
401 | // kos_DisplayNumberToWindow(external_levels_count[0],3,200,340,0x0000FF,nbDecimal,false); |
||
402 | |||
403 | |||
404 | |||
1012 | leency | 405 | kos_WriteTextToWindow(533, 440,0x80, 0xFFFFFF ,(char*)version,0); |
968 | leency | 406 | } |
407 | if (status==2){ |
||
408 | kos_DrawBar(10,150,610,200,0x528B4C); |
||
409 | kos_DrawBar(15,155,601,190,0x3BCF46); |
||
7332 | leency | 410 | kos_WriteTextToWindow(240,230,0x80, 0xFFFFFF ,(char*)win,13); |
411 | kos_WriteTextToWindow(240,250,0x80, 0xFFFFFF ,(char*)press_q,17); |
||
968 | leency | 412 | } |
413 | if (status==3){ |
||
414 | kos_DrawBar(10,150,610,200,0x8B4C4C); |
||
415 | kos_DrawBar(15,155,601,190,0xCF3B3B); |
||
7332 | leency | 416 | kos_WriteTextToWindow(220,220,0x80, 0xFFFFFF ,(char*)fail,13); |
417 | kos_WriteTextToWindow(220,240,0x80, 0xFFFFFF ,(char*)press_r,23); |
||
418 | kos_WriteTextToWindow(220,260,0x80, 0xFFFFFF ,(char*)press_q,17); |
||
968 | leency | 419 | } |
420 | if (status==-1){ |
||
421 | |||
422 | kos_DrawBar(0,0,4,480,0x000000); |
||
423 | kos_DrawBar(631-3,0,3,480,0x000000); |
||
424 | |||
425 | for (int tmpppy=0;tmpppy<20;tmpppy++){ |
||
426 | for (int tmpppx=0;tmpppx<26;tmpppx++){ |
||
427 | if ((tmpppx==0) || (tmpppx==25) || (tmpppy==0) || (tmpppy==19)){ |
||
428 | kos_PutImage((RGB*)stone,24,24,4+tmpppx*24,tmpppy*24); |
||
429 | } |
||
430 | else |
||
431 | { |
||
432 | kos_PutImage((RGB*)skos,24,24,4+tmpppx*24,tmpppy*24); |
||
433 | } |
||
434 | } |
||
435 | } |
||
436 | |||
7344 | leency | 437 | kos_WriteTextToWindow(40,40,0x80, 0xFFFFFF, (char*)windowTitle,22); |
438 | kos_WriteTextToWindow(40,60,0x80, 0xFFFFFF, (char*)version,12); |
||
439 | kos_WriteTextToWindow(40,75,0x80, 0xFFFFFF, "________________________________________",40); |
||
968 | leency | 440 | |
7344 | leency | 441 | kos_WriteTextToWindow(40,120,0x80, 0xFFFFFF, (char*)about1, 18); |
442 | kos_WriteTextToWindow(40,150,0x80, 0xEEFFEE, (char*)about2, 32); |
||
443 | kos_WriteTextToWindow(40,170,0x80, 0xDDFFDD, (char*)about3, 35); |
||
444 | kos_WriteTextToWindow(40,190,0x80, 0xCCFFCC, (char*)about4, 36); |
||
445 | kos_WriteTextToWindow(40,210,0x80, 0xBBFFBB, (char*)about5, 62); |
||
446 | kos_WriteTextToWindow(40,230,0x80, 0xAAFFAA, (char*)about6, 34); |
||
447 | kos_WriteTextToWindow(40,250,0x80, 0x99FF99, (char*)about7, 49); |
||
448 | kos_WriteTextToWindow(40,270,0x80, 0x99FF99, (char*)about8, 49); |
||
968 | leency | 449 | |
7344 | leency | 450 | kos_WriteTextToWindow(40,300,0x80, 0x88FF88, (char*)about9, 16); |
451 | kos_WriteTextToWindow(40,330,0x80, 0x77FF77, (char*)about10, 50); |
||
968 | leency | 452 | |
7344 | leency | 453 | kos_WriteTextToWindow(40,430,0x80, 0x66FF66, (char*)about11, 35); |
968 | leency | 454 | } |
455 | |||
456 | |||
457 | if (status==4){ |
||
458 | kos_DrawBar(0,0,631,480,0x000000); |
||
459 | |||
460 | |||
461 | for (int tmpppy=0;tmpppy<20;tmpppy++){ |
||
462 | for (int tmpppx=0;tmpppx<26;tmpppx++){ |
||
463 | if ((tmpppx==0) || (tmpppx==25) || (tmpppy==0) || (tmpppy==19)){ |
||
464 | kos_PutImage((RGB*)stone,24,24,4+tmpppx*24,tmpppy*24); |
||
465 | } |
||
466 | else |
||
467 | { |
||
468 | kos_PutImage((RGB*)skos,24,24,4+tmpppx*24,tmpppy*24); |
||
469 | } |
||
470 | } |
||
471 | } |
||
472 | |||
7344 | leency | 473 | kos_WriteTextToWindow(215, 200,0x80, 0xFFFFFF, (char*)level_select_1,0); |
474 | kos_WriteTextToWindow(215, 220,0x80, 0xFFFFFF, (char*)level_select_2,0); |
||
475 | kos_WriteTextToWindow(215, 240,0x80, 0xFFFFFF, (char*)level_select_3,0); |
||
968 | leency | 476 | |
477 | } |
||
478 | |||
479 | } |
||
480 | |||
481 | |||
482 | |||
7332 | leency | 483 | //Game level description, |
484 | //where k - kosilka |
||
485 | // g - grass |
||
486 | // n - cut grass |
||
487 | // s - stone |
||
488 | // t - tree |
||
968 | leency | 489 | void initializeLevel(int levnum){ |
490 | laststep=0; |
||
491 | if (external_levels==false){ |
||
492 | |||
493 | kosilkadirection=1; |
||
494 | if (levnum==1){ |
||
495 | static char tmparea[20][20]={{'k','t','g','g','g','g','g','s','g','g','g','g','g','g','g','g','g','g','g','g'}, |
||
496 | {'g','s','g','s','g','g','g','s','g','s','g','g','s','g','g','g','g','g','g','g'}, |
||
497 | {'g','t','g','s','g','g','g','s','g','s','g','g','s','g','g','g','g','g','g','g'}, |
||
498 | {'g','s','g','s','g','g','g','s','g','s','g','g','s','g','g','g','g','g','g','g'}, |
||
499 | {'g','t','g','s','g','g','g','s','g','s','g','g','s','g','g','g','g','g','g','g'}, |
||
500 | {'g','s','g','s','g','g','g','s','g','g','g','g','s','g','g','g','g','g','g','g'}, |
||
501 | {'g','t','g','s','g','g','g','s','g','g','g','g','s','g','g','s','s','s','g','g'}, |
||
502 | {'g','s','g','s','g','g','g','s','g','g','g','g','s','g','g','s','s','s','g','g'}, |
||
503 | {'g','t','g','s','g','g','g','s','g','g','g','g','s','g','g','s','s','s','g','g'}, |
||
504 | {'g','s','g','s','g','g','g','s','g','g','g','g','s','g','g','s','g','g','g','g'}, |
||
505 | {'g','t','g','s','g','g','g','s','g','g','g','g','s','g','g','g','g','g','g','g'}, |
||
506 | {'g','s','g','s','g','g','g','s','g','g','g','g','s','g','g','g','g','g','g','g'}, |
||
507 | {'g','t','g','s','g','g','g','s','g','g','g','g','s','g','g','g','g','g','g','g'}, |
||
508 | {'g','s','g','s','g','g','g','s','g','g','g','g','s','g','g','g','g','g','g','g'}, |
||
509 | {'g','t','g','s','g','g','g','s','g','g','g','g','s','g','g','g','g','g','g','g'}, |
||
510 | {'g','s','g','s','g','g','g','s','g','g','g','g','s','g','g','g','g','g','g','g'}, |
||
511 | {'g','t','g','s','g','g','g','s','g','g','g','g','s','g','g','g','g','g','g','g'}, |
||
512 | {'g','s','g','s','g','g','g','s','g','g','g','g','s','g','g','g','g','g','g','g'}, |
||
513 | {'g','t','g','s','g','g','g','s','g','g','g','g','s','g','g','g','g','g','g','g'}, |
||
514 | {'g','g','g','s','g','g','g','g','g','s','g','g','s','g','g','g','g','g','g','g'}}; |
||
515 | for (int tyy=0;tyy<20;tyy++){ |
||
516 | for (int txx=0;txx<20;txx++){ |
||
517 | |||
518 | if (tmparea[txx][tyy]=='k'){ |
||
519 | kosilkax=tyy; |
||
520 | kosilkay=txx; |
||
521 | } |
||
522 | |||
523 | gamearea[txx][tyy]=tmparea[tyy][txx]; |
||
524 | } |
||
525 | } |
||
526 | } |
||
527 | if (levnum==2){ |
||
528 | static char tmparea[20][20]={{'s','s','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g'}, |
||
529 | {'s','s','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','s','s','g'}, |
||
530 | {'g','k','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','s','s','g'}, |
||
531 | {'g','g','g','g','g','g','g','g','g','g','g','g','s','s','g','g','g','g','g','g'}, |
||
532 | {'g','g','g','g','g','g','g','g','g','g','g','g','s','s','g','g','g','g','g','g'}, |
||
533 | {'g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g'}, |
||
534 | {'g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g'}, |
||
535 | {'g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g'}, |
||
536 | {'s','s','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g'}, |
||
537 | {'s','s','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g'}, |
||
538 | {'g','g','g','g','g','g','g','g','s','s','g','g','g','g','g','g','g','s','s','g'}, |
||
539 | {'g','g','g','g','g','g','g','g','s','s','g','g','g','g','g','g','g','s','s','g'}, |
||
540 | {'g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g'}, |
||
541 | {'g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g'}, |
||
542 | {'g','g','g','g','g','g','g','g','g','g','g','g','g','s','s','g','g','g','g','g'}, |
||
543 | {'g','g','g','g','g','g','g','g','g','g','g','g','g','s','s','g','g','g','g','g'}, |
||
544 | {'g','g','g','s','s','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g'}, |
||
545 | {'g','g','g','s','s','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g'}, |
||
546 | {'g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g'}, |
||
547 | {'g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g'}}; |
||
548 | for (int tyy=0;tyy<20;tyy++){ |
||
549 | for (int txx=0;txx<20;txx++){ |
||
550 | |||
551 | if (tmparea[txx][tyy]=='k'){ |
||
552 | kosilkax=tyy; |
||
553 | kosilkay=txx; |
||
554 | } |
||
555 | |||
556 | gamearea[txx][tyy]=tmparea[tyy][txx]; |
||
557 | } |
||
558 | } |
||
559 | } |
||
560 | |||
561 | if (levnum==3){ |
||
562 | static char tmparea[20][20]={{'t','n','t','n','t','n','t','n','t','n','t','n','t','n','t','n','t','n','t','k'}, |
||
563 | {'n','t','g','g','g','g','g','g','g','g','g','g','s','n','n','s','n','s','t','g'}, |
||
564 | {'t','n','g','g','g','g','g','g','g','g','g','g','n','t','n','n','n','t','t','g'}, |
||
565 | {'n','t','g','g','g','g','g','g','g','g','g','g','n','s','n','s','n','s','t','g'}, |
||
566 | {'t','n','g','g','g','g','g','s','s','g','g','g','n','n','n','n','n','t','t','g'}, |
||
567 | {'n','t','g','g','g','g','g','g','g','g','g','g','t','n','s','n','n','s','t','g'}, |
||
568 | {'t','n','g','g','g','g','g','g','g','g','g','g','n','n','n','n','n','t','t','g'}, |
||
569 | {'n','t','g','g','g','g','g','g','g','g','g','g','n','n','s','n','n','s','t','g'}, |
||
570 | {'t','n','g','g','g','g','g','g','g','g','g','g','n','s','n','n','n','t','t','g'}, |
||
571 | {'n','t','g','g','g','g','g','g','g','g','g','g','s','n','n','n','n','t','g','g'}, |
||
572 | {'t','n','g','g','g','s','g','g','g','g','g','g','t','t','t','t','t','t','g','g'}, |
||
573 | {'n','t','g','g','g','s','g','g','g','g','g','g','g','g','g','g','g','t','g','g'}, |
||
574 | {'t','n','g','g','g','g','g','g','g','g','g','g','t','t','g','g','g','t','g','g'}, |
||
575 | {'n','t','g','g','g','g','g','g','t','t','g','g','g','t','g','g','g','t','g','g'}, |
||
576 | {'t','n','g','g','g','g','g','g','t','t','g','g','g','t','g','g','g','t','g','g'}, |
||
577 | {'n','t','g','g','g','g','g','g','g','g','g','g','g','t','g','g','g','t','g','g'}, |
||
578 | {'t','n','g','g','g','g','g','g','g','g','g','g','g','t','t','g','g','t','g','g'}, |
||
579 | {'n','t','g','g','g','g','g','g','g','g','g','g','g','g','t','g','g','t','g','g'}, |
||
580 | {'t','n','g','g','g','g','g','g','g','g','g','g','g','g','t','g','g','t','g','g'}, |
||
581 | {'n','t','s','s','s','s','s','s','s','s','s','s','s','s','t','g','g','g','g','g'}}; |
||
582 | for (int tyy=0;tyy<20;tyy++){ |
||
583 | for (int txx=0;txx<20;txx++){ |
||
584 | |||
585 | if (tmparea[txx][tyy]=='k'){ |
||
586 | kosilkax=tyy; |
||
587 | kosilkay=txx; |
||
588 | } |
||
589 | |||
590 | gamearea[txx][tyy]=tmparea[tyy][txx]; |
||
591 | } |
||
592 | } |
||
593 | } |
||
594 | |||
595 | if (levnum==4){ |
||
596 | static char tmparea[20][20]={{'t','t','t','t','t','t','t','t','t','t','t','t','t','t','t','t','t','t','t','t'}, |
||
597 | {'t','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','s','n','t'}, |
||
598 | {'t','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','s','n','t'}, |
||
599 | {'t','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','s','n','t'}, |
||
600 | {'t','g','g','g','g','g','g','g','t','t','g','g','g','g','g','g','g','s','n','t'}, |
||
601 | {'t','g','g','g','g','g','g','g','t','t','g','g','g','g','g','g','g','s','n','t'}, |
||
602 | {'t','g','g','g','g','g','g','g','t','t','g','g','g','g','g','g','g','s','n','t'}, |
||
603 | {'t','g','g','g','g','g','g','g','t','t','g','g','g','g','g','g','g','s','n','t'}, |
||
604 | {'t','g','g','g','g','g','g','g','t','t','g','g','g','g','g','g','g','s','s','t'}, |
||
605 | {'t','g','g','g','g','t','t','t','t','t','t','t','t','g','g','g','g','g','g','t'}, |
||
606 | {'t','g','g','g','g','t','t','t','t','t','t','t','t','g','g','g','g','g','g','t'}, |
||
607 | {'t','g','g','g','g','g','g','g','t','t','g','g','g','g','g','g','g','g','g','t'}, |
||
608 | {'t','g','g','g','g','g','g','g','t','t','g','g','g','g','g','g','g','g','g','t'}, |
||
609 | {'t','g','g','g','g','g','g','g','t','t','g','g','g','g','g','g','g','g','g','t'}, |
||
610 | {'t','g','g','g','g','g','g','g','t','t','g','g','g','g','g','g','g','g','g','t'}, |
||
611 | {'t','g','g','g','g','g','g','g','t','t','g','g','g','g','g','g','g','g','g','t'}, |
||
612 | {'t','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','t'}, |
||
613 | {'t','k','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','t'}, |
||
614 | {'t','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','t'}, |
||
615 | {'t','t','t','t','t','t','t','t','t','t','t','t','t','t','t','t','t','t','t','t'}}; |
||
616 | for (int tyy=0;tyy<20;tyy++){ |
||
617 | for (int txx=0;txx<20;txx++){ |
||
618 | |||
619 | if (tmparea[txx][tyy]=='k'){ |
||
620 | kosilkax=tyy; |
||
621 | kosilkay=txx; |
||
622 | } |
||
623 | |||
624 | gamearea[txx][tyy]=tmparea[tyy][txx]; |
||
625 | } |
||
626 | } |
||
627 | } |
||
628 | |||
629 | if (levnum==5){ |
||
630 | static char tmparea[20][20]={{'t','t','t','t','t','t','t','t','t','t','t','t','t','t','t','t','t','t','t','t'}, |
||
631 | {'t','s','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','t'}, |
||
632 | {'t','t','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','t'}, |
||
633 | {'t','s','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','t'}, |
||
634 | {'t','s','g','g','g','g','g','t','g','g','t','g','g','g','g','g','g','g','g','t'}, |
||
635 | {'t','t','g','g','g','g','t','n','t','t','t','g','g','g','g','g','g','g','g','t'}, |
||
636 | {'t','s','g','g','g','g','t','n','n','n','t','g','g','g','g','g','g','g','g','t'}, |
||
637 | {'t','k','g','g','g','g','t','n','n','n','t','g','g','g','g','g','g','g','g','t'}, |
||
638 | {'t','g','g','g','g','g','t','n','n','n','t','g','g','g','g','g','g','g','g','t'}, |
||
639 | {'t','g','g','g','g','g','t','n','n','t','g','g','g','g','g','g','g','g','g','t'}, |
||
640 | {'t','g','g','g','g','g','t','n','n','t','g','g','g','g','g','g','g','g','g','t'}, |
||
641 | {'t','g','g','g','g','g','t','n','n','n','t','g','g','g','g','g','g','g','g','t'}, |
||
642 | {'t','g','g','g','g','g','t','n','n','n','t','g','g','g','g','g','g','g','g','t'}, |
||
643 | {'t','g','g','g','g','g','g','t','n','t','t','g','g','g','g','g','g','g','g','t'}, |
||
644 | {'t','g','g','g','g','g','g','t','t','g','g','g','g','g','g','g','g','g','g','t'}, |
||
645 | {'t','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','t'}, |
||
646 | {'t','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','t'}, |
||
647 | {'t','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','t'}, |
||
648 | {'t','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','t'}, |
||
649 | {'t','t','t','t','t','t','t','t','t','t','t','t','t','t','t','t','t','t','t','t'}}; |
||
650 | for (int tyy=0;tyy<20;tyy++){ |
||
651 | for (int txx=0;txx<20;txx++){ |
||
652 | |||
653 | if (tmparea[txx][tyy]=='k'){ |
||
654 | kosilkax=tyy; |
||
655 | kosilkay=txx; |
||
656 | } |
||
657 | |||
658 | gamearea[txx][tyy]=tmparea[tyy][txx]; |
||
659 | } |
||
660 | } |
||
661 | } |
||
662 | |||
663 | if (levnum==6){ |
||
664 | static char tmparea[20][20]={{'s','s','s','s','s','s','s','s','s','s','s','s','s','s','s','s','s','s','s','s'}, |
||
665 | {'s','k','t','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','s'}, |
||
666 | {'s','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','s'}, |
||
667 | {'s','g','g','s','s','s','s','s','s','s','s','s','s','s','s','s','s','g','g','s'}, |
||
668 | {'s','g','g','g','g','g','g','g','g','g','g','g','g','g','t','t','s','g','g','s'}, |
||
669 | {'s','g','g','s','g','g','g','g','g','g','g','g','g','g','t','t','s','g','g','s'}, |
||
670 | {'s','g','g','s','g','g','g','g','g','g','g','g','g','g','t','t','s','g','g','s'}, |
||
671 | {'s','g','g','s','g','g','g','g','g','t','t','g','g','g','g','g','s','g','g','s'}, |
||
672 | {'s','g','g','s','g','g','g','g','g','t','t','t','g','g','g','g','s','g','g','s'}, |
||
673 | {'s','g','g','s','g','g','g','t','t','t','t','t','t','g','g','g','s','g','g','s'}, |
||
674 | {'s','g','g','s','g','g','g','t','t','t','t','t','t','g','g','g','s','g','g','s'}, |
||
675 | {'s','g','g','s','g','g','g','g','g','t','t','g','g','g','g','g','s','g','g','s'}, |
||
676 | {'s','g','g','s','g','g','g','g','g','t','t','g','g','g','g','g','s','g','g','s'}, |
||
677 | {'s','g','g','s','g','g','g','g','g','g','g','g','g','g','g','g','s','g','g','s'}, |
||
678 | {'s','g','g','s','g','g','g','g','g','g','g','g','g','g','g','g','s','g','g','s'}, |
||
679 | {'s','g','g','s','g','g','g','g','g','g','g','g','g','g','g','g','s','g','g','s'}, |
||
680 | {'s','g','g','s','s','s','s','s','s','s','s','s','s','s','s','s','s','g','g','s'}, |
||
681 | {'s','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','s'}, |
||
682 | {'s','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','s'}, |
||
683 | {'s','s','s','s','s','s','s','s','s','s','s','s','s','s','s','s','s','s','s','s'}}; |
||
684 | for (int tyy=0;tyy<20;tyy++){ |
||
685 | for (int txx=0;txx<20;txx++){ |
||
686 | |||
687 | if (tmparea[txx][tyy]=='k'){ |
||
688 | kosilkax=tyy; |
||
689 | kosilkay=txx; |
||
690 | } |
||
691 | |||
692 | gamearea[txx][tyy]=tmparea[tyy][txx]; |
||
693 | } |
||
694 | } |
||
695 | } |
||
696 | |||
697 | |||
698 | if (levnum==7){ |
||
699 | static char tmparea[20][20]={{'s','s','s','s','s','s','s','s','s','s','s','s','s','s','s','s','s','s','s','s'}, |
||
700 | {'s','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','s','t','t','s'}, |
||
701 | {'s','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','s','t','t','s'}, |
||
702 | {'s','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','s','t','t','s'}, |
||
703 | {'s','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','s','t','t','s'}, |
||
704 | {'s','g','g','g','g','g','t','t','t','t','t','t','g','g','g','g','s','t','t','s'}, |
||
705 | {'s','g','g','g','g','g','t','k','g','g','g','t','g','g','g','g','s','t','t','s'}, |
||
706 | {'s','g','g','g','g','g','t','g','g','g','g','t','g','g','g','g','s','t','t','s'}, |
||
707 | {'s','g','g','g','g','g','t','g','g','g','g','t','g','g','g','g','s','t','t','s'}, |
||
708 | {'s','g','g','g','g','g','t','g','g','g','g','t','g','g','g','g','s','s','s','s'}, |
||
709 | {'s','g','g','g','g','g','t','g','g','g','g','t','g','g','g','g','g','g','g','s'}, |
||
710 | {'s','g','g','g','g','g','t','t','t','t','g','t','g','g','g','g','g','g','g','s'}, |
||
711 | {'s','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','s'}, |
||
712 | {'s','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','s'}, |
||
713 | {'s','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','s'}, |
||
714 | {'s','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','s'}, |
||
715 | {'s','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','s'}, |
||
716 | {'s','g','g','g','g','g','g','g','g','t','g','g','t','g','g','g','g','g','g','s'}, |
||
717 | {'s','g','g','g','g','g','g','g','g','t','g','g','t','g','g','g','g','g','g','s'}, |
||
718 | {'s','s','s','s','s','s','s','s','s','s','s','s','s','s','s','s','s','s','s','s'}}; |
||
719 | for (int tyy=0;tyy<20;tyy++){ |
||
720 | for (int txx=0;txx<20;txx++){ |
||
721 | |||
722 | if (tmparea[txx][tyy]=='k'){ |
||
723 | kosilkax=tyy; |
||
724 | kosilkay=txx; |
||
725 | } |
||
726 | |||
727 | gamearea[txx][tyy]=tmparea[tyy][txx]; |
||
728 | } |
||
729 | } |
||
730 | } |
||
731 | } |
||
732 | else |
||
733 | { |
||
7332 | leency | 734 | //External levels |
968 | leency | 735 | kosilkadirection=1; |
736 | |||
737 | int currentrow=0; |
||
738 | int currentcol=0; |
||
739 | |||
740 | for (int tmpcntr=0;tmpcntr<400;tmpcntr++){ |
||
741 | |||
742 | currentcol=(int)(tmpcntr/20); |
||
743 | currentrow=tmpcntr-(((int)(tmpcntr/20))*20); |
||
744 | switch(externallevels[tmpcntr+(400*(levnum-1))]){ |
||
745 | |||
746 | case 0: |
||
747 | gamearea[currentrow][currentcol]='n'; |
||
748 | break; |
||
749 | case 1: |
||
750 | gamearea[currentrow][currentcol]='g'; |
||
751 | break; |
||
752 | case 2: |
||
753 | gamearea[currentrow][currentcol]='k'; |
||
754 | kosilkax=currentrow; |
||
755 | kosilkay=currentcol; |
||
756 | break; |
||
757 | case 3: |
||
758 | gamearea[currentrow][currentcol]='s'; |
||
759 | break; |
||
760 | case 4: |
||
761 | gamearea[currentrow][currentcol]='t'; |
||
762 | break; |
||
763 | |||
764 | } |
||
765 | } |
||
766 | |||
767 | |||
768 | } |
||
769 | |||
770 | draw_window(); |
||
771 | |||
772 | } |
||
773 | |||
774 | int grassLeft(){ |
||
775 | int leftgrass=0; |
||
776 | for (int chky=0;chky<20;chky++){ |
||
777 | for (int chkx=0;chkx<20;chkx++){ |
||
778 | if (gamearea[chkx][chky]=='g') { |
||
779 | leftgrass++; |
||
780 | } |
||
781 | } |
||
782 | } |
||
783 | return leftgrass; |
||
784 | } |
||
785 | |||
7332 | leency | 786 | //Change level or show win message |
968 | leency | 787 | void updateStatus(){ |
788 | |||
789 | if (grassLeft()==0) { |
||
790 | if (level==levelcount){ |
||
791 | gamestarted=false; |
||
792 | status=2; |
||
793 | draw_window(); |
||
794 | } else { |
||
795 | gamestarted=false; |
||
796 | interlevelpause(); |
||
797 | level++; |
||
798 | initializeLevel(level); |
||
799 | gamestarted=true; |
||
800 | } |
||
801 | } |
||
802 | |||
803 | } |
||
804 | |||
805 | |||
806 | void load_external_levels(){ |
||
807 | |||
808 | CKosFile lev(getLevelsPathName()); |
||
809 | |||
3132 | leency | 810 | level_read_result=lev.Read (external_levels_count,1); |
968 | leency | 811 | |
3132 | leency | 812 | if (level_read_result == 1) |
813 | external_levels_available=true; |
||
814 | else |
||
815 | external_levels_available=false; |
||
968 | leency | 816 | |
3132 | leency | 817 | if (external_levels_count[0]==0) |
968 | leency | 818 | external_levels_available=false; |
3132 | leency | 819 | else |
820 | { |
||
821 | externallevels = new Byte[400*external_levels_count[0]]; |
||
822 | lev.Read (externallevels,400*external_levels_count[0]); |
||
823 | } |
||
968 | leency | 824 | } |
825 | |||
826 | void app_halt(){ |
||
827 | |||
828 | delete apppath; |
||
829 | delete levpath; |
||
830 | if (external_levels_available==true) {delete externallevels;} |
||
831 | kos_ExitApp(); |
||
832 | } |
||
833 | |||
3132 | leency | 834 | |
835 | |||
968 | leency | 836 | void kos_Main(){ |
837 | |||
838 | load_external_levels(); |
||
839 | |||
3132 | leency | 840 | decode_graphics(576*0 + kosilka_gfx,kosilka_d); |
841 | decode_graphics(576*1 + kosilka_gfx,kosilka_u); |
||
842 | decode_graphics(576*2 + kosilka_gfx,kosilka_l); |
||
843 | decode_graphics(576*3 + kosilka_gfx,kosilka_r); |
||
844 | decode_graphics(576*4 + kosilka_gfx,skos); |
||
845 | decode_graphics(576*5 + kosilka_gfx,stone); |
||
846 | decode_graphics(576*6 + kosilka_gfx,tree); |
||
847 | decode_graphics(576*7 + kosilka_gfx,grass); |
||
968 | leency | 848 | |
849 | for (;;){ |
||
850 | |||
851 | switch (kos_WaitForEvent()){ |
||
852 | case 1: |
||
853 | w_redraw=true; |
||
854 | draw_window(); |
||
855 | break; |
||
856 | case 2: |
||
857 | Byte keyCode; |
||
858 | kos_GetKey(keyCode); |
||
859 | if (status==1){ |
||
860 | if (gamestarted==true){ |
||
861 | switch (keyCode){ |
||
862 | case 177: |
||
863 | if (kosilkay<19){ |
||
864 | if (gamearea[kosilkax][kosilkay+1]=='g'){ |
||
865 | gamearea[kosilkax][kosilkay]='n'; |
||
866 | gamearea[kosilkax][kosilkay+1]='k'; |
||
867 | |||
868 | if (drawanimation==true) {animate(kosilkax,kosilkay,1);} |
||
869 | |||
870 | |||
871 | lastkosilkadirection=kosilkadirection; |
||
872 | laststep=1; |
||
873 | |||
874 | kosilkay++; |
||
875 | kosilkadirection=1; |
||
876 | draw_element(kosilkax,kosilkay); |
||
877 | draw_element(kosilkax,kosilkay-1); |
||
878 | display_grass_left(); |
||
879 | updateStatus(); |
||
880 | } |
||
881 | } |
||
882 | break; |
||
883 | case 178: |
||
884 | if (kosilkay>0){ |
||
885 | if (gamearea[kosilkax][kosilkay-1]=='g'){ |
||
886 | gamearea[kosilkax][kosilkay]='n'; |
||
887 | gamearea[kosilkax][kosilkay-1]='k'; |
||
888 | |||
889 | if (drawanimation==true) {animate(kosilkax,kosilkay,2);} |
||
890 | |||
891 | lastkosilkadirection=kosilkadirection; |
||
892 | laststep=2; |
||
893 | |||
894 | kosilkay--; |
||
895 | kosilkadirection=2; |
||
896 | |||
897 | draw_element(kosilkax,kosilkay); |
||
898 | draw_element(kosilkax,kosilkay+1); |
||
899 | display_grass_left(); |
||
900 | updateStatus(); |
||
901 | } |
||
902 | } |
||
903 | break; |
||
904 | |||
905 | case 179: |
||
906 | if (kosilkax<19){ |
||
907 | if (gamearea[kosilkax+1][kosilkay]=='g'){ |
||
908 | gamearea[kosilkax][kosilkay]='n'; |
||
909 | gamearea[kosilkax+1][kosilkay]='k'; |
||
910 | |||
911 | if (drawanimation==true) {animate(kosilkax,kosilkay,3);} |
||
912 | |||
913 | |||
914 | lastkosilkadirection=kosilkadirection; |
||
915 | laststep=3; |
||
916 | |||
917 | kosilkax++; |
||
918 | kosilkadirection=4; |
||
919 | |||
920 | draw_element(kosilkax,kosilkay); |
||
921 | draw_element(kosilkax-1,kosilkay); |
||
922 | display_grass_left(); |
||
923 | updateStatus(); |
||
924 | } |
||
925 | } |
||
926 | break; |
||
927 | |||
928 | case 176: |
||
929 | if (kosilkax>0){ |
||
930 | if (gamearea[kosilkax-1][kosilkay]=='g'){ |
||
931 | gamearea[kosilkax][kosilkay]='n'; |
||
932 | gamearea[kosilkax-1][kosilkay]='k'; |
||
933 | |||
934 | if (drawanimation==true) {animate(kosilkax,kosilkay,4);} |
||
935 | |||
936 | lastkosilkadirection=kosilkadirection; |
||
937 | laststep=4; |
||
938 | |||
939 | kosilkax--; |
||
940 | kosilkadirection=3; |
||
941 | |||
942 | draw_element(kosilkax,kosilkay); |
||
943 | draw_element(kosilkax+1,kosilkay); |
||
944 | display_grass_left(); |
||
945 | updateStatus(); |
||
946 | } |
||
947 | } |
||
948 | break; |
||
949 | |||
950 | case 27: |
||
951 | if (lives>0){ |
||
952 | lives--; |
||
953 | initializeLevel(level); |
||
954 | |||
955 | } else { |
||
956 | gamestarted=false; |
||
957 | status=3; |
||
958 | draw_window(); |
||
959 | } |
||
960 | break; |
||
961 | |||
962 | case 8: |
||
963 | if (laststep!=0){ |
||
964 | kosilkadirection=lastkosilkadirection; |
||
965 | if (laststep==1){ |
||
966 | gamearea[kosilkax][kosilkay]='g'; |
||
967 | gamearea[kosilkax][kosilkay-1]='k'; |
||
968 | draw_element(kosilkax,kosilkay); |
||
969 | draw_element(kosilkax,kosilkay-1); |
||
970 | kosilkay--; |
||
971 | } |
||
972 | if (laststep==2){ |
||
973 | gamearea[kosilkax][kosilkay]='g'; |
||
974 | gamearea[kosilkax][kosilkay+1]='k'; |
||
975 | draw_element(kosilkax,kosilkay); |
||
976 | draw_element(kosilkax,kosilkay+1); |
||
977 | kosilkay++; |
||
978 | } |
||
979 | |||
980 | if (laststep==3){ |
||
981 | gamearea[kosilkax][kosilkay]='g'; |
||
982 | gamearea[kosilkax-1][kosilkay]='k'; |
||
983 | draw_element(kosilkax,kosilkay); |
||
984 | draw_element(kosilkax-1,kosilkay); |
||
985 | kosilkax--; |
||
986 | } |
||
987 | |||
988 | if (laststep==4){ |
||
989 | gamearea[kosilkax][kosilkay]='g'; |
||
990 | gamearea[kosilkax+1][kosilkay]='k'; |
||
991 | draw_element(kosilkax,kosilkay); |
||
992 | draw_element(kosilkax+1,kosilkay); |
||
993 | kosilkax++; |
||
994 | } |
||
995 | |||
996 | |||
997 | laststep=0; |
||
998 | } |
||
999 | break; |
||
1000 | |||
1001 | } |
||
1002 | |||
1003 | } |
||
1004 | } |
||
1005 | if (status==0){ |
||
1006 | if (keyCode==13){ //enter |
||
1007 | if (external_levels_available==true){ |
||
1008 | status=4; |
||
1009 | draw_window(); |
||
1010 | } |
||
1011 | else |
||
1012 | { |
||
1013 | status=1; |
||
1014 | initializeLevel(1); |
||
1015 | gamestarted=true; |
||
1016 | } |
||
1017 | |||
1018 | } |
||
1019 | |||
1020 | if (keyCode==103){ |
||
1021 | if (drawgraphics==true){ |
||
1022 | drawgraphics=false; |
||
1023 | } else { |
||
1024 | drawgraphics=true; |
||
1025 | } |
||
1026 | |||
1027 | if (drawgraphics==true){ |
||
1028 | kos_PutImage((RGB*)kosilka_d,24,24,305,150); |
||
1029 | } |
||
1030 | else |
||
1031 | { |
||
1032 | kos_DrawBar(305,150,24,24,0x00AAAA); |
||
1033 | } |
||
1034 | } |
||
1035 | |||
1036 | if (keyCode==97){ |
||
1037 | if (drawanimation==true){ |
||
1038 | drawanimation=false; |
||
1039 | } else { |
||
1040 | drawanimation=true; |
||
1041 | } |
||
1042 | |||
1043 | if (drawanimation==true){ |
||
1044 | kos_DrawBar(335,150,24,24,0x00AA00); |
||
1045 | } |
||
1046 | else |
||
1047 | { |
||
1048 | kos_DrawBar(335,150,24,24,0xAA0000); |
||
1049 | } |
||
1050 | } |
||
1051 | if (keyCode==104){ |
||
1052 | status=-1; |
||
1053 | draw_window(); |
||
1054 | } |
||
1055 | |||
1056 | if (keyCode==27){ |
||
1057 | app_halt(); |
||
1058 | } |
||
1059 | |||
1060 | } |
||
1061 | |||
1062 | if (status==4){ |
||
1063 | if (keyCode==49){ //1 |
||
1064 | external_levels=false; |
||
1065 | status=1; |
||
1066 | initializeLevel(1); |
||
1067 | gamestarted=true; |
||
1068 | |||
1069 | } |
||
1070 | |||
1071 | if (keyCode==50){ //2 |
||
1072 | external_levels=true; |
||
1073 | levelcount=external_levels_count[0]; |
||
1074 | status=1; |
||
1075 | initializeLevel(1); |
||
1076 | gamestarted=true; |
||
1077 | |||
1078 | } |
||
1079 | } |
||
1080 | |||
1081 | if (status==2){ |
||
1082 | if (keyCode==113){ |
||
1083 | lives=2; |
||
1084 | status=0; |
||
1085 | level=1; |
||
1086 | draw_window(); |
||
1087 | gamestarted=true; |
||
1088 | } |
||
1089 | } |
||
1090 | |||
1091 | if (status==3){ |
||
1092 | if (keyCode==113){ |
||
1093 | lives=2; |
||
1094 | status=0; |
||
1095 | level=1; |
||
1096 | draw_window(); |
||
1097 | gamestarted=true; |
||
1098 | |||
1099 | } |
||
1100 | if (keyCode==114){ |
||
1101 | lives=2; |
||
1102 | status=1; |
||
1103 | level=1; |
||
1104 | initializeLevel(1); |
||
1105 | gamestarted=true; |
||
1106 | } |
||
1107 | |||
1108 | } |
||
1109 | |||
1110 | if (status==-1){ |
||
1111 | if (keyCode==8){ |
||
1112 | status=0; |
||
1113 | draw_window(); |
||
1114 | } |
||
1115 | } |
||
1116 | |||
1117 | break; |
||
1118 | case 3: |
||
1119 | |||
1120 | app_halt(); |
||
1121 | break; |
||
1122 | } |
||
1123 | } |
||
1124 | }19){ |