Rev 1811 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1811 | Rev 2829 | ||
---|---|---|---|
1 | #include "system/kolibri.h" |
1 | #include "system/kolibri.h" |
2 | #include "system/stdlib.h" |
2 | #include "system/stdlib.h" |
3 | #include "system/string.h" |
3 | #include "system/string.h" |
4 | 4 | ||
5 | #include "system/gblib.h" |
5 | #include "system/gblib.h" |
6 | 6 | ||
7 | #include "car_01.h" |
7 | #include "car_01.h" |
8 | #include "car_02.h" |
8 | #include "car_02.h" |
9 | #include "donkey_01.h" |
9 | #include "donkey_01.h" |
10 | #include "donkey_02.h" |
10 | #include "donkey_02.h" |
11 | #include "az.h" |
11 | #include "az.h" |
12 | 12 | ||
13 | char STR_DONKEY[] = {"D O N K E Y 0.8"}; |
13 | char STR_DONKEY[] = {"D O N K E Y 0.8"}; |
14 | 14 | ||
15 | int start, paintbg, pause; |
15 | int start, paintbg, pause; |
16 | int dox, doy; |
16 | int dox, doy; |
17 | int drx, dry; |
17 | int drx, dry; |
18 | 18 | ||
19 | int drn, don; |
19 | int drn, don; |
20 | 20 | ||
21 | int speed; |
21 | int speed; |
22 | 22 | ||
23 | char snd_ok[]={0x08, 0x89, 0x0f, 0}; |
23 | char snd_ok[]={0x08, 0x89, 0x0f, 0}; |
24 | char snd_game_over[]={0x08, 0xa9, 0x0f, 0x09, 0x99, 0x0f, 0x11, 0x59, 0x0f, 0}; |
24 | char snd_game_over[]={0x08, 0xa9, 0x0f, 0x09, 0x99, 0x0f, 0x11, 0x59, 0x0f, 0}; |
25 | 25 | ||
26 | 26 | ||
27 | GB_BMP screen, font, car01, car02, donkey01, donkey02, az; |
27 | GB_BMP screen, font, car01, car02, donkey01, donkey02, az; |
28 | 28 | ||
29 | 29 | ||
30 | void az_putc(unsigned char c, int x, int y) |
30 | void az_putc(unsigned char c, int x, int y) |
31 | { |
31 | { |
32 | gb_image_set_t(&screen, x, y, &az, (c-'!')*11, 0, 11, 16, 0); |
32 | gb_image_set_t(&screen, x, y, &az, (c-'!')*11, 0, 11, 16, 0); |
33 | } |
33 | } |
34 | 34 | ||
35 | 35 | ||
36 | 36 | ||
37 | void az_puts(unsigned char *s, int x, int y) |
37 | void az_puts(unsigned char *s, int x, int y) |
38 | { |
38 | { |
39 | unsigned i; |
39 | unsigned i; |
40 | i = 0; |
40 | i = 0; |
41 | while (*(s+i)) |
41 | while (*(s+i)) |
42 | { |
42 | { |
43 | az_putc(*(s+i), x+i*11, y); |
43 | az_putc(*(s+i), x+i*11, y); |
44 | i++; |
44 | i++; |
45 | } |
45 | } |
46 | 46 | ||
47 | } |
47 | } |
48 | 48 | ||
49 | 49 | ||
50 | 50 | ||
51 | void game_start() |
51 | void game_start() |
52 | { |
52 | { |
53 | drx = -1; |
53 | drx = -1; |
54 | dry = 0; |
54 | dry = 0; |
55 | doy = random(40)+130; |
55 | doy = random(40)+130; |
56 | 56 | ||
57 | dox = random(1); |
57 | dox = random(1); |
58 | if (0 == dox) |
58 | if (0 == dox) |
59 | dox--; |
59 | dox--; |
60 | 60 | ||
61 | drn = don = 0; |
61 | drn = don = 0; |
62 | paintbg = 1; |
62 | paintbg = 1; |
63 | 63 | ||
64 | speed = 0; |
64 | speed = 0; |
65 | 65 | ||
66 | kol_sleep(30); |
66 | kol_sleep(30); |
67 | } |
67 | } |
68 | 68 | ||
69 | 69 | ||
70 | void screen_back() |
70 | void screen_back() |
71 | { |
71 | { |
72 | 72 | ||
73 | gb_bar(&screen, 0, 0, 320, 200, 0x888888); |
73 | gb_bar(&screen, 0, 0, 320, 200, 0x888888); |
74 | 74 | ||
75 | gb_bar(&screen, 6, 6, 97-6, 195-6, 0x488888); |
75 | gb_bar(&screen, 6, 6, 97-6, 195-6, 0x488888); |
76 | gb_bar(&screen, 183, 6, 305-183, 195-6, 0x488888); |
76 | gb_bar(&screen, 183, 6, 305-183, 195-6, 0x488888); |
77 | 77 | ||
78 | az_puts("Donkey", 6, 30); |
78 | az_puts("Donkey", 6, 30); |
79 | az_puts("Driver", 189, 30); |
79 | az_puts("Driver", 189, 30); |
80 | 80 | ||
81 | az_putc (don+'0', 5, 48); |
81 | az_putc (don+'0', 5, 48); |
82 | az_putc (drn/10+'0', 189, 48); |
82 | az_putc (drn/10+'0', 189, 48); |
83 | 83 | ||
84 | az_puts("Keys:", 189, 95); |
84 | az_puts("Keys:", 189, 95); |
85 | az_puts("Space Bar", 189, 116); |
85 | az_puts("Space Bar", 189, 116); |
86 | az_puts("Enter", 189, 132); |
86 | az_puts("Enter", 189, 132); |
87 | az_puts("Esc", 189, 148); |
87 | az_puts("Esc", 189, 148); |
88 | 88 | ||
89 | 89 | ||
90 | gb_line(&screen, 100, 0, 100, 199, 0xffffff); |
90 | gb_line(&screen, 100, 0, 100, 199, 0xffffff); |
91 | gb_line(&screen, 180, 0, 180, 199, 0xffffff); |
91 | gb_line(&screen, 180, 0, 180, 199, 0xffffff); |
92 | 92 | ||
93 | paintbg = 0; |
93 | paintbg = 0; |
94 | } |
94 | } |
95 | 95 | ||
96 | 96 | ||
97 | 97 | ||
98 | void screen_draw() |
98 | void screen_draw() |
99 | { |
99 | { |
100 | 100 | ||
101 | int y; |
101 | int y; |
102 | 102 | ||
103 | if (-1 == pause) |
103 | if (-1 == pause) |
104 | { |
104 | { |
105 | screen_back(); |
105 | screen_back(); |
106 | 106 | ||
107 | gb_bar(&screen, 4, 20, 255, 60, 0xee0000); |
107 | gb_bar(&screen, 4, 20, 255, 60, 0xee0000); |
108 | az_puts ("P A U S E", 5, 30); |
108 | az_puts ("P A U S E", 5, 30); |
109 | az_puts ("Press Enter to continue", 5, 60); |
109 | az_puts ("Press Enter to continue", 5, 60); |
110 | 110 | ||
111 | kol_screen_wait_rr(); |
111 | kol_screen_wait_rr(); |
112 | kol_paint_image( 0, 0, 320, 200, screen.bmp); |
112 | kol_paint_image( 0, 0, 320, 200, screen.bmp); |
113 | 113 | ||
114 | paintbg = 1; |
114 | paintbg = 1; |
115 | return; |
115 | return; |
116 | } |
116 | } |
117 | 117 | ||
118 | if (don > 9) |
118 | if (don > 9) |
119 | { |
119 | { |
120 | gb_bar(&screen, 0, 0, 320, 200, 0x880000); |
120 | gb_bar(&screen, 0, 0, 320, 200, 0x880000); |
121 | az_puts ("G A M E O V E R", 5, 30); |
121 | az_puts ("G A M E O V E R", 5, 30); |
122 | 122 | ||
123 | kol_screen_wait_rr(); |
123 | kol_screen_wait_rr(); |
124 | kol_paint_image( 0, 0, 320, 200, screen.bmp); |
124 | kol_paint_image( 0, 0, 320, 200, screen.bmp); |
125 | 125 | ||
126 | kol_sleep(150); |
126 | kol_sleep(150); |
127 | game_start(); |
127 | game_start(); |
128 | start = 1; |
128 | start = 1; |
129 | } |
129 | } |
130 | 130 | ||
131 | if (drn > 99) |
131 | if (drn > 99) |
132 | { |
132 | { |
133 | gb_bar(&screen, 0, 0, 320, 200, 0x88); |
133 | gb_bar(&screen, 0, 0, 320, 200, 0x88); |
134 | az_puts ("CONGRATULATIONS !!!", 5, 30); |
134 | az_puts ("CONGRATULATIONS !!!", 5, 30); |
135 | 135 | ||
136 | kol_screen_wait_rr(); |
136 | kol_screen_wait_rr(); |
137 | kol_paint_image( 0, 0, 320, 200, screen.bmp); |
137 | kol_paint_image( 0, 0, 320, 200, screen.bmp); |
138 | 138 | ||
139 | kol_sleep(150); |
139 | kol_sleep(150); |
140 | game_start(); |
140 | game_start(); |
141 | start = 1; |
141 | start = 1; |
142 | } |
142 | } |
143 | 143 | ||
144 | if (drn > 9) |
144 | if (drn > 9) |
145 | speed = 1; |
145 | speed = 1; |
146 | 146 | ||
147 | if (drn > 84) |
147 | if (drn > 84) |
148 | speed = 2; |
148 | speed = 2; |
149 | 149 | ||
150 | 150 | ||
151 | if (start) |
151 | if (start) |
152 | { |
152 | { |
153 | if (!paintbg) |
153 | if (!paintbg) |
154 | return; |
154 | return; |
155 | 155 | ||
156 | gb_bar(&screen, 0, 0, 320, 200, 0x55); |
156 | gb_bar(&screen, 0, 0, 320, 200, 0x55); |
157 | 157 | ||
158 | az_puts ( STR_DONKEY, 5, 30); |
158 | az_puts ( STR_DONKEY, 5, 30); |
159 | az_puts ("remake for KolibriOS", 5, 78); |
159 | az_puts ("remake for KolibriOS", 5, 78); |
160 | az_puts ("by Albom", 5, 78+16); |
160 | az_puts ("by Albom", 5, 78+16); |
161 | 161 | ||
162 | az_puts ("Press Space Bar", 5, 140); |
162 | az_puts ("Press Space Bar", 5, 140); |
163 | az_puts ("to continue", 5, 156); |
163 | az_puts ("to continue", 5, 156); |
164 | 164 | ||
165 | 165 | ||
166 | kol_screen_wait_rr(); |
166 | kol_screen_wait_rr(); |
167 | kol_paint_image( 0, 0, 320, 200, screen.bmp); |
167 | kol_paint_image( 0, 0, 320, 200, screen.bmp); |
168 | paintbg = 0; |
168 | paintbg = 0; |
169 | return; |
169 | return; |
170 | } |
170 | } |
171 | 171 | ||
172 | if (paintbg) |
172 | if (paintbg) |
173 | screen_back(); |
173 | screen_back(); |
174 | else |
174 | else |
175 | gb_bar(&screen, 102, 0, 180-102, 200, 0x888888); |
175 | gb_bar(&screen, 102, 0, 180-102, 200, 0x888888); |
176 | 176 | ||
177 | for (y=10; y<180; y+=20) |
177 | for (y=10; y<180; y+=20) |
178 | gb_line(&screen, 140, y-10*(doy%2), 140, y+10-10*(doy%2), 0xffffff); |
178 | gb_line(&screen, 140, y-10*(doy%2), 140, y+10-10*(doy%2), 0xffffff); |
179 | 179 | ||
180 | doy-=5; |
180 | doy-=5; |
181 | if (doy < -50) |
181 | if (doy < -50) |
182 | { |
182 | { |
183 | 183 | ||
184 | dox = random(1); |
184 | dox = random(1); |
185 | if (0 == dox) |
185 | if (0 == dox) |
186 | dox--; |
186 | dox--; |
187 | 187 | ||
188 | doy = random(40)+130; |
188 | doy = random(40)+130; |
189 | dry += 10; |
189 | dry += 10; |
190 | drn++; |
190 | drn++; |
191 | if (0 == drn%10) |
191 | if (0 == drn%10) |
192 | dry = 0; |
192 | dry = 0; |
193 | paintbg = 1; |
193 | paintbg = 1; |
194 | } |
194 | } |
195 | 195 | ||
196 | if ((drx == dox)&&(dry > doy-15)&&(dry < doy+15)) |
196 | if ((drx == dox)&&(dry > doy-15)&&(dry < doy+15)) |
197 | { |
197 | { |
198 | kol_sound_speaker(snd_game_over); |
198 | kol_sound_speaker(snd_game_over); |
199 | don++; |
199 | don++; |
200 | dry = 0; |
200 | dry = 0; |
201 | drn /= 10; |
201 | drn /= 10; |
202 | drn *= 10; |
202 | drn *= 10; |
203 | for (y = 0; y<2; y++) |
203 | for (y = 0; y<2; y++) |
204 | { |
204 | { |
205 | kol_sleep(8); |
205 | kol_sleep(8); |
206 | screen_back(); |
206 | screen_back(); |
207 | az_puts("BOOM!", 6, 120); |
207 | az_puts("BOOM!", 6, 120); |
208 | 208 | ||
209 | gb_image_set_t(&screen, 140-13-(y+1)*20, 120-dry+(y+1)*20, &car01, 0, 0, 13, 34, 0x888888); |
209 | gb_image_set_t(&screen, 140-13-(y+1)*20, 120-dry+(y+1)*20, &car01, 0, 0, 13, 34, 0x888888); |
210 | gb_image_set_t(&screen, 120+(y+3)*20, 120-dry+(y+1)*20, &car02, 0, 0, 13, 34, 0x888888); |
210 | gb_image_set_t(&screen, 120+(y+3)*20, 120-dry+(y+1)*20, &car02, 0, 0, 13, 34, 0x888888); |
211 | 211 | ||
212 | gb_image_set_t(&screen, 140-17-(y+1)*20, 120-(y+1)*20, &donkey01, 0, 0, 17, 17, 0x888888); |
212 | gb_image_set_t(&screen, 140-17-(y+1)*20, 120-(y+1)*20, &donkey01, 0, 0, 17, 17, 0x888888); |
213 | gb_image_set_t(&screen, 140+(y+3)*20, 120-(y+1)*20, &donkey02, 0, 0, 13, 17, 0x888888); |
213 | gb_image_set_t(&screen, 140+(y+3)*20, 120-(y+1)*20, &donkey02, 0, 0, 13, 17, 0x888888); |
214 | 214 | ||
215 | kol_screen_wait_rr(); |
215 | kol_screen_wait_rr(); |
216 | kol_paint_image(0, 0, 320, 200, screen.bmp); |
216 | kol_paint_image(0, 0, 320, 200, screen.bmp); |
217 | } |
217 | } |
218 | 218 | ||
219 | dox = random(1); |
219 | dox = random(1); |
220 | if (0 == dox) |
220 | if (0 == dox) |
221 | dox--; |
221 | dox--; |
222 | 222 | ||
223 | doy = random(40)+130; |
223 | doy = random(40)+130; |
224 | paintbg = 1; |
224 | paintbg = 1; |
225 | } |
225 | } |
226 | 226 | ||
227 | gb_image_set_t(&screen, 140-13-drx*20, 130-dry, &car01, 0, 0, 13, 34, 0x888888); |
227 | gb_image_set_t(&screen, 140-13-drx*20, 130-dry, &car01, 0, 0, 13, 34, 0x888888); |
228 | gb_image_set_t(&screen, 140-drx*20, 130-dry, &car02, 0, 0, 13, 34, 0x888888); |
228 | gb_image_set_t(&screen, 140-drx*20, 130-dry, &car02, 0, 0, 13, 34, 0x888888); |
229 | 229 | ||
230 | gb_image_set_t(&screen, 140-17-dox*20, 130-doy, &donkey01, 0, 0, 17, 17, 0x888888); |
230 | gb_image_set_t(&screen, 140-17-dox*20, 130-doy, &donkey01, 0, 0, 17, 17, 0x888888); |
231 | gb_image_set_t(&screen, 140-dox*20, 130-doy, &donkey02, 0, 0, 13, 17, 0x888888); |
231 | gb_image_set_t(&screen, 140-dox*20, 130-doy, &donkey02, 0, 0, 13, 17, 0x888888); |
232 | 232 | ||
233 | kol_screen_wait_rr(); |
233 | kol_screen_wait_rr(); |
234 | kol_paint_image(0, 0, 320, 200, screen.bmp); |
234 | kol_paint_image(0, 0, 320, 200, screen.bmp); |
235 | 235 | ||
236 | } |
236 | } |
237 | 237 | ||
238 | 238 | ||
239 | 239 | ||
240 | void wnd_draw() |
240 | void wnd_draw() |
241 | { |
241 | { |
242 | kol_paint_start(); |
242 | kol_paint_start(); |
243 | kol_wnd_define(280, 200, 328, 204+kol_skin_height(), 0x34888888); |
243 | kol_wnd_define(280, 200, 328, 204+kol_skin_height(), 0x34888888, 0x34888888, STR_DONKEY); |
244 | kol_wnd_caption(STR_DONKEY); |
244 | screen_draw(); |
245 | screen_draw(); |
- | |
246 | kol_paint_end(); |
245 | kol_paint_end(); |
247 | } |
246 | } |
248 | 247 | ||
249 | 248 | ||
250 | 249 | ||
251 | 250 | ||
252 | void kol_main() |
251 | void kol_main() |
253 | { |
252 | { |
254 | 253 | ||
255 | unsigned event; |
254 | unsigned event; |
256 | unsigned key; |
255 | unsigned key; |
257 | 256 | ||
258 | srand(kol_system_time_get()<<8); |
257 | srand(kol_system_time_get()<<8); |
259 | start = 1; |
258 | start = 1; |
260 | paintbg = 1; |
259 | paintbg = 1; |
261 | 260 | ||
262 | pause = 1; |
261 | pause = 1; |
263 | 262 | ||
264 | speed = 0; |
263 | speed = 0; |
265 | 264 | ||
266 | screen.bmp = malloc(320*200*3); |
265 | screen.bmp = malloc(320*200*3); |
267 | screen.w = 320; |
266 | screen.w = 320; |
268 | screen.h = 200; |
267 | screen.h = 200; |
269 | 268 | ||
270 | car01.bmp = CAR_01; |
269 | car01.bmp = CAR_01; |
271 | car01.w = 13; |
270 | car01.w = 13; |
272 | car01.h = 34; |
271 | car01.h = 34; |
273 | 272 | ||
274 | car02.bmp = CAR_02; |
273 | car02.bmp = CAR_02; |
275 | car02.w = 13; |
274 | car02.w = 13; |
276 | car02.h = 34; |
275 | car02.h = 34; |
277 | 276 | ||
278 | donkey01.bmp = DONKEY_01; |
277 | donkey01.bmp = DONKEY_01; |
279 | donkey01.w = 17; |
278 | donkey01.w = 17; |
280 | donkey01.h = 17; |
279 | donkey01.h = 17; |
281 | 280 | ||
282 | donkey02.bmp = DONKEY_02; |
281 | donkey02.bmp = DONKEY_02; |
283 | donkey02.w = 13; |
282 | donkey02.w = 13; |
284 | donkey02.h = 17; |
283 | donkey02.h = 17; |
285 | 284 | ||
286 | az.bmp = AZ; |
285 | az.bmp = AZ; |
287 | az.w = 1012; |
286 | az.w = 1012; |
288 | az.h = 16; |
287 | az.h = 16; |
289 | 288 | ||
290 | 289 | ||
291 | wnd_draw(); |
290 | wnd_draw(); |
292 | 291 | ||
293 | for (;;) |
292 | for (;;) |
294 | { |
293 | { |
295 | 294 | ||
296 | kol_sleep(6-speed); |
295 | kol_sleep(6-speed); |
297 | screen_draw(); |
296 | screen_draw(); |
298 | event = kol_event_check(); |
297 | event = kol_event_check(); |
299 | 298 | ||
300 | switch (event) |
299 | switch (event) |
301 | { |
300 | { |
302 | case 1: |
301 | case 1: |
303 | paintbg = 1; |
302 | paintbg = 1; |
304 | wnd_draw(); |
303 | wnd_draw(); |
305 | break; |
304 | break; |
306 | 305 | ||
307 | case 2: |
306 | case 2: |
308 | key = (kol_key_get() & 0xff00)>>8; |
307 | key = (kol_key_get() & 0xff00)>>8; |
309 | if (start && (32==key)) |
308 | if (start && (32==key)) |
310 | { |
309 | { |
311 | start = 0; |
310 | start = 0; |
312 | game_start(); |
311 | game_start(); |
313 | screen_draw(); |
312 | screen_draw(); |
314 | break; |
313 | break; |
315 | } |
314 | } |
316 | 315 | ||
317 | if (27 == key) |
316 | if (27 == key) |
318 | { |
317 | { |
319 | if (-1 == pause) |
318 | if (-1 == pause) |
320 | break; |
319 | break; |
321 | start = 1; |
320 | start = 1; |
322 | paintbg = 1; |
321 | paintbg = 1; |
323 | break; |
322 | break; |
324 | } |
323 | } |
325 | 324 | ||
326 | if (32 == key) |
325 | if (32 == key) |
327 | { |
326 | { |
328 | if (-1 == pause) |
327 | if (-1 == pause) |
329 | break; |
328 | break; |
330 | 329 | ||
331 | kol_sound_speaker(snd_ok); |
330 | kol_sound_speaker(snd_ok); |
332 | 331 | ||
333 | drx *= -1; |
332 | drx *= -1; |
334 | screen_draw(); |
333 | screen_draw(); |
335 | } |
334 | } |
336 | 335 | ||
337 | if ((!start) && (13 == key)) |
336 | if ((!start) && (13 == key)) |
338 | { |
337 | { |
339 | pause *= -1; |
338 | pause *= -1; |
340 | screen_draw(); |
339 | screen_draw(); |
341 | } |
340 | } |
342 | 341 | ||
343 | 342 | ||
344 | break; |
343 | break; |
345 | 344 | ||
346 | case 3: |
345 | case 3: |
347 | if ( 1 == (kol_btn_get() & 0xff00)>>8 ) |
346 | if ( 1 == (kol_btn_get() & 0xff00)>>8 ) |
348 | kol_exit(); |
347 | kol_exit(); |
349 | break; |
348 | break; |
350 | 349 | ||
351 | }; |
350 | }; |
352 | } |
351 | } |
353 | 352 | ||
354 | }8); |
353 | }8); |
355 | start><8); |
354 | start><8); |
356 | start>2;>>>180;> |
355 | start>2;>>>180;> |