Rev 6976 | Rev 6995 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 6976 | Rev 6984 | ||
---|---|---|---|
Line 4... | Line 4... | ||
4 | Menu image from Freepik.com |
4 | Menu image from Freepik.com |
5 | D O N K E Y |
5 | D O N K E Y |
6 | Copyright (C) 2008 O.Bogomaz |
6 | Copyright (C) 2008 O.Bogomaz |
7 | */ |
7 | */ |
Line -... | Line 8... | ||
- | 8 | ||
- | 9 | #ifndef AUTOBUILD |
|
- | 10 | #include "lang.h--" |
|
- | 11 | #endif |
|
8 | 12 | ||
Line 9... | Line 13... | ||
9 | #define MEMSIZE 1024 * 60; |
13 | #define MEMSIZE 1024 * 60; |
10 | 14 | ||
Line 11... | Line 15... | ||
11 | #include "..\lib\kolibri.h" |
15 | #include "..\lib\kolibri.h" |
12 | #include "..\lib\random.h" |
16 | #include "..\lib\random.h" |
13 | 17 | ||
Line 14... | Line -... | ||
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 |
18 | #include "..\lib\obj\libio_lib.h" |
19 | 19 | #include "..\lib\obj\libimg_lib.h" |
|
20 | #include "draw_scalled.h" |
20 | #include "..\lib\patterns\libimg_load_skin.h" |
Line 21... | Line 21... | ||
21 | 21 | ||
22 | libimg_image menu; |
22 | libimg_image menu; |
23 | libimg_image road; |
23 | libimg_image road; |
24 | libimg_image objects; |
24 | libimg_image objects; |
Line 25... | Line 25... | ||
25 | 25 | ||
26 | int lives=0, level=0, score=0; |
26 | int lives=0, level=0, score=0; |
27 | int don_x, don_y, don_h, don_w=39, don_type, don_image_y; |
27 | int don_x, don_y, don_h, don_w=68, don_type, don_image_y, don_step_y, don_step_y_default=3; |
Line 28... | Line 28... | ||
28 | int don_h_mas[8] = { 18,36,18,37,12,32,24,37 }; |
28 | int don_h_mas[8] = { 36,72,36,74,24,64,48,74 }; |
Line 29... | Line 29... | ||
29 | int bus_x, bus_w=21, bus_y=145, bus_h=44; |
29 | int bus_x, bus_w=42, bus_y, bus_h=88, bus_y_default=290; |
30 | 30 | ||
Line 31... | Line 31... | ||
31 | #define SCR_MENU_MAIN 1 |
31 | #define SCR_MENU_MAIN 1 |
Line 32... | Line 32... | ||
32 | #define SCR_GAME 2 |
32 | #define SCR_GAME 2 |
Line 33... | Line 33... | ||
33 | #define SCR_PAUSE 3 |
33 | #define SCR_PAUSE 3 |
Line 34... | Line 34... | ||
34 | 34 | ||
35 | #define RAND -1 |
35 | #define RAND -1 |
36 | 36 | ||
37 | #define WIN_X 258 |
37 | #define WIN_X 516 |
38 | #define WIN_Y 191 |
38 | #define WIN_Y 382 |
39 | 39 | ||
Line 62... | Line 62... | ||
62 | else { |
62 | else { |
63 | image_h = don_h + y; |
63 | image_h = don_h + y; |
64 | don_offset_y = don_image_y - y; |
64 | don_offset_y = don_image_y - y; |
65 | y = 0; |
65 | y = 0; |
66 | } |
66 | } |
67 | - | ||
68 | debugval("y", y); |
- | |
69 | debugval("don_h", don_h); |
- | |
70 | debugval("image_h", image_h); |
- | |
71 | debugval("don_offset_y", don_offset_y); |
67 | if (y>=don_step_y) DrawBar(x, y-don_step_y, don_w, don_step_y, COLOR_ROAD); //Fill donkey old parts |
72 | DrawScaledImage(objects.image, x, y, don_w, image_h, 0, don_offset_y); |
68 | if (image_h>0) DrawLibImage(objects.image, x, y, don_w, image_h, 0, don_offset_y); |
73 | } |
69 | } |
74 | void DrawBus(dword x, y) { DrawScaledImage(objects.image, x, y, bus_w, bus_h, 0, 222); } |
70 | void DrawBus(dword x, y) { DrawLibImage(objects.image, x, y, bus_w, bus_h, 0, 444); } |
75 | void DrawBoom(dword x, y) { DrawScaledImage(objects.image, x, y, 39, 33, 0, 268); } |
71 | void DrawBoom(dword x, y) { DrawLibImage(objects.image, x, y, 78, 66, 0, 536); } |
76 | void DrawHighway() { DrawScaledImage(road.image, 0,0, WIN_X, WIN_Y, 0, 0); } |
72 | void DrawHighway() { DrawLibImage(road.image, 0,0, WIN_X, WIN_Y, 0, 0); } |
77 | void DrawMenuBackground() { DrawScaledImage(menu.image, 0, 0, WIN_X, WIN_Y, 0, 0); } |
73 | void DrawMenuBackground() { DrawLibImage(menu.image, 0, 0, WIN_X, WIN_Y, 0, 0); } |
Line 78... | Line 74... | ||
78 | 74 | ||
79 | void main() |
75 | void main() |
80 | { |
76 | { |
81 | randomize(); |
77 | randomize(); |
Line 82... | Line 78... | ||
82 | GetNewObstacle(RAND); |
78 | StartNewGame(); |
83 | 79 | ||
84 | load_dll(libio, #libio_init,1); |
80 | load_dll(libio, #libio_init,1); |
85 | load_dll(libimg, #libimg_init,1); |
81 | load_dll(libimg, #libimg_init,1); |
86 | Libimg_LoadImage(#menu, "/sys/fonts/menu.png"); |
82 | Libimg_LoadImage(#menu, "menu.png"); |
Line 87... | Line 83... | ||
87 | Libimg_LoadImage(#road, "/sys/fonts/road.png"); |
83 | Libimg_LoadImage(#road, "road.png"); |
88 | Libimg_LoadImage(#objects, "/sys/fonts/objects.png"); |
84 | Libimg_LoadImage(#objects, "objects.png"); |
89 | 85 | ||
Line 112... | Line 108... | ||
112 | } |
108 | } |
113 | if (key_scancode == SCAN_CODE_ENTER) && (screen_type==SCR_MENU_MAIN) |
109 | if (key_scancode == SCAN_CODE_ENTER) && (screen_type==SCR_MENU_MAIN) |
114 | { |
110 | { |
115 | if (active_menu_item==0) |
111 | if (active_menu_item==0) |
116 | { |
112 | { |
117 | lives=3; |
- | |
118 | level=0; |
- | |
119 | score=0; |
113 | StartNewGame(); |
120 | SetScreen(SCR_GAME); |
114 | SetScreen(SCR_GAME); |
121 | } |
115 | } |
122 | if (active_menu_item==1) notify("'The Bus\nControl keys:\nLeft, Right, Space\nPress P key for pause'tI"); |
116 | if (active_menu_item==1) notify("'The Bus\nControl keys:\nLeft, Right, Space\nPress P key for pause'tI"); |
123 | if (active_menu_item==2) notify("'The Bus\nVersion v0.4 Alpha\n\nAuthor: Leency\nMenu image from Freepik.com'tI"); |
117 | if (active_menu_item==2) notify("'The Bus\nVersion v0.9\nAuthor: Leency\nMenu image from Freepik.com'tI"); |
124 | if (active_menu_item==3) ExitProcess(); |
118 | if (active_menu_item==3) ExitProcess(); |
125 | } |
119 | } |
126 | if (key_scancode == SCAN_CODE_SPACE) && (screen_type==SCR_GAME) |
120 | if (key_scancode == SCAN_CODE_SPACE) && (screen_type==SCR_GAME) |
127 | { |
121 | { |
128 | DrawScaledBar(bus_x*40+100, bus_y, bus_w, bus_h+1, COLOR_ROAD); |
122 | DrawBar(bus_x*80+200, bus_y, bus_w, bus_h+1, COLOR_ROAD); |
129 | if (bus_x==1) bus_x=0; else bus_x=1; |
123 | if (bus_x==1) bus_x=0; else bus_x=1; |
130 | } |
124 | } |
131 | if (key_scancode == SCAN_CODE_LEFT) && (screen_type==SCR_GAME) |
125 | if (key_scancode == SCAN_CODE_LEFT) && (screen_type==SCR_GAME) |
132 | { |
126 | { |
133 | if (bus_x==0) break; |
127 | if (bus_x==0) break; |
134 | DrawScaledBar(bus_x*40+100, bus_y, bus_w, bus_h+1, COLOR_ROAD); |
128 | DrawBar(bus_x*80+200, bus_y, bus_w, bus_h+1, COLOR_ROAD); |
135 | bus_x=0; |
129 | bus_x=0; |
136 | } |
130 | } |
137 | if (key_scancode == SCAN_CODE_RIGHT) && (screen_type==SCR_GAME) |
131 | if (key_scancode == SCAN_CODE_RIGHT) && (screen_type==SCR_GAME) |
138 | { |
132 | { |
139 | if (bus_x==1) break; |
133 | if (bus_x==1) break; |
140 | DrawScaledBar(bus_x*40+100, bus_y, bus_w, bus_h+1, COLOR_ROAD); |
134 | DrawBar(bus_x*80+200, bus_y, bus_w, bus_h+1, COLOR_ROAD); |
141 | bus_x=1; |
135 | bus_x=1; |
142 | } |
136 | } |
143 | if (key_scancode == SCAN_CODE_KEY_P) |
137 | if (key_scancode == SCAN_CODE_KEY_P) |
144 | { |
138 | { |
145 | if (screen_type==SCR_MENU_MAIN) break; |
139 | if (screen_type==SCR_MENU_MAIN) break; |
Line 147... | Line 141... | ||
147 | else if (screen_type==SCR_PAUSE) SetScreen(SCR_GAME); |
141 | else if (screen_type==SCR_PAUSE) SetScreen(SCR_GAME); |
148 | } |
142 | } |
149 | break; |
143 | break; |
Line 150... | Line 144... | ||
150 | 144 | ||
151 | case evReDraw: |
145 | case evReDraw: |
152 | DefineAndDrawWindow(250,150,WIN_X * SCALE-1+10,WIN_Y * SCALE-1+skin_height+5,0x74,0,"The Bus",0); |
146 | DefineAndDrawWindow(250,150,WIN_X-1,WIN_Y-1,0x01,0,"The Bus",0); //0x74 is also possible if you fix bottom border |
153 | DrawScreen(); |
147 | DrawScreen(); |
Line 154... | Line 148... | ||
154 | break; |
148 | break; |
155 | 149 | ||
156 | case evButton: |
150 | case evButton: |
Line 157... | Line 151... | ||
157 | ExitProcess(); |
151 | ExitProcess(); |
158 | break; |
152 | break; |
- | 153 | ||
- | 154 | default: |
|
- | 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 | } |
|
159 | 165 | ||
160 | default: |
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(); |
|
161 | if (screen_type==SCR_GAME) DrawRoad(); |
191 | } |
- | 192 | } |
|
- | 193 | } |
|
- | 194 | } |
|
- | 195 | ||
- | 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; |
|
162 | break; |
207 | bus_y = bus_y_default; |
Line 163... | Line 208... | ||
163 | } |
208 | don_step_y = don_step_y_default; |
164 | } |
209 | GetNewObstacle(RAND); |
165 | } |
210 | } |
166 | 211 | ||
167 | void WriteScore() { |
212 | void WriteScore() { |
Line 168... | Line 213... | ||
168 | DrawScaledImage(road.image, 10, 83, 60, 12, 10, 82); |
213 | DrawLibImage(road.image, 20, 166, 120, 24, 20, 164); |
169 | WriteScaledText(10, 70, 0x80, 0xFFFFFF, "Score"); |
214 | WriteText(20, 140, 0x81, 0xFFFFFF, "Score"); |
170 | WriteScaledText(10, 83, 0x80, 0xFFFFFF, itoa(score)); |
215 | WriteText(20, 166, 0x81, 0xFFFFFF, itoa(score)); |
Line 179... | Line 224... | ||
179 | { |
224 | { |
180 | int i; |
225 | int i; |
181 | if (screen_type==SCR_MENU_MAIN) |
226 | if (screen_type==SCR_MENU_MAIN) |
182 | { |
227 | { |
183 | DrawMenuBackground(); |
228 | DrawMenuBackground(); |
184 | WriteScaledText(10, 10, 0x80, 0xE8783F, "TAKE THE CHILDREN HOME"); |
229 | WriteTextB(20, 20, 0x82, 0xE8783F, "THE BUS"); |
185 | $add ebx, 2 << 16 |
- | |
186 | $int 64 |
- | |
187 | DrawMenuList(); |
230 | DrawMenuList(); |
188 | } |
231 | } |
189 | if (screen_type==SCR_GAME) || (screen_type==SCR_PAUSE) |
232 | if (screen_type==SCR_GAME) || (screen_type==SCR_PAUSE) |
190 | { |
233 | { |
191 | DrawHighway(); |
234 | DrawHighway(); |
192 | WriteScaledText(10, 10, 0x80, 0xFFFFFF, "Lives"); |
235 | WriteText(20, 20, 0x81, 0xFFFFFF, "Lives"); |
193 | WriteScaledText(10, 23, 0x80, 0xFFFFFF, itoa(lives)); |
236 | WriteText(20, 46, 0x81, 0xFFFFFF, itoa(lives)); |
194 | WriteScaledText(10, 40, 0x80, 0xFFFFFF, "Level"); |
237 | WriteText(20, 80, 0x81, 0xFFFFFF, "Level"); |
195 | WriteScaledText(10, 53, 0x80, 0xFFFFFF, itoa(level)); |
238 | WriteText(20, 106, 0x81, 0xFFFFFF, itoa(level)); |
196 | WriteScore(); |
239 | WriteScore(); |
197 | DrawRoad(); |
240 | DrawRoad(); |
198 | if (screen_type==SCR_PAUSE) { |
241 | if (screen_type==SCR_PAUSE) { |
199 | DrawScaledBar(0,0,70,30,0xFF0000); |
242 | DrawBar(0,0,140,60,0xFF0000); |
200 | WriteScaledText(5,7,0x81,0xFFFfff,"PAUSE"); |
243 | WriteText(10,14,0x83,0xFFFfff,"PAUSE"); |
201 | } |
- | |
202 | } |
244 | } |
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 | } |
245 | } |
211 | } |
246 | } |
212 | */ |
- | |
213 | } |
- | |
Line 214... | Line 247... | ||
214 | 247 | ||
215 | 248 | ||
216 | void DrawMenuList() |
249 | void DrawMenuList() |
Line 221... | Line 254... | ||
221 | 254 | ||
222 | void DrawMenuItem(int item_n, text_n) |
255 | void DrawMenuItem(int item_n, text_n) |
223 | { |
256 | { |
224 | dword color; |
257 | dword color; |
225 | if (active_menu_item==item_n) color = 0xFF0000; else color = 0xFFffff; |
258 | 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]); |
259 | WriteText(20+2, item_n*56+116+2, 0x81, 0xAAAaaa, MENU_LIST[text_n]); |
227 | WriteScaledText(10, item_n*28+48, 0x80, color, ITEMS_LIST[text_n]); |
260 | WriteText(20, item_n*56+116, 0x81, color, MENU_LIST[text_n]); |
Line 228... | Line 261... | ||
228 | } |
261 | } |
229 | 262 | ||
230 | 263 | ||
231 | void DrawGameOverMessage() |
264 | void DrawGameOverMessage() |
232 | { |
265 | { |
233 | DrawScaledBar(0, 0, WIN_X, WIN_Y, 0xF3E1BD); |
266 | DrawBar(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)); |
267 | WriteText(40, 40, 0x81, 0xA48C74, "GAME OVER"); |
237 | $add ecx, 2 << 16 |
268 | WriteText(40, 75, 0x81, 0xA48C74, "FINAL SCORE"); |
238 | $int 64 |
269 | WriteTextB(40, 140, 0x85, 0xA48C74, itoa(score)); |
239 | pause(350); |
270 | pause(350); |
Line 240... | Line -... | ||
240 | active_menu_item=0; |
- | |
241 | SetScreen(SCR_MENU_MAIN); |
- | |
242 | } |
- | |
243 | - | ||
244 | void DrawAccident() |
- | |
245 | { |
- | |
246 | DrawBus(bus_x*40+100,bus_y); |
- | |
247 | DrawBoom(bus_x*40+90,151); |
- | |
248 | pause(150); |
- | |
249 | lives--; |
- | |
250 | don_y = -don_h; |
- | |
251 | DrawScreen(); |
271 | active_menu_item=0; |
252 | if (lives>0) DrawScaledBar(bus_x*40+90, 147-17, 39, 45+23, COLOR_ROAD); |
272 | SetScreen(SCR_MENU_MAIN); |
253 | } |
273 | } |
254 | 274 | ||
255 | void GetNewObstacle(int N) |
- | |
256 | { |
275 | void GetNewObstacle(int N) |
257 | int i; |
- | |
258 | don_x = random(2); |
- | |
259 | if (N==RAND) { |
- | |
260 | don_type = random(7); |
- | |
261 | } |
276 | { |
262 | else { |
277 | int i; |
263 | don_type = N; |
278 | don_x = random(2); |
264 | } |
279 | if (N==RAND) don_type = random(7); else don_type = N; |
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 |
280 | don_h = don_h_mas[don_type]; |
Line 269... | Line 281... | ||
269 | { |
281 | don_y = -don_h; |
270 | don_image_y += don_h_mas[i]+1; |
- | |
271 | } |
- | |
272 | } |
282 | don_image_y = 0; |
273 | - | ||
274 | #define LINE_LENGTH 10 |
- | |
275 | void DrawRoad() |
- | |
276 | { |
- | |
277 | int y, line_y; |
283 | for (i = 0; i < don_type; i++) don_image_y += don_h_mas[i]+2; //calculate image y offset for current obstacle |
278 | - | ||
279 | if ((don_x == bus_x)&&(don_y + don_h > bus_y )&&(don_y < bus_y + don_h )) DrawAccident(); |
- | |
280 | - | ||
281 | if (lives==0) { |
- | |
282 | DrawGameOverMessage(); |
284 | } |
283 | return; |
285 | |
284 | } |
286 | #define LINE_LENGTH 10 |
285 | - | ||
286 | if (screen_type != SCR_PAUSE) |
- | |
287 | { |
287 | int line_y=0; |
288 | line_y+=2; |
288 | void DrawLineSeparator() |
289 | don_y+=2; |
289 | { |
290 | } |
290 | int y; |
291 | 291 | if (screen_type == SCR_GAME) line_y += don_step_y; |
|
292 | //the beginning of the white dashed line between two roadways |
292 | //the beginning of the white dashed line between two roadways |
293 | if (line_y>=20) { |
293 | if (line_y>=20) { |
294 | line_y=0; |
294 | line_y=0; |
295 | } |
295 | } |
296 | else |
296 | else |
297 | { |
297 | { |
298 | DrawScaledBar(129, 0, 1, line_y, COLOR_ROAD); |
298 | DrawBar(258, 0, 2, line_y, COLOR_ROAD); |
299 | DrawScaledBar(129, 0, 1, line_y-LINE_LENGTH, 0xDDE9F2); |
299 | DrawBar(258, 0, 2, line_y-LINE_LENGTH, 0xDDE9F2); |
300 | } |
300 | } |
301 | for (y=0; y |
- | |
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 | } |
- | |
306 | if (don_y >= WIN_Y) |
301 | for (y=0; y |
- | 302 | { |
|
- | 303 | DrawBar(258, line_y+y, 2, LINE_LENGTH, 0xDDE9F2); |
|
- | 304 | DrawBar(258, line_y+y+LINE_LENGTH, 2, LINE_LENGTH, COLOR_ROAD); |
|
307 | { |
305 | } |
308 | GetNewObstacle(RAND); |
306 | } |
309 | score++; |
307 | |
310 | WriteScore(); |
308 | void DrawRoad() |