Rev 6976 | Rev 6995 | 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 | |||
18 | #include "..\lib\obj\libio_lib.h" |
||
19 | #include "..\lib\obj\libimg_lib.h" |
||
20 | #include "..\lib\patterns\libimg_load_skin.h" |
||
21 | |||
22 | libimg_image menu; |
||
23 | libimg_image road; |
||
6976 | leency | 24 | libimg_image objects; |
6970 | leency | 25 | |
26 | int lives=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 | |||
6984 | leency | 46 | char *MENU_LIST[]={ |
6970 | leency | 47 | "New game", |
48 | "Control keys", |
||
49 | "About", |
||
50 | "Exit", |
||
51 | 0}; |
||
52 | |||
53 | |||
6976 | leency | 54 | void DrawObstacle(signed int x, y) { |
6970 | leency | 55 | int don_offset_y; |
56 | int image_h; |
||
57 | |||
6976 | leency | 58 | if (y >= 0) { |
59 | image_h = don_h; |
||
60 | don_offset_y = don_image_y; |
||
6970 | leency | 61 | } |
62 | else { |
||
6976 | leency | 63 | image_h = don_h + y; |
64 | don_offset_y = don_image_y - y; |
||
6970 | leency | 65 | y = 0; |
66 | } |
||
6984 | leency | 67 | if (y>=don_step_y) DrawBar(x, y-don_step_y, don_w, don_step_y, COLOR_ROAD); //Fill donkey old parts |
68 | if (image_h>0) DrawLibImage(objects.image, x, y, don_w, image_h, 0, don_offset_y); |
||
6970 | leency | 69 | } |
6984 | leency | 70 | void DrawBus(dword x, y) { DrawLibImage(objects.image, x, y, bus_w, bus_h, 0, 444); } |
71 | void DrawBoom(dword x, y) { DrawLibImage(objects.image, x, y, 78, 66, 0, 536); } |
||
72 | void DrawHighway() { DrawLibImage(road.image, 0,0, WIN_X, WIN_Y, 0, 0); } |
||
73 | void DrawMenuBackground() { DrawLibImage(menu.image, 0, 0, WIN_X, WIN_Y, 0, 0); } |
||
6970 | leency | 74 | |
75 | void main() |
||
76 | { |
||
77 | randomize(); |
||
6984 | leency | 78 | StartNewGame(); |
6970 | leency | 79 | |
80 | load_dll(libio, #libio_init,1); |
||
81 | load_dll(libimg, #libimg_init,1); |
||
6984 | leency | 82 | Libimg_LoadImage(#menu, "menu.png"); |
83 | Libimg_LoadImage(#road, "road.png"); |
||
84 | Libimg_LoadImage(#objects, "objects.png"); |
||
6970 | leency | 85 | |
86 | loop() |
||
87 | { |
||
88 | WaitEventTimeout(1); |
||
89 | |||
90 | switch(EAX & 0xFF) |
||
91 | { |
||
92 | case evKey: |
||
93 | GetKeys(); |
||
94 | if (key_scancode == SCAN_CODE_ESC) |
||
95 | { |
||
96 | if (screen_type==SCR_GAME) SetScreen(SCR_MENU_MAIN); |
||
97 | else if (screen_type==SCR_MENU_MAIN) ExitProcess(); |
||
98 | } |
||
99 | if (key_scancode == SCAN_CODE_DOWN) && (screen_type==SCR_MENU_MAIN) |
||
100 | { |
||
101 | if (active_menu_item<>3) active_menu_item++; ELSE active_menu_item=0; |
||
102 | DrawMenuList(); |
||
103 | } |
||
104 | if (key_scancode == SCAN_CODE_UP) && (screen_type==SCR_MENU_MAIN) |
||
105 | { |
||
106 | if (active_menu_item<>0) active_menu_item--; ELSE active_menu_item=3; |
||
107 | DrawMenuList(); |
||
108 | } |
||
109 | if (key_scancode == SCAN_CODE_ENTER) && (screen_type==SCR_MENU_MAIN) |
||
110 | { |
||
111 | if (active_menu_item==0) |
||
112 | { |
||
6984 | leency | 113 | StartNewGame(); |
6970 | leency | 114 | SetScreen(SCR_GAME); |
115 | } |
||
116 | if (active_menu_item==1) notify("'The Bus\nControl keys:\nLeft, Right, Space\nPress P key for pause'tI"); |
||
6984 | leency | 117 | if (active_menu_item==2) notify("'The Bus\nVersion v0.9\nAuthor: Leency\nMenu image from Freepik.com'tI"); |
6970 | leency | 118 | if (active_menu_item==3) ExitProcess(); |
119 | } |
||
120 | if (key_scancode == SCAN_CODE_SPACE) && (screen_type==SCR_GAME) |
||
121 | { |
||
6984 | leency | 122 | DrawBar(bus_x*80+200, bus_y, bus_w, bus_h+1, COLOR_ROAD); |
6970 | leency | 123 | if (bus_x==1) bus_x=0; else bus_x=1; |
124 | } |
||
125 | if (key_scancode == SCAN_CODE_LEFT) && (screen_type==SCR_GAME) |
||
126 | { |
||
127 | if (bus_x==0) break; |
||
6984 | leency | 128 | DrawBar(bus_x*80+200, bus_y, bus_w, bus_h+1, COLOR_ROAD); |
6970 | leency | 129 | bus_x=0; |
130 | } |
||
131 | if (key_scancode == SCAN_CODE_RIGHT) && (screen_type==SCR_GAME) |
||
132 | { |
||
133 | if (bus_x==1) break; |
||
6984 | leency | 134 | DrawBar(bus_x*80+200, bus_y, bus_w, bus_h+1, COLOR_ROAD); |
6970 | leency | 135 | bus_x=1; |
136 | } |
||
137 | if (key_scancode == SCAN_CODE_KEY_P) |
||
138 | { |
||
139 | if (screen_type==SCR_MENU_MAIN) break; |
||
140 | else if (screen_type==SCR_GAME) SetScreen(SCR_PAUSE); |
||
141 | else if (screen_type==SCR_PAUSE) SetScreen(SCR_GAME); |
||
142 | } |
||
143 | break; |
||
144 | |||
145 | case evReDraw: |
||
6984 | leency | 146 | DefineAndDrawWindow(250,150,WIN_X-1,WIN_Y-1,0x01,0,"The Bus",0); //0x74 is also possible if you fix bottom border |
6970 | leency | 147 | DrawScreen(); |
148 | break; |
||
149 | |||
150 | case evButton: |
||
151 | ExitProcess(); |
||
152 | break; |
||
153 | |||
154 | default: |
||
6984 | leency | 155 | if (screen_type==SCR_GAME) |
156 | { |
||
157 | if ((don_x == bus_x)&&(don_y + don_h > bus_y )&&(don_y < bus_y + don_h )) { |
||
158 | lives--; |
||
159 | DrawBus(bus_x*80+200,bus_y); |
||
160 | DrawBoom(bus_x*80+180,302); |
||
161 | pause(150); |
||
162 | GetNewObstacle(RAND); |
||
163 | DrawScreen(); |
||
164 | } |
||
165 | |||
166 | if (lives==0) { |
||
167 | DrawGameOverMessage(); |
||
168 | break; |
||
169 | } |
||
170 | |||
171 | don_y += don_step_y; |
||
172 | |||
173 | if (don_y - don_step_y >= WIN_Y) |
||
174 | { |
||
175 | GetNewObstacle(RAND); |
||
176 | score++; |
||
177 | bus_y -= don_step_y+1; |
||
178 | DrawBar(bus_x*80+200, bus_y+bus_h, bus_w, don_step_y, COLOR_ROAD); |
||
179 | WriteScore(); |
||
180 | } |
||
181 | |||
182 | if (score) && (score % 15 == 0) |
||
183 | { |
||
184 | score++; |
||
185 | NewLevel(); |
||
186 | DrawScreen(); |
||
187 | don_step_y++; |
||
188 | } |
||
189 | |||
190 | DrawRoad(); |
||
191 | } |
||
6970 | leency | 192 | } |
193 | } |
||
194 | } |
||
195 | |||
6984 | leency | 196 | void NewLevel() |
197 | { |
||
198 | level++; |
||
199 | bus_y = bus_y_default; |
||
200 | } |
||
201 | |||
202 | void StartNewGame() |
||
203 | { |
||
204 | lives=3; |
||
205 | level=0; |
||
206 | score=0; |
||
207 | bus_y = bus_y_default; |
||
208 | don_step_y = don_step_y_default; |
||
209 | GetNewObstacle(RAND); |
||
210 | } |
||
211 | |||
6970 | leency | 212 | void WriteScore() { |
6984 | leency | 213 | DrawLibImage(road.image, 20, 166, 120, 24, 20, 164); |
214 | WriteText(20, 140, 0x81, 0xFFFFFF, "Score"); |
||
215 | WriteText(20, 166, 0x81, 0xFFFFFF, itoa(score)); |
||
6970 | leency | 216 | } |
217 | |||
218 | void SetScreen(dword _screen_type) { |
||
219 | screen_type = _screen_type; |
||
220 | DrawScreen(); |
||
221 | } |
||
222 | |||
223 | void DrawScreen() |
||
224 | { |
||
6976 | leency | 225 | int i; |
6970 | leency | 226 | if (screen_type==SCR_MENU_MAIN) |
227 | { |
||
228 | DrawMenuBackground(); |
||
6984 | leency | 229 | WriteTextB(20, 20, 0x82, 0xE8783F, "THE BUS"); |
6970 | leency | 230 | DrawMenuList(); |
231 | } |
||
232 | if (screen_type==SCR_GAME) || (screen_type==SCR_PAUSE) |
||
233 | { |
||
234 | DrawHighway(); |
||
6984 | leency | 235 | WriteText(20, 20, 0x81, 0xFFFFFF, "Lives"); |
236 | WriteText(20, 46, 0x81, 0xFFFFFF, itoa(lives)); |
||
237 | WriteText(20, 80, 0x81, 0xFFFFFF, "Level"); |
||
238 | WriteText(20, 106, 0x81, 0xFFFFFF, itoa(level)); |
||
6970 | leency | 239 | WriteScore(); |
240 | DrawRoad(); |
||
241 | if (screen_type==SCR_PAUSE) { |
||
6984 | leency | 242 | DrawBar(0,0,140,60,0xFF0000); |
243 | WriteText(10,14,0x83,0xFFFfff,"PAUSE"); |
||
6976 | leency | 244 | } |
6970 | leency | 245 | } |
246 | } |
||
247 | |||
248 | |||
249 | void DrawMenuList() |
||
250 | { |
||
251 | int j; |
||
252 | for (j=0; j<4; j++) DrawMenuItem(j, j); |
||
253 | } |
||
254 | |||
255 | void DrawMenuItem(int item_n, text_n) |
||
256 | { |
||
257 | dword color; |
||
258 | if (active_menu_item==item_n) color = 0xFF0000; else color = 0xFFffff; |
||
6984 | leency | 259 | WriteText(20+2, item_n*56+116+2, 0x81, 0xAAAaaa, MENU_LIST[text_n]); |
260 | WriteText(20, item_n*56+116, 0x81, color, MENU_LIST[text_n]); |
||
6970 | leency | 261 | } |
262 | |||
263 | |||
264 | void DrawGameOverMessage() |
||
265 | { |
||
6984 | leency | 266 | DrawBar(0, 0, WIN_X, WIN_Y, 0xF3E1BD); |
267 | WriteText(40, 40, 0x81, 0xA48C74, "GAME OVER"); |
||
268 | WriteText(40, 75, 0x81, 0xA48C74, "FINAL SCORE"); |
||
269 | WriteTextB(40, 140, 0x85, 0xA48C74, itoa(score)); |
||
6970 | leency | 270 | pause(350); |
271 | active_menu_item=0; |
||
6976 | leency | 272 | SetScreen(SCR_MENU_MAIN); |
6970 | leency | 273 | } |
274 | |||
6976 | leency | 275 | void GetNewObstacle(int N) |
276 | { |
||
277 | int i; |
||
278 | don_x = random(2); |
||
6984 | leency | 279 | if (N==RAND) don_type = random(7); else don_type = N; |
6976 | leency | 280 | don_h = don_h_mas[don_type]; |
6984 | leency | 281 | don_y = -don_h; |
6976 | leency | 282 | don_image_y = 0; |
6984 | leency | 283 | for (i = 0; i < don_type; i++) don_image_y += don_h_mas[i]+2; //calculate image y offset for current obstacle |
6976 | leency | 284 | } |
285 | |||
6970 | leency | 286 | #define LINE_LENGTH 10 |
6984 | leency | 287 | int line_y=0; |
288 | void DrawLineSeparator() |
||
6970 | leency | 289 | { |
6984 | leency | 290 | int y; |
291 | if (screen_type == SCR_GAME) line_y += don_step_y; |
||
6970 | leency | 292 | //the beginning of the white dashed line between two roadways |
293 | if (line_y>=20) { |
||
294 | line_y=0; |
||
295 | } |
||
296 | else |
||
297 | { |
||
6984 | leency | 298 | DrawBar(258, 0, 2, line_y, COLOR_ROAD); |
299 | DrawBar(258, 0, 2, line_y-LINE_LENGTH, 0xDDE9F2); |
||
6970 | leency | 300 | } |
6976 | leency | 301 | for (y=0; y |
6970 | leency | 302 | { |
6984 | leency | 303 | DrawBar(258, line_y+y, 2, LINE_LENGTH, 0xDDE9F2); |
304 | DrawBar(258, line_y+y+LINE_LENGTH, 2, LINE_LENGTH, COLOR_ROAD); |
||
6970 | leency | 305 | } |
306 | } |
||
307 | |||
6984 | leency | 308 | void DrawRoad() |
309 | { |
||
310 | DrawLineSeparator(); |
||
311 | DrawObstacle(don_w+10*don_x+186,don_y); |
||
312 | DrawBus(bus_x*80+200,bus_y); |
||
313 | } |
||
6970 | leency | 314 | |
315 | |||
316 | |||
317 | |||
6984 | leency | 318 | |
6970 | leency | 319 | stop:>4;>>>> |