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