Rev 7995 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
6970 | leency | 1 | /* |
2 | THE BUS |
||
3 | Copyright (C) 2008, 2012, 2017 Leency |
||
4 | Menu image from Freepik.com |
||
5 | D O N K E Y |
||
6 | Copyright (C) 2008 O.Bogomaz |
||
7 | */ |
||
8 | |||
6984 | leency | 9 | #ifndef AUTOBUILD |
10 | #include "lang.h--" |
||
11 | #endif |
||
12 | |||
6970 | leency | 13 | #define MEMSIZE 1024 * 60; |
14 | |||
15 | #include "..\lib\kolibri.h" |
||
16 | #include "..\lib\random.h" |
||
17 | |||
7049 | leency | 18 | #include "..\lib\obj\libimg.h" |
6970 | leency | 19 | |
20 | libimg_image menu; |
||
21 | libimg_image road; |
||
6976 | leency | 22 | libimg_image objects; |
6970 | leency | 23 | |
6995 | leency | 24 | int frame_timeout = 1; |
25 | |||
6997 | leency | 26 | int lifes=0, level=0, score=0; |
6984 | leency | 27 | int don_x, don_y, don_h, don_w=68, don_type, don_image_y, don_step_y, don_step_y_default=3; |
28 | int don_h_mas[8] = { 36,72,36,74,24,64,48,74 }; |
||
29 | int bus_x, bus_w=42, bus_y, bus_h=88, bus_y_default=290; |
||
6970 | leency | 30 | |
31 | #define SCR_MENU_MAIN 1 |
||
32 | #define SCR_GAME 2 |
||
33 | #define SCR_PAUSE 3 |
||
34 | |||
6976 | leency | 35 | #define RAND -1 |
6970 | leency | 36 | |
6984 | leency | 37 | #define WIN_X 516 |
38 | #define WIN_Y 382 |
||
6970 | leency | 39 | |
40 | int screen_type=SCR_MENU_MAIN; |
||
41 | |||
42 | #define COLOR_ROAD 0x6D879B; |
||
43 | |||
44 | int active_menu_item=0; |
||
45 | |||
6995 | leency | 46 | #ifdef LANG_RUS |
47 | #define THE_BUS_TEXT "Маршрутка" |
||
48 | #define CONTROLS_TEXT "'Маршрутка |
||
49 | Управление: |
||
50 | Влево/Вправо или Пробел |
||
51 | Клавиша P ставит на паузу'tI" |
||
52 | #define ABOUT_TEXT "'Маршрутка |
||
6996 | leency | 53 | Версия v1.01 |
6995 | leency | 54 | |
6997 | leency | 55 | Сыграйте за дерзкого маршрутчика, |
6995 | leency | 56 | который несется домой после смены. |
7578 | leency | 57 | Он уже накатил рюмаху с мужиками |
6995 | leency | 58 | и теперь его ничто не остановит! |
59 | |||
60 | Автор Leency |
||
61 | Картинка в меню Freepik.com'tI" |
||
62 | #define PAUSE_TEXT "ПАУЗА" |
||
63 | #define GAME_OVER_TEXT "Игра окончена" |
||
64 | #define FINAL_SCORE_TEXT "Финальный счет" |
||
6997 | leency | 65 | #define LIFES_TEXT "Жизни" |
6995 | leency | 66 | #define LEVEL_TEXT "Уровень" |
67 | #define SCORE_TEXT "Счет" |
||
6984 | leency | 68 | char *MENU_LIST[]={ |
6995 | leency | 69 | "Новая игра", |
70 | "Управление", |
||
71 | "Об игре", |
||
72 | "Выход", |
||
73 | 0}; |
||
74 | #else |
||
75 | #define THE_BUS_TEXT "THE BUS" |
||
76 | #define CONTROLS_TEXT "'The Bus |
||
77 | Control keys: |
||
78 | Left, Right, Space |
||
79 | Press P key for pause'tI" |
||
80 | #define ABOUT_TEXT "'The Bus |
||
6996 | leency | 81 | Version v1.01 |
6995 | leency | 82 | Author: Leency |
83 | Menu image from Freepik.com'tI" |
||
84 | #define PAUSE_TEXT "PAUSE" |
||
85 | #define GAME_OVER_TEXT "GAME OVER" |
||
86 | #define FINAL_SCORE_TEXT "Final Score" |
||
6997 | leency | 87 | #define LIFES_TEXT "Lifes" |
6995 | leency | 88 | #define LEVEL_TEXT "Level" |
89 | #define SCORE_TEXT "Score" |
||
90 | char *MENU_LIST[]={ |
||
6970 | leency | 91 | "New game", |
92 | "Control keys", |
||
93 | "About", |
||
94 | "Exit", |
||
95 | 0}; |
||
6995 | leency | 96 | #endif |
6970 | leency | 97 | |
98 | |||
6976 | leency | 99 | void DrawObstacle(signed int x, y) { |
6970 | leency | 100 | int don_offset_y; |
101 | int image_h; |
||
102 | |||
6976 | leency | 103 | if (y >= 0) { |
104 | image_h = don_h; |
||
105 | don_offset_y = don_image_y; |
||
6970 | leency | 106 | } |
107 | else { |
||
6976 | leency | 108 | image_h = don_h + y; |
109 | don_offset_y = don_image_y - y; |
||
6970 | leency | 110 | y = 0; |
111 | } |
||
6995 | leency | 112 | DrawBar(x, y-don_step_y, don_w, don_step_y, COLOR_ROAD); |
113 | if (y>0) && (y |
||
7995 | leency | 114 | if (image_h>0) objects.draw(x, y, don_w, image_h, 0, don_offset_y); |
6970 | leency | 115 | } |
7995 | leency | 116 | void DrawBus(dword x, y) { objects.draw(x, y, bus_w, bus_h, 0, 444); } |
117 | void DrawBoom(dword x, y) { objects.draw(x, y, 78, 66, 0, 536); } |
||
118 | void DrawHighway() { road.draw(0,0, WIN_X, WIN_Y, 0, 0); } |
||
119 | void DrawMenuBackground() { menu.draw(0, 0, WIN_X, WIN_Y, 0, 0); } |
||
6970 | leency | 120 | |
121 | void main() |
||
122 | { |
||
123 | randomize(); |
||
6984 | leency | 124 | StartNewGame(); |
6970 | leency | 125 | |
126 | load_dll(libimg, #libimg_init,1); |
||
7977 | leency | 127 | menu.load(abspath("menu.png")); |
128 | road.load(abspath("road.png")); |
||
129 | objects.load(abspath("objects.png")); |
||
6970 | leency | 130 | |
7985 | leency | 131 | loop() switch(@WaitEventTimeout(frame_timeout)) |
6970 | leency | 132 | { |
7985 | leency | 133 | case evKey: |
134 | GetKeys(); |
||
135 | if (key_scancode == SCAN_CODE_ESC) |
||
136 | { |
||
137 | if (screen_type==SCR_GAME) SetScreen(SCR_MENU_MAIN); |
||
138 | else if (screen_type==SCR_MENU_MAIN) ExitProcess(); |
||
139 | } |
||
140 | if (key_scancode == SCAN_CODE_DOWN) && (screen_type==SCR_MENU_MAIN) |
||
141 | { |
||
142 | if (active_menu_item<>3) active_menu_item++; ELSE active_menu_item=0; |
||
143 | DrawMenuList(); |
||
144 | } |
||
145 | if (key_scancode == SCAN_CODE_UP) && (screen_type==SCR_MENU_MAIN) |
||
146 | { |
||
147 | if (active_menu_item<>0) active_menu_item--; ELSE active_menu_item=3; |
||
148 | DrawMenuList(); |
||
149 | } |
||
150 | if (key_scancode == SCAN_CODE_ENTER) && (screen_type==SCR_MENU_MAIN) |
||
151 | { |
||
152 | if (active_menu_item==0) |
||
6970 | leency | 153 | { |
7985 | leency | 154 | StartNewGame(); |
155 | SetScreen(SCR_GAME); |
||
6970 | leency | 156 | } |
7985 | leency | 157 | if (active_menu_item==1) notify(CONTROLS_TEXT); |
158 | if (active_menu_item==2) notify(ABOUT_TEXT); |
||
159 | if (active_menu_item==3) ExitProcess(); |
||
160 | } |
||
161 | if (key_scancode == SCAN_CODE_SPACE) && (screen_type==SCR_GAME) |
||
162 | { |
||
163 | DrawBar(bus_x*80+200, bus_y, bus_w, bus_h+1, COLOR_ROAD); |
||
164 | if (bus_x==1) bus_x=0; else bus_x=1; |
||
165 | } |
||
166 | if (key_scancode == SCAN_CODE_LEFT) && (screen_type==SCR_GAME) |
||
167 | { |
||
168 | if (bus_x==0) break; |
||
169 | DrawBar(bus_x*80+200, bus_y, bus_w, bus_h+1, COLOR_ROAD); |
||
170 | bus_x=0; |
||
171 | } |
||
172 | if (key_scancode == SCAN_CODE_RIGHT) && (screen_type==SCR_GAME) |
||
173 | { |
||
174 | if (bus_x==1) break; |
||
175 | DrawBar(bus_x*80+200, bus_y, bus_w, bus_h+1, COLOR_ROAD); |
||
176 | bus_x=1; |
||
177 | } |
||
178 | if (key_scancode == SCAN_CODE_KEY_P) |
||
179 | { |
||
180 | if (screen_type==SCR_MENU_MAIN) break; |
||
181 | else if (screen_type==SCR_GAME) SetScreen(SCR_PAUSE); |
||
182 | else if (screen_type==SCR_PAUSE) SetScreen(SCR_GAME); |
||
183 | } |
||
184 | break; |
||
185 | |||
186 | case evReDraw: |
||
187 | DefineAndDrawWindow(250,150,WIN_X-1,WIN_Y-1,0x01,0,THE_BUS_TEXT,0); //0x74 is also possible if you fix bottom border |
||
188 | DrawScreen(); |
||
189 | break; |
||
190 | |||
191 | case evButton: |
||
192 | ExitProcess(); |
||
193 | break; |
||
194 | |||
195 | default: |
||
196 | if (screen_type==SCR_GAME) |
||
197 | { |
||
198 | if ((don_x == bus_x)&&(don_y + don_h > bus_y )&&(don_y < bus_y + don_h )) { |
||
199 | lifes--; |
||
200 | DrawBus(bus_x*80+200,bus_y); |
||
201 | DrawBoom(bus_x*80+180,bus_y+10); |
||
202 | pause(150); |
||
203 | GetNewObstacle(RAND); |
||
204 | DrawScreen(); |
||
6970 | leency | 205 | } |
7985 | leency | 206 | |
207 | if (lifes==0) { |
||
208 | DrawGameOverMessage(); |
||
209 | break; |
||
6970 | leency | 210 | } |
7985 | leency | 211 | |
212 | don_y += don_step_y; |
||
213 | |||
214 | if (don_y - don_step_y >= WIN_Y) |
||
6970 | leency | 215 | { |
7985 | leency | 216 | GetNewObstacle(RAND); |
217 | score++; |
||
218 | bus_y -= don_step_y+1; |
||
219 | DrawBar(bus_x*80+200, bus_y+bus_h, bus_w, don_step_y+1, COLOR_ROAD); |
||
220 | WriteScore(); |
||
6970 | leency | 221 | } |
7985 | leency | 222 | |
223 | if (score) && (score % 15 == 0) |
||
6970 | leency | 224 | { |
7985 | leency | 225 | score++; |
226 | NewLevel(); |
||
227 | DrawScreen(); |
||
228 | don_step_y++; |
||
6970 | leency | 229 | } |
6984 | leency | 230 | |
7985 | leency | 231 | DrawRoad(); |
232 | } |
||
6970 | leency | 233 | } |
234 | } |
||
235 | |||
6984 | leency | 236 | void NewLevel() |
237 | { |
||
238 | level++; |
||
239 | bus_y = bus_y_default; |
||
240 | } |
||
241 | |||
242 | void StartNewGame() |
||
243 | { |
||
6997 | leency | 244 | lifes=3; |
6984 | leency | 245 | level=0; |
246 | score=0; |
||
247 | bus_y = bus_y_default; |
||
248 | don_step_y = don_step_y_default; |
||
249 | GetNewObstacle(RAND); |
||
250 | } |
||
251 | |||
6970 | leency | 252 | void WriteScore() { |
7995 | leency | 253 | road.draw(20, 166, 120, 24, 20, 164); |
6995 | leency | 254 | WriteText(20, 140, 0x81, 0xFFFFFF, SCORE_TEXT); |
6984 | leency | 255 | WriteText(20, 166, 0x81, 0xFFFFFF, itoa(score)); |
6970 | leency | 256 | } |
257 | |||
258 | void SetScreen(dword _screen_type) { |
||
259 | screen_type = _screen_type; |
||
260 | DrawScreen(); |
||
261 | } |
||
262 | |||
263 | void DrawScreen() |
||
264 | { |
||
6976 | leency | 265 | int i; |
6970 | leency | 266 | if (screen_type==SCR_MENU_MAIN) |
267 | { |
||
268 | DrawMenuBackground(); |
||
6995 | leency | 269 | WriteTextB(20, 20, 0x83, 0xE8783F, THE_BUS_TEXT); |
6970 | leency | 270 | DrawMenuList(); |
271 | } |
||
272 | if (screen_type==SCR_GAME) || (screen_type==SCR_PAUSE) |
||
273 | { |
||
274 | DrawHighway(); |
||
6997 | leency | 275 | WriteText(20, 20, 0x81, 0xFFFFFF, LIFES_TEXT); |
276 | WriteText(20, 46, 0x81, 0xFFFFFF, itoa(lifes)); |
||
6995 | leency | 277 | WriteText(20, 80, 0x81, 0xFFFFFF, LEVEL_TEXT); |
6984 | leency | 278 | WriteText(20, 106, 0x81, 0xFFFFFF, itoa(level)); |
6970 | leency | 279 | WriteScore(); |
280 | DrawRoad(); |
||
281 | if (screen_type==SCR_PAUSE) { |
||
6984 | leency | 282 | DrawBar(0,0,140,60,0xFF0000); |
6995 | leency | 283 | WriteText(10,14,0x83,0xFFFfff,PAUSE_TEXT); |
6976 | leency | 284 | } |
6970 | leency | 285 | } |
286 | } |
||
287 | |||
288 | |||
289 | void DrawMenuList() |
||
290 | { |
||
291 | int j; |
||
292 | for (j=0; j<4; j++) DrawMenuItem(j, j); |
||
293 | } |
||
294 | |||
295 | void DrawMenuItem(int item_n, text_n) |
||
296 | { |
||
297 | dword color; |
||
298 | if (active_menu_item==item_n) color = 0xFF0000; else color = 0xFFffff; |
||
6984 | leency | 299 | WriteText(20+2, item_n*56+116+2, 0x81, 0xAAAaaa, MENU_LIST[text_n]); |
300 | WriteText(20, item_n*56+116, 0x81, color, MENU_LIST[text_n]); |
||
6970 | leency | 301 | } |
302 | |||
303 | void DrawGameOverMessage() |
||
304 | { |
||
6984 | leency | 305 | DrawBar(0, 0, WIN_X, WIN_Y, 0xF3E1BD); |
6995 | leency | 306 | WriteText(40, 40, 0x81, 0xA48C74, GAME_OVER_TEXT); |
307 | WriteText(40, 75, 0x81, 0xA48C74, FINAL_SCORE_TEXT); |
||
6984 | leency | 308 | WriteTextB(40, 140, 0x85, 0xA48C74, itoa(score)); |
6970 | leency | 309 | pause(350); |
310 | active_menu_item=0; |
||
6976 | leency | 311 | SetScreen(SCR_MENU_MAIN); |
6970 | leency | 312 | } |
313 | |||
6976 | leency | 314 | void GetNewObstacle(int N) |
315 | { |
||
316 | int i; |
||
317 | don_x = random(2); |
||
6984 | leency | 318 | if (N==RAND) don_type = random(7); else don_type = N; |
6976 | leency | 319 | don_h = don_h_mas[don_type]; |
6984 | leency | 320 | don_y = -don_h; |
6976 | leency | 321 | don_image_y = 0; |
6984 | leency | 322 | for (i = 0; i < don_type; i++) don_image_y += don_h_mas[i]+2; //calculate image y offset for current obstacle |
6976 | leency | 323 | } |
324 | |||
6970 | leency | 325 | #define LINE_LENGTH 10 |
6984 | leency | 326 | int line_y=0; |
327 | void DrawLineSeparator() |
||
6970 | leency | 328 | { |
6984 | leency | 329 | int y; |
330 | if (screen_type == SCR_GAME) line_y += don_step_y; |
||
6970 | leency | 331 | //the beginning of the white dashed line between two roadways |
332 | if (line_y>=20) { |
||
333 | line_y=0; |
||
334 | } |
||
335 | else |
||
336 | { |
||
6984 | leency | 337 | DrawBar(258, 0, 2, line_y, COLOR_ROAD); |
338 | DrawBar(258, 0, 2, line_y-LINE_LENGTH, 0xDDE9F2); |
||
6970 | leency | 339 | } |
6976 | leency | 340 | for (y=0; y |
6970 | leency | 341 | { |
6984 | leency | 342 | DrawBar(258, line_y+y, 2, LINE_LENGTH, 0xDDE9F2); |
343 | DrawBar(258, line_y+y+LINE_LENGTH, 2, LINE_LENGTH, COLOR_ROAD); |
||
6970 | leency | 344 | } |
345 | } |
||
346 | |||
6984 | leency | 347 | void DrawRoad() |
348 | { |
||
349 | DrawLineSeparator(); |
||
350 | DrawObstacle(don_w+10*don_x+186,don_y); |
||
351 | DrawBus(bus_x*80+200,bus_y); |
||
352 | } |
||
6970 | leency | 353 | |
354 | |||
355 | |||
356 | |||
6984 | leency | 357 | |
6970 | leency | 358 | stop:>4;>>>> |