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