Rev 4386 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
950 | leency | 1 | ;=============================================================================; |
5188 | hidnplayr | 2 | ; Hidnplayr's invaders for Kolibrios ; |
950 | leency | 3 | ;-----------------------------------------------------------------------------; |
4 | ; ; |
||
5188 | hidnplayr | 5 | ; Copyright (C) hidnplayr 2007-2014. All rights reserved. ; |
950 | leency | 6 | ; ; |
7 | ; Invaders is distributed in the hope that it will be useful, but WITHOUT ANY ; |
||
8 | ; WARRANTY. No author or distributor accepts responsibility to anyone for the ; |
||
9 | ; consequences of using it or for whether it serves any particular purpose or ; |
||
10 | ; works at all, unless he says so in writing. Refer to the GNU General Public ; |
||
11 | ; License (the "GPL") for full details. ; |
||
12 | ; Everyone is granted permission to copy, modify and redistribute KolibriOS, ; |
||
13 | ; but only under the conditions described in the GPL. A copy of this license ; |
||
14 | ; is supposed to have been given to you along with KolibriOS so you can know ; |
||
15 | ; your rights and responsibilities. It should be in a file named COPYING. ; |
||
16 | ; Among other things, the copyright notice and this notice must be preserved ; |
||
17 | ; on all copies. ; |
||
18 | ; ; |
||
19 | ; see copying.txt ; |
||
20 | ; ; |
||
21 | ; contact me on hidnplayr@gmail.com ; |
||
22 | ; ; |
||
23 | ;-----------------------------------------------------------------------------; |
||
24 | |||
5188 | hidnplayr | 25 | format binary as "" |
950 | leency | 26 | |
5188 | hidnplayr | 27 | ; Screen size |
28 | SCREEN_X = 640 |
||
29 | SCREEN_Y = 480 |
||
950 | leency | 30 | |
5188 | hidnplayr | 31 | ; Ship size |
32 | SHIP_X = 32 |
||
33 | SHIP_Y = 32 |
||
950 | leency | 34 | |
5188 | hidnplayr | 35 | ; Ship begin position |
36 | SHIP_X_POS = (SCREEN_X-SHIP_X)/2 |
||
37 | SHIP_Y_POS = SCREEN_Y-SHIP_Y-27 |
||
950 | leency | 38 | |
5188 | hidnplayr | 39 | ; Enemy size |
40 | ENEMY_X = 32 |
||
41 | ENEMY_Y = 32 |
||
950 | leency | 42 | |
5188 | hidnplayr | 43 | ; Alien size and position |
44 | ALIEN_X = 48 |
||
45 | ALIEN_Y = 38 |
||
46 | ALIEN_Y_POS = 1 |
||
950 | leency | 47 | |
5188 | hidnplayr | 48 | ; |
49 | BOUNDARY = 10 |
||
50 | MOVEMENT = 7 ; pixels/frame |
||
950 | leency | 51 | |
5188 | hidnplayr | 52 | TRANSPARENCY = 0x00ffffff ; color used as transparant |
950 | leency | 53 | |
5188 | hidnplayr | 54 | ; Window start position |
55 | WINDOW_X = 100 |
||
56 | WINDOW_Y = 100 |
||
950 | leency | 57 | |
5188 | hidnplayr | 58 | ; Bullet size |
59 | BULLET_X = 10 |
||
60 | BULLET_Y = 10 |
||
950 | leency | 61 | |
5188 | hidnplayr | 62 | ; Number of stars |
63 | STARS_ = 226 |
||
950 | leency | 64 | |
5188 | hidnplayr | 65 | ; Number of star levels (depth) |
66 | STARLEVELS = 3 |
||
950 | leency | 67 | |
5188 | hidnplayr | 68 | ENEMY_STARTING_X = 25 |
69 | ENEMY_STARTING_Y = 50 |
||
950 | leency | 70 | |
5188 | hidnplayr | 71 | BULLETSPEED = 12 ; pixels/frame |
950 | leency | 72 | |
5188 | hidnplayr | 73 | use32 |
74 | org 0x0 |
||
75 | db 'MENUET01' ; 8 byte id |
||
76 | dd 0x01 ; header version |
||
77 | dd START ; start of code |
||
78 | dd IM_END ; size of image |
||
79 | dd I_END+1000 ; memory for app |
||
80 | dd I_END+1000 ; esp |
||
81 | dd 0x0, 0x0 ; I_Param , I_Path |
||
950 | leency | 82 | |
5188 | hidnplayr | 83 | include '../../macros.inc' |
84 | include '../../proc32.inc' |
||
85 | include '../../dll.inc' |
||
86 | include '../../develop/libraries/libs-dev/libimg/libimg.inc' |
||
950 | leency | 87 | |
5188 | hidnplayr | 88 | KEY_RIGHT = 179 |
89 | KEY_LEFT = 176 |
||
90 | KEY_UP = 178 |
||
91 | KEY_P = 'p' |
||
92 | KEY_DOWN = 177 |
||
93 | KEY_ENTER = 13 |
||
94 | KEY_ESC = 27 |
||
950 | leency | 95 | |
5188 | hidnplayr | 96 | proc aimgtoimg img, x, y, canvas, acolor |
950 | leency | 97 | |
5188 | hidnplayr | 98 | pusha |
99 | ; Calculate offset on canvas in edi |
||
100 | mov eax, [y] |
||
101 | mov ecx, [canvas] |
||
102 | mul dword[ecx] ; canvas xsize |
||
103 | add eax, [x] |
||
950 | leency | 104 | |
5188 | hidnplayr | 105 | lea edi, [eax*2 + eax + 8] |
106 | add edi, [canvas] |
||
950 | leency | 107 | |
5188 | hidnplayr | 108 | ; get img size in ecx and edx |
109 | mov esi, [img] |
||
110 | mov ecx, dword[esi+0] ; img x size |
||
111 | mov edx, dword[esi+4] ; img y size |
||
950 | leency | 112 | |
5188 | hidnplayr | 113 | ; caluclate number of bytes between 2 lines in ebx |
114 | mov ebx, [canvas] |
||
115 | mov ebx, [ebx] ; canvas xsize |
||
116 | sub ebx, [esi] ; img xsize |
||
117 | lea ebx, [ebx*2 + ebx] |
||
950 | leency | 118 | |
5188 | hidnplayr | 119 | ; get image start ptr in esi |
120 | add esi, 8 |
||
950 | leency | 121 | |
5188 | hidnplayr | 122 | .loop2: |
123 | push ecx edx |
||
124 | mov edx, [acolor] |
||
125 | .loop: |
||
126 | mov eax, [esi] |
||
127 | and eax, 0x00ffffff |
||
128 | cmp eax, edx |
||
129 | je @f |
||
130 | mov word[edi], ax |
||
131 | shr eax, 16 |
||
132 | mov byte[edi+2], al |
||
133 | @@: |
||
134 | add esi, 3 |
||
135 | add edi, 3 |
||
136 | dec ecx |
||
137 | jnz .loop |
||
138 | pop edx ecx |
||
950 | leency | 139 | |
5188 | hidnplayr | 140 | add edi, ebx |
141 | dec edx |
||
142 | jnz .loop2 |
||
950 | leency | 143 | |
5188 | hidnplayr | 144 | popa |
145 | ret |
||
950 | leency | 146 | |
5188 | hidnplayr | 147 | endp |
950 | leency | 148 | |
5188 | hidnplayr | 149 | proc aimgtoimg2 img, x, y, canvas, acolor |
950 | leency | 150 | |
5188 | hidnplayr | 151 | pusha |
152 | ; Calculate offset on canvas in edi |
||
153 | mov eax, [y] |
||
154 | mov ecx, [canvas] |
||
155 | mul dword[ecx] ; canvas xsize |
||
156 | add eax, [x] |
||
950 | leency | 157 | |
5188 | hidnplayr | 158 | lea edi, [eax*2 + eax + 8] |
159 | add edi, [canvas] |
||
950 | leency | 160 | |
5188 | hidnplayr | 161 | ; get img size in ecx and edx |
162 | mov esi, [img] |
||
163 | mov ecx, dword[esi+0] ; img x size |
||
164 | mov edx, dword[esi+4] ; img y size |
||
950 | leency | 165 | |
5188 | hidnplayr | 166 | ; caluclate number of bytes between 2 lines in ebx |
167 | mov ebx, [canvas] |
||
168 | mov ebx, [ebx] ; canvas xsize |
||
169 | sub ebx, [esi] ; img xsize |
||
170 | lea ebx, [ebx*2 + ebx] |
||
950 | leency | 171 | |
5188 | hidnplayr | 172 | ; get image start ptr in esi |
173 | add esi, 8 |
||
950 | leency | 174 | |
5188 | hidnplayr | 175 | .loop2: |
176 | push ecx edx |
||
177 | mov edx, [acolor] |
||
178 | .loop: |
||
179 | mov eax, [esi] |
||
180 | and eax, 0x00ffffff |
||
181 | cmp eax, edx |
||
182 | je @f |
||
183 | mov byte[edi+2], al |
||
184 | shr eax, 8 |
||
185 | mov word[edi], ax |
||
186 | @@: |
||
187 | add esi, 3 |
||
188 | add edi, 3 |
||
189 | dec ecx |
||
190 | jnz .loop |
||
191 | pop edx ecx |
||
950 | leency | 192 | |
5188 | hidnplayr | 193 | add edi, ebx |
194 | dec edx |
||
195 | jnz .loop2 |
||
950 | leency | 196 | |
5188 | hidnplayr | 197 | popa |
198 | ret |
||
950 | leency | 199 | |
5188 | hidnplayr | 200 | endp |
950 | leency | 201 | |
5188 | hidnplayr | 202 | proc getimg imgsrc, x, y, xs, ys, imgdest |
950 | leency | 203 | |
5188 | hidnplayr | 204 | pusha |
950 | leency | 205 | |
5188 | hidnplayr | 206 | mov esi, [imgsrc] |
207 | mov eax, dword[esi+0] ; xsize |
||
208 | mov ebx, [y] |
||
209 | mul ebx ; xsize*y |
||
210 | add eax, [x] ; xsize*y+x |
||
211 | lea eax, [eax+2*eax] ; (xsize*y+x)*3 |
||
950 | leency | 212 | |
5188 | hidnplayr | 213 | mov edx, dword[esi+0] ; xsize |
214 | sub edx, [xs] ; xsize-xs |
||
215 | lea edx, [edx*2+edx] ; (xsize-xs)*3 |
||
950 | leency | 216 | |
5188 | hidnplayr | 217 | lea esi, [esi + eax + 8] ; imgsrc + (xsize*y+x)*3 + 8 |
950 | leency | 218 | |
5188 | hidnplayr | 219 | mov edi, [imgdest] |
220 | mov ecx, [xs] |
||
221 | mov dword[edi+0], ecx ; xsize |
||
222 | mov ebx, [ys] |
||
223 | mov dword[edi+4], ebx ; ysize |
||
224 | add edi, 8 ; imgdest + 8 |
||
950 | leency | 225 | |
5188 | hidnplayr | 226 | cld |
227 | .loop: |
||
228 | movsw |
||
229 | movsb |
||
230 | dec ecx |
||
231 | jnz .loop |
||
950 | leency | 232 | |
5188 | hidnplayr | 233 | add esi, edx |
234 | mov ecx, [xs] |
||
235 | dec ebx |
||
236 | jnz .loop |
||
950 | leency | 237 | |
5188 | hidnplayr | 238 | popa |
239 | ret |
||
950 | leency | 240 | |
5188 | hidnplayr | 241 | endp |
950 | leency | 242 | |
5188 | hidnplayr | 243 | macro decodeimg source, size, dest { |
950 | leency | 244 | |
5188 | hidnplayr | 245 | invoke img.decode, source, size, 0 |
246 | or eax, eax |
||
247 | jz exit |
||
248 | push [eax + Image.Width] |
||
249 | pop dword[dest+0] |
||
250 | push [eax + Image.Height] |
||
251 | pop dword[dest+4] |
||
252 | push eax |
||
253 | invoke img.to_rgb2, eax, dest+8 |
||
254 | pop eax |
||
255 | invoke img.destroy, eax |
||
256 | } |
||
950 | leency | 257 | |
258 | |||
5188 | hidnplayr | 259 | START: |
260 | mcall 68, 11 |
||
950 | leency | 261 | |
5188 | hidnplayr | 262 | stdcall dll.Load, @IMPORT |
263 | or eax, eax |
||
264 | jz @f |
||
265 | exit: |
||
266 | mcall -1 |
||
267 | @@: |
||
950 | leency | 268 | |
5188 | hidnplayr | 269 | call draw_window |
950 | leency | 270 | |
5188 | hidnplayr | 271 | decodeimg gif_bullet,gif_bullet.size,img_bullet |
272 | decodeimg gif_bullet2,gif_bullet2.size,img_bullet2 |
||
273 | decodeimg gif_ship,gif_ship.size,img_ship |
||
274 | decodeimg gif_enemy1,gif_enemy1.size,img_enemy1 |
||
275 | decodeimg gif_enemy2,gif_enemy2.size,img_enemy2 |
||
276 | decodeimg gif_enemy3,gif_enemy3.size,img_enemy3 |
||
277 | decodeimg gif_enemy4,gif_enemy4.size,img_enemy4 |
||
278 | decodeimg gif_enemy5,gif_enemy5.size,img_enemy5 |
||
279 | decodeimg gif_alien,gif_alien.size,img_alien |
||
280 | decodeimg gif_menu1,gif_menu1.size,img_menu1 |
||
281 | decodeimg gif_menu2,gif_menu2.size,img_menu2 |
||
282 | decodeimg gif_menu3,gif_menu3.size,img_menu3 |
||
283 | decodeimg gif_menu4,gif_menu4.size,img_menu4 |
||
284 | decodeimg gif_logo,gif_logo.size,img_logo |
||
285 | decodeimg gif_pause,gif_pause.size,img_pause |
||
286 | decodeimg gif_levelup,gif_levelup.size,img_levelup |
||
287 | decodeimg gif_gameover,gif_gameover.size,img_gameover |
||
288 | decodeimg gif_highscore,gif_highscore.size,img_highscore |
||
289 | decodeimg gif_smallfont,gif_smallfont.size,img_smallfont |
||
290 | decodeimg gif_bigfont,gif_bigfont.size,img_bigfont |
||
291 | decodeimg gif_numbers,gif_numbers.size,img_numbers |
||
950 | leency | 292 | |
5188 | hidnplayr | 293 | call init_starfield |
294 | call render_frame |
||
295 | call draw_to_screen |
||
950 | leency | 296 | |
5188 | hidnplayr | 297 | mainloop: |
950 | leency | 298 | |
5188 | hidnplayr | 299 | call render_frame |
300 | call draw_to_screen |
||
301 | call bullet_collision_detection |
||
950 | leency | 302 | |
5188 | hidnplayr | 303 | cmp [status], 3 ; if game is paused,... |
304 | jne .wait |
||
950 | leency | 305 | |
5188 | hidnplayr | 306 | mcall 10 |
307 | jmp .switch |
||
950 | leency | 308 | |
5188 | hidnplayr | 309 | .wait: |
310 | mcall 5, 1 ; wait 1/100 s |
||
950 | leency | 311 | |
5188 | hidnplayr | 312 | mcall 11 ; check for events |
313 | .switch: |
||
314 | test eax, eax |
||
315 | jz mainloop |
||
316 | dec eax |
||
317 | jz .redraw |
||
318 | dec eax |
||
319 | jz .key |
||
320 | dec eax |
||
321 | jz .button |
||
950 | leency | 322 | |
5188 | hidnplayr | 323 | .redraw: |
324 | call draw_window |
||
325 | jmp .wait |
||
950 | leency | 326 | |
5188 | hidnplayr | 327 | .button: |
328 | mcall 17 ; get button id |
||
950 | leency | 329 | |
5188 | hidnplayr | 330 | cmp ah, 1 |
331 | jne .wait |
||
332 | mcall -1 |
||
950 | leency | 333 | |
5188 | hidnplayr | 334 | .key: |
335 | mcall 2 ; get key code |
||
336 | test ah, ah |
||
337 | jz mainloop |
||
950 | leency | 338 | |
5188 | hidnplayr | 339 | cmp [status], 1 |
340 | je key_game |
||
341 | cmp [status], 0 |
||
342 | je key_menu |
||
343 | cmp [status], 3 |
||
344 | je key_pause |
||
345 | cmp [status], 6 |
||
346 | je key_levelup |
||
347 | cmp [status], 7 |
||
348 | je key_highscore |
||
349 | cmp [status], 2 |
||
350 | je key_gameover |
||
950 | leency | 351 | |
5188 | hidnplayr | 352 | cmp ah, KEY_ESC |
353 | jne .no_escape |
||
950 | leency | 354 | |
5188 | hidnplayr | 355 | mov [status], 0 |
356 | mov [intro], 0 |
||
357 | .no_escape: |
||
950 | leency | 358 | |
5188 | hidnplayr | 359 | jmp mainloop |
950 | leency | 360 | |
361 | |||
5188 | hidnplayr | 362 | key_game: |
363 | cmp ah, KEY_RIGHT |
||
364 | jnz .no_right |
||
950 | leency | 365 | |
5188 | hidnplayr | 366 | cmp [ship_x], SCREEN_X-SHIP_X-BOUNDARY |
367 | jge mainloop |
||
368 | add [ship_x], MOVEMENT |
||
369 | jmp mainloop |
||
370 | .no_right: |
||
950 | leency | 371 | |
5188 | hidnplayr | 372 | cmp ah, KEY_LEFT |
373 | jne .no_left |
||
950 | leency | 374 | |
5188 | hidnplayr | 375 | cmp [ship_x], BOUNDARY |
376 | jle mainloop |
||
377 | sub [ship_x], MOVEMENT |
||
378 | jmp mainloop |
||
379 | .no_left: |
||
950 | leency | 380 | |
5188 | hidnplayr | 381 | cmp ah, KEY_UP |
382 | jne .no_up |
||
950 | leency | 383 | |
5188 | hidnplayr | 384 | cmp [bullet_y], 1 |
385 | jg mainloop |
||
950 | leency | 386 | |
5188 | hidnplayr | 387 | mov eax, [ship_x] |
388 | add eax, (SHIP_X-BULLET_X)/2 |
||
389 | mov [bullet_x], eax |
||
390 | mov [bullet_y], SHIP_Y_POS;-BULLET_Y |
||
391 | jmp mainloop |
||
392 | .no_up: |
||
950 | leency | 393 | |
5188 | hidnplayr | 394 | cmp ah, KEY_P |
395 | jne no_pause |
||
950 | leency | 396 | |
5188 | hidnplayr | 397 | mov [status], 3 |
398 | stdcall aimgtoimg, img_pause, 150, 180, vscreen, TRANSPARENCY |
||
399 | call draw_to_screen |
||
950 | leency | 400 | |
5188 | hidnplayr | 401 | jmp mainloop |
402 | no_pause: |
||
403 | cmp ah, KEY_ESC |
||
404 | jne .no_escape |
||
950 | leency | 405 | |
5188 | hidnplayr | 406 | mov [status], 0 |
407 | mov [intro], 0 |
||
408 | .no_escape: |
||
409 | jmp mainloop |
||
950 | leency | 410 | |
411 | |||
5188 | hidnplayr | 412 | key_menu: |
413 | cmp ah, KEY_DOWN |
||
414 | jne .no_down |
||
950 | leency | 415 | |
5188 | hidnplayr | 416 | cmp [menu], 3 |
417 | jne @f |
||
418 | mov [menu], 0 |
||
419 | jmp mainloop |
||
420 | @@: |
||
421 | inc [menu] |
||
422 | jmp mainloop |
||
423 | .no_down: |
||
950 | leency | 424 | |
5188 | hidnplayr | 425 | cmp ah, KEY_UP |
426 | jnz .no_up |
||
950 | leency | 427 | |
5188 | hidnplayr | 428 | cmp [menu], 0 |
429 | jne @f |
||
430 | mov [menu], 3 |
||
431 | jmp mainloop |
||
432 | @@: |
||
433 | dec [menu] |
||
434 | jmp mainloop |
||
435 | .no_up: |
||
950 | leency | 436 | |
5188 | hidnplayr | 437 | cmp ah, KEY_ESC |
438 | jne @f |
||
439 | mcall -1 |
||
440 | @@: |
||
950 | leency | 441 | |
5188 | hidnplayr | 442 | cmp ah, KEY_ENTER |
443 | jnz .no_enter |
||
950 | leency | 444 | |
5188 | hidnplayr | 445 | cmp [menu], 0 ;start |
446 | je new_game |
||
950 | leency | 447 | |
5188 | hidnplayr | 448 | cmp [menu], 1 ;about |
449 | jne @f |
||
450 | mov [status], 4 |
||
451 | jmp mainloop |
||
452 | @@: |
||
950 | leency | 453 | |
5188 | hidnplayr | 454 | cmp [menu], 2 ;highscores |
455 | jne @f |
||
456 | mov [status], 5 |
||
457 | call load_highscores |
||
458 | jmp mainloop |
||
459 | @@: |
||
950 | leency | 460 | |
5188 | hidnplayr | 461 | cmp byte[menu], 3 ;exit |
462 | jne @f |
||
463 | mcall -1 |
||
464 | @@: |
||
465 | .no_enter: |
||
466 | jmp mainloop |
||
950 | leency | 467 | |
468 | |||
5188 | hidnplayr | 469 | key_pause: |
470 | cmp ah, KEY_P |
||
471 | jnz no_pause |
||
950 | leency | 472 | |
5188 | hidnplayr | 473 | mov [status], 1 |
474 | .nopause: |
||
475 | jmp mainloop |
||
950 | leency | 476 | |
477 | |||
5188 | hidnplayr | 478 | key_levelup: |
950 | leency | 479 | |
5188 | hidnplayr | 480 | cmp ah, KEY_ENTER |
481 | jne .no_enter |
||
950 | leency | 482 | |
5188 | hidnplayr | 483 | inc [level] |
950 | leency | 484 | |
5188 | hidnplayr | 485 | inc byte[levelnumb+1] |
486 | cmp byte[levelnumb+1], '9' |
||
487 | jle @f |
||
488 | mov byte[levelnumb+1], '0' |
||
489 | inc byte[levelnumb] |
||
950 | leency | 490 | |
5188 | hidnplayr | 491 | @@: |
492 | mov eax,20 |
||
493 | mov ah,byte[level] |
||
494 | and ah,7 |
||
495 | mul ah |
||
496 | add eax,level1 |
||
497 | mov esi,eax |
||
498 | jmp load_level |
||
950 | leency | 499 | |
5188 | hidnplayr | 500 | .no_enter: |
501 | cmp ah, KEY_ESC |
||
502 | jne .no_escape |
||
950 | leency | 503 | |
5188 | hidnplayr | 504 | mov [status], 0 |
505 | mov [intro], 0 |
||
506 | .no_escape: |
||
507 | jmp mainloop |
||
950 | leency | 508 | |
509 | |||
5188 | hidnplayr | 510 | key_highscore: |
950 | leency | 511 | |
5188 | hidnplayr | 512 | cmp ah, KEY_ENTER |
513 | jne @f |
||
950 | leency | 514 | |
5188 | hidnplayr | 515 | call load_highscores |
516 | mov eax, [score] |
||
517 | mov ebx, highscorebuffer+140 |
||
518 | .findscore: |
||
519 | cmp ebx, highscorebuffer+100 |
||
520 | je .topscore |
||
521 | sub ebx, 4 |
||
522 | cmp eax, dword[ebx] |
||
523 | jg .findscore |
||
950 | leency | 524 | |
5188 | hidnplayr | 525 | .topscore: |
526 | mov esi, name |
||
527 | mov edi, highscorebuffer |
||
528 | mov ecx, 10 |
||
529 | rep movsb |
||
950 | leency | 530 | |
5188 | hidnplayr | 531 | mov eax, [score] |
532 | mov dword[highscorebuffer+100], eax |
||
950 | leency | 533 | |
5188 | hidnplayr | 534 | call save_highscores |
535 | mov [status], 5 |
||
950 | leency | 536 | |
5188 | hidnplayr | 537 | @@: |
538 | cmp ah, 14 |
||
539 | jne @f |
||
950 | leency | 540 | |
5188 | hidnplayr | 541 | cmp byte[namepos],0 |
542 | je @f |
||
950 | leency | 543 | |
5188 | hidnplayr | 544 | dec byte[namepos] |
545 | movzx ebx,byte[namepos] |
||
546 | add ebx,name |
||
547 | mov byte[ebx], 0x11 ; this is a character we dont print |
||
950 | leency | 548 | |
5188 | hidnplayr | 549 | @@: |
550 | cmp byte[namepos],10 |
||
551 | jge mainloop |
||
950 | leency | 552 | |
5188 | hidnplayr | 553 | cmp al,'0' |
554 | jl mainloop |
||
555 | cmp al,'9' |
||
556 | jle @f |
||
950 | leency | 557 | |
5188 | hidnplayr | 558 | cmp al,'z' |
559 | jg mainloop |
||
560 | cmp al,'a' |
||
561 | jge @f |
||
950 | leency | 562 | |
5188 | hidnplayr | 563 | cmp al,'Z' |
564 | jg mainloop |
||
565 | cmp al,'A' |
||
566 | jl mainloop |
||
567 | @@: |
||
950 | leency | 568 | |
5188 | hidnplayr | 569 | movzx ebx, byte[namepos] |
570 | add ebx, name |
||
571 | mov byte[ebx], al |
||
950 | leency | 572 | |
5188 | hidnplayr | 573 | inc byte[namepos] |
950 | leency | 574 | |
5188 | hidnplayr | 575 | jmp mainloop |
950 | leency | 576 | |
577 | |||
5188 | hidnplayr | 578 | key_gameover: |
579 | cmp ah, KEY_ENTER |
||
580 | jne .no_enter |
||
950 | leency | 581 | |
5188 | hidnplayr | 582 | ; TODO: test if score is high enough to put in highscore list... |
583 | mov [status],7 |
||
584 | jmp mainloop |
||
950 | leency | 585 | |
5188 | hidnplayr | 586 | .no_enter: |
587 | jmp mainloop |
||
950 | leency | 588 | |
589 | |||
5188 | hidnplayr | 590 | new_game: |
591 | |||
592 | mov [score], 0 |
||
593 | mov eax, [score] |
||
594 | call convertscore |
||
595 | |||
596 | mov word[levelnumb], '01' |
||
597 | mov esi, level1 |
||
598 | |||
599 | load_level: |
||
600 | mov [enemy_speed], 1 |
||
601 | mov [enemy_x], ENEMY_STARTING_X |
||
602 | mov [enemy_y], ENEMY_STARTING_Y |
||
603 | |||
604 | mov edi, enemy_table |
||
605 | mov ecx, 5 |
||
606 | rep movsd |
||
607 | |||
608 | mov [status],1 |
||
609 | |||
610 | jmp mainloop |
||
611 | |||
612 | |||
613 | draw_window: |
||
614 | |||
615 | mcall 12, 1 ; Start of window draw |
||
616 | |||
617 | mov ebx, WINDOW_X shl 16 + 9 + SCREEN_X ; [x start] shl 16 + [x size] |
||
618 | mov ecx, WINDOW_Y shl 16 + 25 + SCREEN_Y ; [y start] shl 16 + [y size] |
||
619 | mov edx, 0x64000000 ; color of work area RRGGBB |
||
620 | mov esi, 0x805080d0 ; color of grab bar RRGGBB |
||
621 | mov edi, 0x005080d0 ; color of frames RRGGBB |
||
622 | mcall 0 |
||
623 | |||
624 | mcall 71, 1, title |
||
625 | |||
626 | call draw_to_screen |
||
627 | |||
628 | mcall 12, 2 ; End of window draw |
||
629 | |||
4386 | hidnplayr | 630 | ret |
950 | leency | 631 | |
632 | |||
633 | |||
5188 | hidnplayr | 634 | draw_to_screen: |
950 | leency | 635 | |
5188 | hidnplayr | 636 | ; Draw buffer to the screen |
637 | mov ebx, vscreen+8 |
||
638 | mov ecx, SCREEN_X shl 16 + SCREEN_Y |
||
639 | mov edx, 0 shl 16 + 0 |
||
640 | mcall 7 |
||
950 | leency | 641 | |
5188 | hidnplayr | 642 | ret |
950 | leency | 643 | |
644 | |||
5188 | hidnplayr | 645 | load_highscores: |
950 | leency | 646 | |
5188 | hidnplayr | 647 | ret |
950 | leency | 648 | |
649 | |||
5188 | hidnplayr | 650 | save_highscores: |
950 | leency | 651 | |
5188 | hidnplayr | 652 | ret |
950 | leency | 653 | |
654 | |||
5188 | hidnplayr | 655 | render_frame: |
950 | leency | 656 | |
5188 | hidnplayr | 657 | mov eax, 0x00000000 |
658 | call fillscreen |
||
659 | call render_starfield |
||
950 | leency | 660 | |
5188 | hidnplayr | 661 | cmp [status], 1 |
662 | je render_game |
||
663 | cmp [status], 2 |
||
664 | je render_gameover |
||
665 | cmp [status], 4 |
||
666 | je render_about |
||
667 | cmp [status], 6 |
||
668 | je render_levelup |
||
669 | cmp [status], 0 |
||
670 | je render_menu |
||
671 | cmp [status], 5 |
||
672 | je render_highscorelist |
||
673 | cmp [status], 7 |
||
674 | je render_highscore |
||
950 | leency | 675 | |
5188 | hidnplayr | 676 | ret |
950 | leency | 677 | |
678 | |||
5188 | hidnplayr | 679 | render_game: |
950 | leency | 680 | |
5188 | hidnplayr | 681 | call render_bullet |
682 | call render_enemies ; Draw the enemies to buffer |
||
683 | stdcall aimgtoimg, img_ship, [ship_x], SHIP_Y_POS, vscreen, TRANSPARENCY; Draw the ship to buffer |
||
950 | leency | 684 | |
5188 | hidnplayr | 685 | mov esi, scoretext |
686 | mov ebx, 0 |
||
687 | mov ecx, SCREEN_Y-24 |
||
688 | call printtext |
||
950 | leency | 689 | |
5188 | hidnplayr | 690 | mov esi, leveltext |
691 | mov ebx, 300 |
||
692 | call printtext |
||
950 | leency | 693 | |
5188 | hidnplayr | 694 | ret |
950 | leency | 695 | |
696 | |||
5188 | hidnplayr | 697 | render_gameover: |
950 | leency | 698 | |
5188 | hidnplayr | 699 | stdcall aimgtoimg, img_ship, [ship_x], SHIP_Y_POS, vscreen, TRANSPARENCY; Draw the ship to buffer |
950 | leency | 700 | |
5188 | hidnplayr | 701 | mov esi, scoretext |
702 | mov ebx, 0 |
||
703 | mov ecx, SCREEN_Y-24 |
||
704 | call printtext |
||
950 | leency | 705 | |
5188 | hidnplayr | 706 | mov esi, leveltext |
707 | mov ebx, 300 |
||
708 | call printtext |
||
709 | stdcall aimgtoimg, img_gameover, 150, 180, vscreen, TRANSPARENCY |
||
950 | leency | 710 | |
5188 | hidnplayr | 711 | ret |
950 | leency | 712 | |
713 | |||
5188 | hidnplayr | 714 | render_about: |
950 | leency | 715 | |
5188 | hidnplayr | 716 | mov esi, msgAbout |
717 | mov ebx, 50 |
||
718 | mov ecx, 100 |
||
719 | call printtext |
||
950 | leency | 720 | |
5188 | hidnplayr | 721 | ret |
950 | leency | 722 | |
723 | |||
5188 | hidnplayr | 724 | render_levelup: |
950 | leency | 725 | |
5188 | hidnplayr | 726 | stdcall aimgtoimg, img_ship, [ship_x], SHIP_Y_POS, vscreen, TRANSPARENCY; Draw the ship to buffer |
950 | leency | 727 | |
5188 | hidnplayr | 728 | mov esi, scoretext |
729 | mov ebx, 0 |
||
730 | mov ecx, SCREEN_Y-24 |
||
731 | call printtext |
||
950 | leency | 732 | |
5188 | hidnplayr | 733 | mov esi, leveltext |
734 | mov ebx, 300 |
||
735 | call printtext |
||
736 | stdcall aimgtoimg, img_levelup, 150, 180, vscreen, TRANSPARENCY |
||
950 | leency | 737 | |
5188 | hidnplayr | 738 | ret |
950 | leency | 739 | |
740 | |||
5188 | hidnplayr | 741 | render_menu: |
950 | leency | 742 | |
5188 | hidnplayr | 743 | stdcall aimgtoimg, img_logo, 50, 80, vscreen, TRANSPARENCY |
950 | leency | 744 | |
5188 | hidnplayr | 745 | cmp [menu], 0 |
746 | jne .menu_0 |
||
747 | stdcall aimgtoimg2, img_menu1, 30, 200, vscreen, TRANSPARENCY |
||
748 | jmp .menu_1 |
||
749 | .menu_0: |
||
750 | stdcall aimgtoimg, img_menu1, 30, 200, vscreen, TRANSPARENCY |
||
751 | .menu_1: |
||
752 | cmp [menu], 1 |
||
753 | jne .menu_2 |
||
754 | stdcall aimgtoimg2, img_menu2, 80, 250, vscreen, TRANSPARENCY |
||
755 | jmp .menu_3 |
||
756 | .menu_2: |
||
757 | stdcall aimgtoimg, img_menu2, 80, 250, vscreen, TRANSPARENCY |
||
758 | .menu_3: |
||
759 | cmp [menu], 2 |
||
760 | jne .menu_4 |
||
761 | stdcall aimgtoimg2, img_menu3, 120, 300, vscreen, TRANSPARENCY |
||
762 | jmp .menu_5 |
||
763 | .menu_4: |
||
764 | stdcall aimgtoimg, img_menu3, 120, 300, vscreen,TRANSPARENCY |
||
765 | .menu_5: |
||
766 | cmp [menu], 3 |
||
767 | jne .menu_6 |
||
768 | stdcall aimgtoimg2, img_menu4, 150, 350, vscreen, TRANSPARENCY |
||
769 | jmp .menu_7 |
||
770 | .menu_6: |
||
771 | stdcall aimgtoimg, img_menu4, 150, 350, vscreen, TRANSPARENCY |
||
772 | .menu_7: |
||
950 | leency | 773 | |
5188 | hidnplayr | 774 | cmp [intro], 200 |
775 | je .menu_75 |
||
776 | inc [intro] |
||
950 | leency | 777 | |
5188 | hidnplayr | 778 | .menu_75: |
779 | cmp [intro], 0 |
||
780 | jl .menu_8 |
||
781 | stdcall aimgtoimg, img_enemy1, 390, 180, vscreen, TRANSPARENCY |
||
950 | leency | 782 | |
5188 | hidnplayr | 783 | cmp [intro], 15 |
784 | jl .menu_8 |
||
785 | mov esi, points_50 |
||
786 | mov ebx, 470 |
||
787 | mov ecx, 180 |
||
788 | call printtext |
||
950 | leency | 789 | |
5188 | hidnplayr | 790 | cmp [intro],30 |
791 | jl .menu_8 |
||
792 | stdcall aimgtoimg, img_enemy2, 390, 220, vscreen, TRANSPARENCY |
||
950 | leency | 793 | |
5188 | hidnplayr | 794 | cmp [intro], 45 |
795 | jl .menu_8 |
||
796 | mov esi, points_100 |
||
797 | mov ebx, 450 |
||
798 | mov ecx, 220 |
||
799 | call printtext |
||
950 | leency | 800 | |
5188 | hidnplayr | 801 | cmp [intro], 60 |
802 | jl .menu_8 |
||
803 | stdcall aimgtoimg, img_enemy3, 390, 260, vscreen, TRANSPARENCY |
||
950 | leency | 804 | |
5188 | hidnplayr | 805 | cmp [intro], 75 |
806 | jl .menu_8 |
||
807 | mov esi, points_150 |
||
808 | mov ebx, 450 |
||
809 | mov ecx, 260 |
||
810 | call printtext |
||
950 | leency | 811 | |
5188 | hidnplayr | 812 | cmp [intro],90 |
813 | jl .menu_8 |
||
814 | stdcall aimgtoimg, img_enemy4, 390, 300, vscreen, TRANSPARENCY |
||
950 | leency | 815 | |
5188 | hidnplayr | 816 | cmp [intro], 105 |
817 | jl .menu_8 |
||
818 | mov esi, points_200 |
||
819 | mov ebx, 450 |
||
820 | mov ecx, 300 |
||
821 | call printtext |
||
950 | leency | 822 | |
5188 | hidnplayr | 823 | cmp [intro], 120 |
824 | jl .menu_8 |
||
825 | stdcall aimgtoimg, img_enemy5, 390, 340, vscreen, TRANSPARENCY |
||
950 | leency | 826 | |
5188 | hidnplayr | 827 | cmp [intro],135 |
828 | jl .menu_8 |
||
829 | mov esi, points_250 |
||
830 | mov ebx, 450 |
||
831 | mov ecx, 340 |
||
832 | call printtext |
||
950 | leency | 833 | |
5188 | hidnplayr | 834 | cmp [intro],150 |
835 | jl .menu_8 |
||
836 | stdcall aimgtoimg, img_alien, 380, 380, vscreen, TRANSPARENCY |
||
950 | leency | 837 | |
5188 | hidnplayr | 838 | cmp [intro],165 |
839 | jl .menu_8 |
||
840 | mov esi, points_1000 |
||
841 | mov ebx, 430 |
||
842 | mov ecx, 380 |
||
843 | call printtext |
||
950 | leency | 844 | |
5188 | hidnplayr | 845 | .menu_8: |
846 | ret |
||
950 | leency | 847 | |
5188 | hidnplayr | 848 | |
849 | render_highscorelist: |
||
850 | |||
851 | stdcall aimgtoimg, img_highscore, 60, 40, vscreen, TRANSPARENCY |
||
852 | |||
853 | mov ebx, 100 ; print names |
||
854 | mov ecx, 120 |
||
855 | mov esi, highscorebuffer |
||
856 | call printtext |
||
857 | |||
858 | mov edi, highscorebuffer+100 ; print scores |
||
859 | mov esi, scorenumb |
||
860 | mov ebx, 420 |
||
861 | mov ecx, 120 |
||
862 | |||
863 | .loop: |
||
864 | mov eax,[edi] |
||
865 | push ecx |
||
866 | call convertscore |
||
867 | pop ecx |
||
868 | push esi |
||
869 | call printtext |
||
870 | pop esi |
||
871 | add ecx, 26 |
||
872 | add edi, 4 |
||
873 | cmp edi, highscorebuffer+140 |
||
874 | jl .loop |
||
875 | |||
4386 | hidnplayr | 876 | ret |
950 | leency | 877 | |
878 | |||
5188 | hidnplayr | 879 | render_highscore: |
950 | leency | 880 | |
5188 | hidnplayr | 881 | stdcall aimgtoimg, img_highscore, 60, 40, vscreen, TRANSPARENCY |
882 | |||
883 | mov ebx, 60 |
||
884 | mov ecx, 200 |
||
885 | mov esi, entername |
||
886 | call printtext |
||
887 | |||
888 | mov ebx, 250 |
||
889 | mov ecx, 250 |
||
890 | mov esi, name |
||
891 | call printtext |
||
892 | |||
893 | mov esi, scoretext |
||
894 | mov ebx, 0 |
||
895 | mov ecx, SCREEN_Y-24 |
||
896 | call printtext |
||
897 | |||
898 | mov esi, leveltext |
||
899 | mov ebx, 300 |
||
900 | call printtext |
||
901 | |||
4386 | hidnplayr | 902 | ret |
950 | leency | 903 | |
904 | |||
5188 | hidnplayr | 905 | render_enemies: |
906 | ; check if direction should change |
||
907 | test [enemy_d], 2 |
||
908 | jz @f |
||
950 | leency | 909 | |
5188 | hidnplayr | 910 | add [enemy_y], 5 |
950 | leency | 911 | |
5188 | hidnplayr | 912 | mov eax, [enemy_y] |
913 | shr eax, 5 |
||
914 | add al, [level] |
||
915 | mov [enemy_speed], al |
||
950 | leency | 916 | |
5188 | hidnplayr | 917 | and [enemy_d], 1 |
950 | leency | 918 | |
5188 | hidnplayr | 919 | @@: |
920 | ; move the aliens to left or right |
||
921 | movzx eax, [enemy_speed] |
||
922 | test [enemy_d], 1 |
||
923 | jz .other_dir |
||
950 | leency | 924 | |
5188 | hidnplayr | 925 | sub [enemy_x], eax |
926 | jmp .no_other_dir |
||
950 | leency | 927 | |
5188 | hidnplayr | 928 | .other_dir: |
929 | add [enemy_x], eax |
||
930 | .no_other_dir: |
||
950 | leency | 931 | |
5188 | hidnplayr | 932 | ; initialization |
933 | mov [alldeadb],1 |
||
934 | mov edi, enemy_table |
||
935 | mov eax, [enemy_x] |
||
936 | mov [current_enemy_x], eax |
||
937 | mov eax, [enemy_y] |
||
938 | mov [current_enemy_y], eax |
||
950 | leency | 939 | |
5188 | hidnplayr | 940 | .loopit: |
941 | movzx eax, byte[edi] |
||
942 | test al, al |
||
943 | jz .next_alien |
||
944 | cmp al, 5 |
||
945 | ja .next_alien |
||
946 | dec eax |
||
947 | mov eax, [enemy_img_list+eax*4] |
||
950 | leency | 948 | |
5188 | hidnplayr | 949 | .drawenemy: |
950 | mov [alldeadb], 0 |
||
951 | stdcall aimgtoimg, eax, [current_enemy_x], [current_enemy_y], vscreen, TRANSPARENCY |
||
952 | ; jmp checknext |
||
950 | leency | 953 | |
5188 | hidnplayr | 954 | .checknext: |
955 | cmp [enemy_d], 2 |
||
956 | jge .dont_change_dir |
||
950 | leency | 957 | |
5188 | hidnplayr | 958 | movzx eax, [enemy_speed] |
950 | leency | 959 | |
5188 | hidnplayr | 960 | cmp [enemy_d], 0 |
961 | jbe .change_dir |
||
950 | leency | 962 | |
5188 | hidnplayr | 963 | cmp dword[current_enemy_x],eax |
964 | jg .dont_change_dir |
||
950 | leency | 965 | |
5188 | hidnplayr | 966 | mov [enemy_d], 2 |
967 | jmp .dont_change_dir |
||
950 | leency | 968 | |
5188 | hidnplayr | 969 | .change_dir: |
970 | mov ebx, SCREEN_X-ENEMY_X |
||
971 | sub ebx, eax |
||
972 | cmp dword[current_enemy_x],ebx |
||
973 | jl .dont_change_dir |
||
950 | leency | 974 | |
5188 | hidnplayr | 975 | mov [enemy_d], 3 |
950 | leency | 976 | |
5188 | hidnplayr | 977 | .dont_change_dir: |
978 | cmp [current_enemy_y], SHIP_Y_POS-ENEMY_Y-BOUNDARY |
||
979 | jle .next_alien ;;;;;; |
||
950 | leency | 980 | |
5188 | hidnplayr | 981 | mov [status], 2 |
982 | ret |
||
950 | leency | 983 | |
5188 | hidnplayr | 984 | .next_alien: |
985 | cmp edi, enemy_table+20 |
||
986 | jge .alldead |
||
950 | leency | 987 | |
5188 | hidnplayr | 988 | inc edi |
989 | add dword[current_enemy_x],ENEMY_X+BOUNDARY |
||
990 | mov eax,dword[current_enemy_x] |
||
991 | sub eax,dword[enemy_x] |
||
992 | cmp eax,5*(ENEMY_X+BOUNDARY) |
||
993 | jl .no_newline |
||
950 | leency | 994 | |
5188 | hidnplayr | 995 | sub [current_enemy_x], 5*(ENEMY_X+BOUNDARY) |
996 | add [current_enemy_y], ENEMY_Y+BOUNDARY |
||
997 | .no_newline: |
||
998 | jmp .loopit |
||
950 | leency | 999 | |
5188 | hidnplayr | 1000 | .alldead: |
1001 | cmp [alldeadb], 0 |
||
1002 | je .enemy_end |
||
1003 | |||
1004 | mov [status], 6 |
||
4386 | hidnplayr | 1005 | ret |
950 | leency | 1006 | |
5188 | hidnplayr | 1007 | .enemy_end: |
1008 | cmp [alien_x], 5 |
||
1009 | jge @f |
||
950 | leency | 1010 | |
5188 | hidnplayr | 1011 | call random_generator |
1012 | cmp eax,0xffffffff/50 ; one out of 500 chances that it appears during this frame |
||
1013 | jl .alien_end |
||
1014 | mov [alien_x], SCREEN_X-ALIEN_X |
||
1015 | @@: |
||
1016 | push eax |
||
950 | leency | 1017 | |
5188 | hidnplayr | 1018 | mov eax, SCREEN_X ; mov eax, SCREEN_X |
1019 | sub eax, dword [alien_x] |
||
950 | leency | 1020 | |
5188 | hidnplayr | 1021 | cmp eax, ALIEN_X |
1022 | jle @f |
||
1023 | mov eax, ALIEN_X |
||
1024 | @@: |
||
950 | leency | 1025 | |
5188 | hidnplayr | 1026 | ; stdcall getimg, img_alien, 0, 0, 10, ALIEN_Y, img_alienpiece |
1027 | stdcall aimgtoimg, img_alien, [alien_x], ALIEN_Y_POS, vscreen, TRANSPARENCY |
||
1028 | sub [alien_x], 5 |
||
1029 | |||
1030 | pop eax |
||
1031 | |||
1032 | .alien_end: |
||
4386 | hidnplayr | 1033 | ret |
950 | leency | 1034 | |
1035 | |||
1036 | |||
5188 | hidnplayr | 1037 | render_bullet: |
1038 | cmp [bullet_y], BULLETSPEED |
||
1039 | jl .nobullet |
||
1040 | sub [bullet_y], BULLETSPEED |
||
950 | leency | 1041 | |
5188 | hidnplayr | 1042 | stdcall aimgtoimg, img_bullet, [bullet_x], [bullet_y], vscreen, TRANSPARENCY |
950 | leency | 1043 | |
5188 | hidnplayr | 1044 | .nobullet: |
1045 | ret |
||
950 | leency | 1046 | |
1047 | |||
1048 | |||
5188 | hidnplayr | 1049 | bullet_collision_detection: |
950 | leency | 1050 | |
5188 | hidnplayr | 1051 | cmp [bullet_y], BULLETSPEED ; does the bullet hit top of the screen? |
1052 | jle .hidebullet ; yes, hide bullet |
||
950 | leency | 1053 | |
5188 | hidnplayr | 1054 | mov edi, enemy_table |
1055 | mov eax, [enemy_x] |
||
1056 | mov [current_enemy_x], eax |
||
1057 | mov eax, [enemy_y] |
||
1058 | mov [current_enemy_y], eax |
||
950 | leency | 1059 | |
5188 | hidnplayr | 1060 | .check: |
1061 | cmp byte[edi],0 ; is the enemy at this position alive? |
||
1062 | je .nextcheck ; no, try next enemy |
||
1063 | ; check if bullet hits current enemy |
||
950 | leency | 1064 | |
5188 | hidnplayr | 1065 | mov eax, [current_enemy_y] ; move the enemy y position into eax |
1066 | cmp [bullet_y], eax ; is the bullet's y position less than eax (enemy y pos) |
||
1067 | jl .nextcheck ; yes, bullet can't be colliding, check next enemy |
||
950 | leency | 1068 | |
5188 | hidnplayr | 1069 | add eax, ENEMY_Y ; add the width of the enemy to the enemy's y position (wich is still stored in eax) |
1070 | cmp [bullet_y], eax ; is the bullet's y position greater than eax (the end of the enemy) |
||
1071 | jg .nextcheck ; yes, bullet can't be colliding, check next enemy |
||
950 | leency | 1072 | |
5188 | hidnplayr | 1073 | mov eax, [current_enemy_x] ; now do the same but for the x positions |
1074 | cmp [bullet_x], eax ; |
||
1075 | jl .nextcheck ; |
||
1076 | ; |
||
1077 | add eax, ENEMY_Y ; |
||
1078 | cmp [bullet_x], eax ; |
||
1079 | jg .nextcheck ; |
||
950 | leency | 1080 | |
5188 | hidnplayr | 1081 | jmp .hit |
950 | leency | 1082 | |
5188 | hidnplayr | 1083 | .nextcheck: |
1084 | inc edi |
||
1085 | add [current_enemy_x], ENEMY_X+BOUNDARY |
||
1086 | mov eax, [current_enemy_x] |
||
1087 | sub eax, [enemy_x] |
||
1088 | cmp eax, 5*(ENEMY_X+BOUNDARY) |
||
1089 | jl .no_newline |
||
950 | leency | 1090 | |
5188 | hidnplayr | 1091 | sub [current_enemy_x], 5*(ENEMY_X+BOUNDARY) |
1092 | add [current_enemy_y], ENEMY_Y+BOUNDARY |
||
1093 | .no_newline: |
||
950 | leency | 1094 | |
5188 | hidnplayr | 1095 | cmp edi, enemy_table+20 ; is this the last enemy? |
1096 | jg .nohit ; yes, none of them was hit |
||
1097 | jmp .check ; no, check if enemy is alive and draw it |
||
950 | leency | 1098 | |
5188 | hidnplayr | 1099 | .hit: |
1100 | movzx ebx, byte[edi] ; mov the enemy number onto ebx |
||
1101 | add [score], ebx ; add this number to the score dword |
||
950 | leency | 1102 | |
5188 | hidnplayr | 1103 | mov eax,[score] |
1104 | call convertscore |
||
950 | leency | 1105 | |
5188 | hidnplayr | 1106 | mov byte[edi],0 ; hide the enemy |
1107 | .hidebullet: |
||
1108 | mov [bullet_y], 1 ; mov the bullet to top of screen (hide it) |
||
1109 | jmp .noalienhit |
||
950 | leency | 1110 | |
5188 | hidnplayr | 1111 | .nohit: |
1112 | mov eax, [alien_x] ; check if we hit the big alien in the ufo |
||
1113 | cmp [bullet_x], eax |
||
1114 | jl .noalienhit |
||
1115 | add eax, ALIEN_X-BULLET_X |
||
1116 | cmp [bullet_x], eax |
||
1117 | jg .noalienhit |
||
1118 | cmp [bullet_y], ALIEN_Y_POS+ALIEN_Y |
||
1119 | jg .noalienhit |
||
950 | leency | 1120 | |
5188 | hidnplayr | 1121 | add [score], 100/5 |
1122 | mov eax, [score] |
||
1123 | call convertscore |
||
950 | leency | 1124 | |
5188 | hidnplayr | 1125 | mov [alien_x], 0 |
950 | leency | 1126 | |
5188 | hidnplayr | 1127 | .noalienhit: |
1128 | ret |
||
950 | leency | 1129 | |
1130 | |||
1131 | |||
5188 | hidnplayr | 1132 | convertscore: |
950 | leency | 1133 | |
5188 | hidnplayr | 1134 | test al,1 |
1135 | jz .1 |
||
1136 | mov byte[scorenumb+5],'5' |
||
1137 | jmp .2 |
||
1138 | .1: |
||
1139 | mov byte[scorenumb+5],'0' |
||
1140 | .2: |
||
1141 | shr eax,1 |
||
1142 | mov ecx,10 |
||
1143 | xor edx,edx |
||
1144 | div ecx |
||
1145 | add dl,'0' |
||
1146 | mov byte[scorenumb+4],dl |
||
1147 | xor edx,edx |
||
1148 | div ecx |
||
1149 | add dl,'0' |
||
1150 | mov byte[scorenumb+3],dl |
||
1151 | xor edx,edx |
||
1152 | div ecx |
||
1153 | add dl,'0' |
||
1154 | mov byte[scorenumb+2],dl |
||
1155 | xor edx,edx |
||
1156 | div ecx |
||
1157 | add dl,'0' |
||
1158 | mov byte[scorenumb+1],dl |
||
1159 | xor edx,edx |
||
1160 | div ecx |
||
1161 | add dl,'0' |
||
1162 | mov byte[scorenumb+0],dl |
||
950 | leency | 1163 | |
5188 | hidnplayr | 1164 | ret |
950 | leency | 1165 | |
1166 | |||
5188 | hidnplayr | 1167 | fillscreen: ; eax - screen color ( 0x00RRGGBB ) |
950 | leency | 1168 | |
5188 | hidnplayr | 1169 | mov edi, vscreen+8 |
1170 | cld |
||
1171 | mov ecx, SCREEN_X*SCREEN_Y |
||
1172 | .lab1: |
||
1173 | mov [edi], eax |
||
1174 | add edi, 3 |
||
1175 | loop .lab1 |
||
950 | leency | 1176 | |
5188 | hidnplayr | 1177 | ret |
950 | leency | 1178 | |
1179 | |||
5188 | hidnplayr | 1180 | printtext: |
950 | leency | 1181 | |
5188 | hidnplayr | 1182 | push ebx |
950 | leency | 1183 | |
5188 | hidnplayr | 1184 | .loop: |
1185 | lodsb |
||
1186 | test al, al |
||
1187 | jz .done |
||
1188 | cmp al, 13 |
||
1189 | je .nextline |
||
1190 | cmp al,' ' |
||
1191 | je .space |
||
950 | leency | 1192 | |
5188 | hidnplayr | 1193 | cmp al,'0' |
1194 | jl .loop |
||
1195 | cmp al,'9' |
||
1196 | jle .usenumbers |
||
950 | leency | 1197 | |
5188 | hidnplayr | 1198 | cmp al,'z' |
1199 | jg .loop |
||
1200 | cmp al,'a' |
||
1201 | jge .usesmallfont |
||
950 | leency | 1202 | |
5188 | hidnplayr | 1203 | cmp al,'Z' |
1204 | jg .loop |
||
1205 | cmp al,'A' |
||
1206 | jge .usebigfont |
||
1207 | jmp .loop |
||
950 | leency | 1208 | |
5188 | hidnplayr | 1209 | .usesmallfont: |
1210 | movzx edx, al |
||
1211 | sub edx, 'a' |
||
1212 | mov eax, 12 |
||
1213 | mul edx |
||
950 | leency | 1214 | |
5188 | hidnplayr | 1215 | stdcall getimg, img_smallfont, 0, eax, 20, 12, img_char |
1216 | push ecx |
||
1217 | add ecx, 4 |
||
1218 | stdcall aimgtoimg, img_char, ebx, ecx, vscreen, TRANSPARENCY |
||
1219 | pop ecx |
||
1220 | add ebx, 20 |
||
1221 | jmp .loop |
||
950 | leency | 1222 | |
5188 | hidnplayr | 1223 | .usebigfont: |
1224 | movzx edx, al |
||
1225 | sub edx, 'A' |
||
1226 | mov eax, 20 |
||
1227 | mul edx |
||
950 | leency | 1228 | |
5188 | hidnplayr | 1229 | stdcall getimg, img_bigfont, 0, eax, 28, 20, img_char |
1230 | stdcall aimgtoimg, img_char, ebx, ecx, vscreen, TRANSPARENCY |
||
1231 | add ebx, 28 |
||
1232 | jmp .loop |
||
950 | leency | 1233 | |
5188 | hidnplayr | 1234 | .usenumbers: |
1235 | movzx edx, al |
||
1236 | sub edx, '0' |
||
1237 | mov eax, 20 |
||
1238 | mul edx |
||
1239 | |||
1240 | stdcall getimg, img_numbers, 0, eax, 16, 20, img_char |
||
1241 | stdcall aimgtoimg, img_char, ebx, ecx, vscreen, TRANSPARENCY |
||
1242 | add ebx, 20 |
||
1243 | jmp .loop |
||
1244 | |||
1245 | .space: |
||
1246 | add ebx, 20 |
||
1247 | jmp .loop |
||
1248 | |||
1249 | .nextline: |
||
1250 | pop ebx |
||
1251 | push ebx |
||
1252 | add ecx, 26 |
||
1253 | jmp .loop |
||
1254 | |||
1255 | .done: |
||
1256 | pop ebx |
||
1257 | ret |
||
1258 | |||
1259 | |||
1260 | init_starfield: |
||
1261 | |||
1262 | mov ebx, STARS |
||
1263 | .loop: |
||
1264 | cmp ebx, STARS+(STARS_*5) |
||
1265 | jge .done |
||
1266 | |||
1267 | call random_generator |
||
1268 | and al, STARLEVELS |
||
1269 | test al,al |
||
1270 | jnz @f |
||
1271 | inc al |
||
1272 | @@: |
||
1273 | mov byte[ebx],al |
||
1274 | |||
1275 | call random_generator |
||
1276 | and eax, SCREEN_X-1 |
||
1277 | inc eax |
||
1278 | mov word[ebx+1],ax |
||
1279 | |||
1280 | call random_generator |
||
1281 | and eax, SCREEN_Y-1 |
||
1282 | inc eax |
||
1283 | mov word[ebx+3],ax |
||
1284 | |||
1285 | add ebx, 5 |
||
1286 | jmp .loop |
||
1287 | .done: |
||
1288 | ret |
||
1289 | |||
1290 | |||
1291 | render_starfield: |
||
1292 | |||
1293 | mov esi, STARS |
||
1294 | .loop: |
||
1295 | cmp esi, STARS+(STARS_*5) |
||
1296 | jge .done |
||
1297 | |||
1298 | movzx eax, byte[esi] ; z (speed, brightness) |
||
1299 | movzx ebx, word[esi+1] ; x |
||
1300 | movzx ecx, word[esi+3] ; y |
||
1301 | add bx, ax |
||
1302 | cmp bx, SCREEN_X |
||
1303 | jl .moveit |
||
1304 | |||
1305 | xor ebx, ebx |
||
1306 | inc ebx |
||
1307 | |||
1308 | call random_generator |
||
1309 | mov ecx, [generator] |
||
1310 | and ecx, SCREEN_Y-1 |
||
1311 | inc ecx |
||
1312 | mov word[esi+3], cx |
||
1313 | |||
1314 | call random_generator |
||
1315 | and al, STARLEVELS |
||
1316 | test al, al |
||
1317 | jnz @f |
||
1318 | inc al |
||
950 | leency | 1319 | @@: |
5188 | hidnplayr | 1320 | mov [esi], al |
950 | leency | 1321 | |
5188 | hidnplayr | 1322 | .moveit: |
1323 | mov word[esi+1], bx |
||
950 | leency | 1324 | |
5188 | hidnplayr | 1325 | movzx eax, byte[esi] |
1326 | inc eax |
||
1327 | mov edx, 0xff/(STARLEVELS+1) |
||
1328 | mul edx |
||
950 | leency | 1329 | |
5188 | hidnplayr | 1330 | mov ah, al |
1331 | shl eax, 8 |
||
1332 | mov al, ah |
||
1333 | mov ebp, eax |
||
950 | leency | 1334 | |
5188 | hidnplayr | 1335 | mov eax, SCREEN_X |
1336 | mul ecx |
||
1337 | add eax, ebx |
||
1338 | mov edx, 3 |
||
1339 | mul edx |
||
950 | leency | 1340 | |
5188 | hidnplayr | 1341 | cmp eax, SCREEN_X*SCREEN_Y*3 |
1342 | jg @f |
||
1343 | add eax, vscreen+8 |
||
1344 | and dword[eax], 0xff000000 |
||
1345 | or dword[eax], ebp |
||
1346 | @@: |
||
950 | leency | 1347 | |
5188 | hidnplayr | 1348 | add esi, 5 |
1349 | jmp .loop |
||
1350 | |||
1351 | .done: |
||
1352 | ret |
||
1353 | |||
950 | leency | 1354 | random_generator: ; (pseudo random, actually :) |
1355 | |||
5188 | hidnplayr | 1356 | xor eax, [generator] |
1357 | imul eax, 214013 |
||
1358 | xor eax, 0xdeadbeef |
||
1359 | rol eax, 9 |
||
1360 | mov [generator], eax |
||
1361 | ror eax, 16 |
||
1362 | and eax, 0x7fff |
||
950 | leency | 1363 | |
5188 | hidnplayr | 1364 | ret |
950 | leency | 1365 | |
1366 | |||
1367 | |||
1368 | |||
1369 | level1: |
||
1370 | db 4,4,4,4,4 |
||
1371 | db 3,3,3,3,3 |
||
1372 | db 2,2,2,2,2 |
||
1373 | db 1,1,1,1,1 |
||
1374 | |||
1375 | level2: |
||
1376 | db 4,1,3,1,4 |
||
1377 | db 4,3,2,3,4 |
||
1378 | db 0,4,1,4,0 |
||
1379 | db 0,0,2,0,0 |
||
1380 | |||
1381 | level3: |
||
1382 | db 1,5,5,5,1 |
||
1383 | db 1,2,2,2,1 |
||
1384 | db 3,1,2,1,3 |
||
1385 | db 4,3,1,3,4 |
||
1386 | |||
1387 | level4: |
||
1388 | db 4,5,2,5,4 |
||
1389 | db 5,3,3,3,5 |
||
1390 | db 4,5,4,5,4 |
||
1391 | db 1,5,5,5,1 |
||
1392 | |||
1393 | level5: |
||
1394 | db 5,4,3,4,5 |
||
1395 | db 5,4,4,4,5 |
||
1396 | db 4,5,4,5,4 |
||
1397 | db 3,5,1,5,3 |
||
1398 | |||
1399 | level6: |
||
1400 | db 1,2,5,4,5 |
||
1401 | db 5,4,5,2,1 |
||
1402 | db 1,2,5,4,5 |
||
1403 | db 1,1,5,1,1 |
||
1404 | |||
1405 | level7: |
||
1406 | db 1,2,3,2,1 |
||
1407 | db 1,3,3,3,1 |
||
1408 | db 3,4,3,4,3 |
||
1409 | db 5,5,5,5,5 |
||
1410 | |||
1411 | level8: |
||
1412 | db 1,2,3,4,5 |
||
1413 | db 3,5,3,5,4 |
||
1414 | db 4,2,3,2,3 |
||
1415 | db 5,4,3,2,1 |
||
1416 | |||
1417 | enemy_table: |
||
1418 | db 0,0,0,0,0 |
||
1419 | db 0,0,0,0,0 |
||
1420 | db 0,0,0,0,0 |
||
1421 | db 0,0,0,0,0 |
||
1422 | |||
4386 | hidnplayr | 1423 | msgAbout db 'Hidnplayrs invaders',13,'KolibriOS version',13,13,'released under GPL',13,'make this game better',13,'if you want to',0 |
5188 | hidnplayr | 1424 | title db 'Invaders',0 |
4386 | hidnplayr | 1425 | msgdone db 'You have saved the planet!',0 |
1426 | entername db 'Enter your name highscorer!',0 |
||
1427 | highscorefile db 'invaders.dat',0 |
||
1428 | points_50 db '5 pt',0 |
||
1429 | points_100 db '10 pt',0 |
||
1430 | points_150 db '15 pt',0 |
||
1431 | points_200 db '20 pt',0 |
||
1432 | points_250 db '25 pt',0 |
||
1433 | points_1000 db '100 pt',0 |
||
1434 | ship_x dd SHIP_X_POS |
||
1435 | enemy_x dd 0 |
||
1436 | enemy_y dd 0 |
||
1437 | enemy_d db 0 |
||
950 | leency | 1438 | current_enemy_x dd 0 |
1439 | current_enemy_y dd 0 |
||
4386 | hidnplayr | 1440 | bullet_x dd 0 |
1441 | bullet_y dd 1 |
||
1442 | score dd 0 |
||
1443 | alldeadb db 0 |
||
1444 | status db 0 ; status: 0=menu 1=game 2=gameover 3=paused 4=about 5=highscorelist 6=levelup 7=highscore... |
||
1445 | menu db 0 ; menu: 0=start 1=about 2=highscores 3=exit... |
||
1446 | generator dd 0x45dd4d15 |
||
1447 | alien_x dd 0 |
||
5188 | hidnplayr | 1448 | ;drawroutine dd 0 |
4386 | hidnplayr | 1449 | returnaddr dd 0 |
1450 | intro dw 0 |
||
1451 | scoretext db 'score ' |
||
1452 | scorenumb db 0,0,0,0,0,0,0 |
||
1453 | leveltext db 'level ' |
||
1454 | levelnumb db 0,0,0 |
||
1455 | lives db 0 |
||
1456 | level db 1 |
||
1457 | enemy_speed db 1 |
||
1458 | namepos db 0 |
||
1459 | name db 0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x0d,0x00 |
||
950 | leency | 1460 | |
5188 | hidnplayr | 1461 | enemy_img_list: |
1462 | dd img_enemy1 |
||
1463 | dd img_enemy2 |
||
1464 | dd img_enemy3 |
||
1465 | dd img_enemy4 |
||
1466 | dd img_enemy5 |
||
950 | leency | 1467 | |
1468 | |||
5188 | hidnplayr | 1469 | gif_bullet file 'bullet2.gif' |
1470 | .size = $ - gif_bullet |
||
1471 | gif_bullet2 file 'bullet2.gif' |
||
1472 | .size = $ - gif_bullet2 |
||
1473 | gif_ship file 'ship.gif' |
||
1474 | .size = $ - gif_ship |
||
1475 | gif_enemy1 file 'enemy1.gif' |
||
1476 | .size = $ - gif_enemy1 |
||
1477 | gif_enemy2 file 'enemy2.gif' |
||
1478 | .size = $ - gif_enemy2 |
||
1479 | gif_enemy3 file 'enemy3.gif' |
||
1480 | .size = $ - gif_enemy3 |
||
1481 | gif_enemy4 file 'enemy4.gif' |
||
1482 | .size = $ - gif_enemy4 |
||
1483 | gif_enemy5 file 'enemy5.gif' |
||
1484 | .size = $ - gif_enemy5 |
||
1485 | gif_alien file 'alien.gif' |
||
1486 | .size = $ - gif_alien |
||
1487 | gif_menu1 file 'menu1.gif' |
||
1488 | .size = $ - gif_menu1 |
||
1489 | gif_menu2 file 'menu2.gif' |
||
1490 | .size = $ - gif_menu2 |
||
1491 | gif_menu3 file 'menu3.gif' |
||
1492 | .size = $ - gif_menu3 |
||
1493 | gif_menu4 file 'menu4.gif' |
||
1494 | .size = $ - gif_menu3 |
||
1495 | gif_logo file 'logo.gif' |
||
1496 | .size = $ - gif_logo |
||
1497 | gif_pause file 'pause.gif' |
||
1498 | .size = $ - gif_pause |
||
1499 | gif_highscore file 'highscores.gif' |
||
1500 | .size = $ - gif_highscore |
||
1501 | gif_smallfont file 'font_small.gif' |
||
1502 | .size = $ - gif_smallfont |
||
1503 | gif_bigfont file 'font_capital.gif' |
||
1504 | .size = $ - gif_bigfont |
||
1505 | gif_numbers file 'numbers.gif' |
||
1506 | .size = $ - gif_numbers |
||
1507 | gif_levelup file 'nextlevel.gif' |
||
1508 | .size = $ - gif_levelup |
||
1509 | gif_gameover file 'gameover.gif' |
||
1510 | .size = $ - gif_gameover |
||
950 | leency | 1511 | |
5188 | hidnplayr | 1512 | align 16 |
1513 | @IMPORT: |
||
950 | leency | 1514 | |
5188 | hidnplayr | 1515 | library \ |
1516 | libimg , 'libimg.obj' |
||
950 | leency | 1517 | |
5188 | hidnplayr | 1518 | import libimg , \ |
1519 | libimg.init , 'lib_init' , \ |
||
1520 | img.decode , 'img_decode' , \ |
||
1521 | img.to_rgb2 , 'img_to_rgb2', \ |
||
1522 | img.destroy , 'img_destroy' |
||
950 | leency | 1523 | |
1524 | |||
1525 | vscreen: |
||
5188 | hidnplayr | 1526 | dd SCREEN_X |
1527 | dd SCREEN_Y |
||
1528 | rb SCREEN_X*SCREEN_Y*3 |
||
950 | leency | 1529 | |
1530 | IM_END: |
||
1531 | |||
5188 | hidnplayr | 1532 | STARS rb STARS_*5 |
950 | leency | 1533 | |
5188 | hidnplayr | 1534 | img_bullet rb BULLET_X*BULLET_Y*3+8 |
1535 | img_bullet2 rb BULLET_X*BULLET_Y*3+8 |
||
1536 | img_ship rb SHIP_X*SHIP_Y*3+8 |
||
1537 | img_enemy1 rb ENEMY_X*ENEMY_Y*3+8 |
||
1538 | img_enemy2 rb ENEMY_X*ENEMY_Y*3+8 |
||
1539 | img_enemy3 rb ENEMY_X*ENEMY_Y*3+8 |
||
1540 | img_enemy4 rb ENEMY_X*ENEMY_Y*3+8 |
||
1541 | img_enemy5 rb ENEMY_X*ENEMY_Y*3+8 |
||
1542 | img_alien rb ALIEN_X*ALIEN_Y*3+8 |
||
1543 | img_menu1 rb 220*18*3+8 |
||
1544 | img_menu2 rb 135*18*3+8 |
||
1545 | img_menu3 rb 245*18*3+8 |
||
1546 | img_menu4 rb 110*18*3+8 |
||
1547 | img_logo rb 40*540*3+8 |
||
1548 | img_pause rb 40*320*3+8 |
||
1549 | img_levelup rb 40*320*3+8 |
||
1550 | img_gameover rb 40*320*3+8 |
||
1551 | img_highscore rb 40*530*3+8 |
||
1552 | img_smallfont rb 20*312*3+8 |
||
1553 | img_bigfont rb 28*520*3+8 |
||
1554 | img_numbers rb 16*200*3+8 |
||
950 | leency | 1555 | |
5188 | hidnplayr | 1556 | img_char rb 28*20*3+8 |
1557 | img_alienpiece rb ALIEN_X*ALIEN_Y*3+8 |
||
950 | leency | 1558 | |
5188 | hidnplayr | 1559 | highscorebuffer rb 1024 |
950 | leency | 1560 | |
5188 | hidnplayr | 1561 | I_END: |