Subversion Repositories Kolibri OS

Rev

Rev 950 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. ;=============================================================================;
  2. ; Hidnplayr's invaders, Compilable for DexOs and Kolibrios                    ;
  3. ;-----------------------------------------------------------------------------;
  4. ;                                                                             ;
  5. ; Copyright (C) hidnplayr 2007. All rights reserved.                          ;
  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.  
  25.  
  26. SCREEN_X equ 640
  27. SCREEN_Y equ 480
  28.  
  29. SHIP_X equ 32
  30. SHIP_Y equ 32
  31.  
  32. SHIP_X_POS equ (SCREEN_X-SHIP_X)/2
  33. SHIP_Y_POS equ SCREEN_Y-SHIP_Y-27
  34.  
  35. ENEMY_X equ 32
  36. ENEMY_Y equ 32
  37.  
  38. ALIEN_X equ 48
  39. ALIEN_Y equ 38
  40. ALIEN_Y_POS equ 1
  41.  
  42. BOUNDARY equ 10
  43. MOVEMENT equ 7
  44.  
  45. TRANSPARENCY equ 0x00000000
  46.  
  47. WINDOW_X equ 100
  48. WINDOW_Y equ 100
  49.  
  50. BULLET_X equ 10
  51. BULLET_Y equ 10
  52.  
  53. STARS_   equ 226
  54. STARLEVELS equ 3
  55.  
  56. ENEMY_STARTING_X equ 25
  57. ENEMY_STARTING_Y equ 50
  58.  
  59. BULLETSPEED equ 12
  60.  
  61. SCREEN_X_POS equ 5
  62. SCREEN_Y_POS equ 25
  63.  
  64. gif_hash_offset = gif_hash_area
  65.  
  66. include 'ascgl.inc'
  67. include 'invaders_kolibri.inc'
  68.  
  69. decodegif:
  70.         giftoimg gif_bullet,bullet
  71.         giftoimg gif_bullet2,bullet2
  72.         giftoimg gif_ship,ship
  73.         giftoimg gif_enemy1,enemy1
  74.         giftoimg gif_enemy2,enemy2
  75.         giftoimg gif_enemy3,enemy3
  76.         giftoimg gif_enemy4,enemy4
  77.         giftoimg gif_enemy5,enemy5
  78.         giftoimg gif_alien,alien
  79.         giftoimg gif_menu1,menu1
  80.         giftoimg gif_menu2,menu2
  81.         giftoimg gif_menu3,menu3
  82.         giftoimg gif_menu4,menu4
  83.         giftoimg gif_logo,logo
  84.         giftoimg gif_pause,pause_
  85.         giftoimg gif_levelup,levelup
  86.         giftoimg gif_gameover,gameover
  87.         giftoimg gif_highscore,highscore
  88.         giftoimg gif_smallfont,smallfont
  89.         giftoimg gif_bigfont,bigfont
  90.         giftoimg gif_numbers,numbers
  91.  
  92.         call  createstars
  93.         call  drawit
  94.         call  [drawroutine]
  95.  
  96. mainloop:
  97.  
  98.     cmp  byte[status],3 ; if game is paused,...
  99.     je   waitfordraw
  100.  
  101.     call drawit
  102.     call [drawroutine]
  103.     call checkbullet
  104.  
  105.    waitfordraw:
  106.  
  107.     call waitandgetkey ;;;
  108.     test ah,ah
  109.     jz   mainloop
  110.  
  111.     cmp  byte[status],1      ;
  112.     jne  nogame
  113.  
  114.          cmp  ah, KEY_RIGHT
  115.          jnz  noright
  116.          cmp  dword[ship_x],SCREEN_X-SHIP_X-BOUNDARY
  117.          jge  mainloop
  118.          add  dword[ship_x],MOVEMENT
  119.  
  120.          jmp  mainloop
  121.  
  122.        noright:
  123.          cmp  ah, KEY_LEFT
  124.          jnz  noleft
  125.          cmp  dword[ship_x],BOUNDARY
  126.          jle  mainloop
  127.          sub  dword[ship_x],MOVEMENT
  128.  
  129.          jmp  mainloop
  130.  
  131.        noleft:
  132.          cmp  ah, KEY_UP
  133.          jnz  noup
  134.  
  135.          cmp  dword[bullet_y],1
  136.          jg   mainloop
  137.  
  138.          mov  eax,dword[ship_x]
  139.          add  eax,(SHIP_X-BULLET_X)/2
  140.          mov  dword[bullet_x],eax
  141.          mov  dword[bullet_y],SHIP_Y_POS;-BULLET_Y
  142.  
  143.          jmp  mainloop
  144.  
  145.        noup:
  146.          cmp  ah,KEY_P
  147.          jnz  no_pause1
  148.  
  149.          mov  byte[status],3
  150.          aimgtoimg pause_,150,180,vscreen,TRANSPARENCY,0
  151.          call [drawroutine]
  152.  
  153.          jmp  mainloop
  154.  
  155.        no_pause1:
  156.  
  157. nogame:
  158.     cmp  byte[status],0
  159.     jne  nomenu
  160.  
  161.          cmp  ah, KEY_DOWN
  162.          jnz  no_down
  163.  
  164.          cmp  byte[menu],3
  165.          jne  no_menu1
  166.  
  167.          mov  byte[menu],0
  168.          jmp  nomenu
  169.  
  170.        no_menu1:
  171.          inc  byte[menu]
  172.  
  173.        no_down:
  174.          cmp  ah, KEY_UP
  175.          jnz  no_up
  176.  
  177.          cmp  byte[menu],0
  178.          jne  no_menu0
  179.  
  180.          mov  byte[menu],3
  181.          jmp  nomenu
  182.  
  183.        no_menu0:
  184.          dec  byte[menu]
  185.  
  186.        no_up:
  187.  
  188.          cmp  ah, KEY_ESC
  189.          je   exit
  190.  
  191.        no_esc:
  192.          cmp  ah, KEY_ENTER
  193.          jnz  no_enter
  194.  
  195.         exemenu:
  196.                 cmp  byte[menu],0  ;start
  197.                 jne  exemenu1
  198.  
  199.               new_game:
  200.                         mov  dword[score],0
  201.                         mov  eax,[score]
  202.                         call convertscore
  203.  
  204.                         mov  esi, level1
  205.                         mov  word[levelnumb],'01'
  206.               load_level:
  207.                         mov  byte[enemy_speed],1
  208.                         mov  dword[enemy_x], ENEMY_STARTING_X
  209.                         mov  dword[enemy_y], ENEMY_STARTING_Y
  210.  
  211.                         mov  edi, enemy_table
  212.                         mov  ecx, 5
  213.                         rep  movsd
  214.  
  215.                         mov  byte[status],1
  216.  
  217.                         jmp  mainloop
  218.  
  219.         exemenu1:
  220.                 cmp  byte[menu],1  ;about
  221.                 jne  exemenu2
  222.                 mov  byte[status],4
  223.                 jmp  mainloop
  224.  
  225.         exemenu2:
  226.                 cmp  byte[menu],2  ;highscores
  227.                 jne  exemenu3
  228.                 mov  byte[status],5
  229.                 call load_highscores
  230.                 jmp  mainloop
  231.  
  232.         exemenu3:
  233.                 cmp  byte[menu],3  ;exit
  234.                 je   exit
  235.  
  236.       no_enter:
  237. nomenu:
  238.     cmp  byte[status],3
  239.     jne  nopause
  240.  
  241.     cmp  ah, KEY_P
  242.     jnz  nopause
  243.  
  244.     mov  byte[status],1
  245.  
  246. nopause:
  247.     cmp  byte[status],6
  248.     jne  nolevelup
  249.  
  250.     cmp  ah, KEY_ENTER
  251.     jne  nolevelup
  252.  
  253.         inc  byte[level]
  254.  
  255. ;        cmp  byte[level],5
  256. ;        jne  @f
  257. ;        mov  byte[level],0
  258.  
  259. ;@@:
  260.         inc  byte[levelnumb+1]
  261.         cmp  byte[levelnumb+1],'9'
  262.         jle  @f
  263.         mov  byte[levelnumb+1],'0'
  264.         inc  byte[levelnumb]
  265.  
  266.        @@:
  267.         mov  eax,20
  268.         mov  ah,byte[level]
  269.         and  ah,7
  270.         mul  ah
  271.         add  eax,level1
  272.         mov  esi,eax
  273.         jmp  load_level
  274.  
  275. nolevelup:
  276.     cmp  byte[status],7
  277.     jne  nohighscore
  278.  
  279.         cmp   ah, KEY_ENTER
  280.         jne   @f
  281.  
  282.         call  load_highscores
  283.         mov   eax,dword[score]
  284.         mov   ebx,gif_hash_area+140
  285.     .findscore:
  286.         cmp   ebx,gif_hash_area+100
  287.         je    .topscore
  288.         sub   ebx,4
  289.         cmp   eax,dword[ebx]
  290.         jg    .findscore
  291.  
  292.     .topscore:
  293.         mov   esi,name
  294.         mov   edi,gif_hash_area
  295.         mov   ecx,10
  296.         rep   movsb
  297.  
  298.         mov   eax,dword[score]
  299.         mov   dword[gif_hash_area+100],eax
  300.  
  301.         call  save_highscores
  302.         mov   byte[status],5
  303.  
  304. @@:
  305.         cmp   ah,14
  306.         jne   @f
  307.  
  308.         cmp   byte[namepos],0
  309.         je    @f
  310.  
  311.         dec   byte[namepos]
  312.         movzx ebx,byte[namepos]
  313.         add   ebx,name
  314.         mov   byte[ebx],0x11  ; this is a character we dont print
  315.  
  316. @@:
  317.         cmp   byte[namepos],10
  318.         jge   nohighscore
  319.  
  320.         cmp   al,'0'
  321.         jl    nohighscore
  322.         cmp   al,'9'
  323.         jle   @f
  324.  
  325.         cmp   al,'z'
  326.         jg    nohighscore
  327.         cmp   al,'a'
  328.         jge   @f
  329.  
  330.         cmp   al,'Z'
  331.         jg    nohighscore
  332.         cmp   al,'A'
  333.         jl    nohighscore
  334. @@:
  335.  
  336.         movzx ebx,byte[namepos]
  337.         add   ebx,name
  338.         mov   byte[ebx],al
  339.  
  340.         inc   byte[namepos]
  341.  
  342.         jmp   mainloop
  343.  
  344. nohighscore:
  345.     cmp  byte[status],2 ; gameover
  346.     jne  nogameover
  347.  
  348.     cmp  ah, KEY_ENTER
  349.     jne  nogameover
  350.  
  351.         ; test if score is high enough to put in highscore list...
  352.         mov   byte[status],7
  353.  
  354.         jmp   mainloop
  355.  
  356. nogameover:
  357.     cmp  byte[status],0
  358.     je   mainloop
  359.  
  360.     cmp  ah, KEY_ESC
  361.     jnz  mainloop
  362.  
  363.     mov  byte[status],0
  364.     mov  word[intro],0
  365.  
  366.     jmp  mainloop
  367.  
  368.  ;----------------------------------------------------;
  369.  ; Drawing routine: create image in buffer            ;
  370.  ;----------------------------------------------------;
  371. drawit:
  372.     mov  eax,0x00000000
  373.     call fillscreen
  374.     call drawstars
  375.  
  376.     cmp  byte[status],1
  377.     jne  @f
  378.  
  379.         call drawbullet
  380.         call drawenemys                                               ; Draw the enemy's to buffer
  381.         aimgtoimg ship,dword[ship_x],SHIP_Y_POS,vscreen,TRANSPARENCY,0  ; Draw the ship to buffer
  382.  
  383.         mov  esi,scoretext
  384.         mov  ebx,0
  385.         mov  ecx,SCREEN_Y-24
  386.         call printtext
  387.  
  388.         mov  esi,leveltext
  389.         mov  ebx,300
  390.         call printtext
  391.  
  392.     ret
  393.  
  394. @@:
  395.     cmp  byte[status],2 ; game over, dude !
  396.     jne  @f
  397.  
  398.         aimgtoimg ship,dword[ship_x],SHIP_Y_POS,vscreen,TRANSPARENCY,0  ; Draw the ship to buffer
  399.  
  400.         mov  esi,scoretext
  401.         mov  ebx,0
  402.         mov  ecx,SCREEN_Y-24
  403.         call printtext
  404.  
  405.         mov  esi,leveltext
  406.         mov  ebx,300
  407.         call printtext
  408.         aimgtoimg gameover,150,180,vscreen,TRANSPARENCY,0
  409.  
  410.         ret
  411.  
  412. @@:
  413.     cmp  byte[status],4 ; about screen
  414.     jne  @f
  415.  
  416.         mov  esi,msgAbout
  417.         mov  ebx,50
  418.         mov  ecx,100
  419.         call printtext
  420.  
  421.         ret
  422.  
  423. @@:
  424.     cmp  byte[status],6 ; level up!
  425.     jne  @f
  426.         aimgtoimg ship,dword[ship_x],SHIP_Y_POS,vscreen,TRANSPARENCY,0  ; Draw the ship to buffer
  427.  
  428.         mov  esi,scoretext
  429.         mov  ebx,0
  430.         mov  ecx,SCREEN_Y-24
  431.         call printtext
  432.  
  433.         mov  esi,leveltext
  434.         mov  ebx,300
  435.         call printtext
  436.         aimgtoimg levelup,150,180,vscreen,TRANSPARENCY,0
  437.  
  438.         ret
  439.  
  440. @@:
  441.     cmp  byte[status],0 ; menu!
  442.     jne  @f
  443.  
  444.         aimgtoimg logo,50,80,vscreen,TRANSPARENCY,0
  445.  
  446.  
  447.         cmp  byte[menu],0
  448.         jne  .menu_0
  449.         aimgtoimg menu1,30,200,vscreen,TRANSPARENCY,1
  450.         jmp  .menu_1
  451.     .menu_0:
  452.         aimgtoimg menu1,30,200,vscreen,TRANSPARENCY,0
  453.     .menu_1:
  454.         cmp  byte[menu],1
  455.         jne  .menu_2
  456.         aimgtoimg menu2,80,250,vscreen,TRANSPARENCY,1
  457.         jmp  .menu_3
  458.     .menu_2:
  459.         aimgtoimg menu2,80,250,vscreen,TRANSPARENCY,0
  460.     .menu_3:
  461.         cmp  byte[menu],2
  462.         jne  .menu_4
  463.         aimgtoimg menu3,120,300,vscreen,TRANSPARENCY,1
  464.         jmp  .menu_5
  465.     .menu_4:
  466.         aimgtoimg menu3,120,300,vscreen,TRANSPARENCY,0
  467.     .menu_5:
  468.         cmp  byte[menu],3
  469.         jne  .menu_6
  470.         aimgtoimg menu4,150,350,vscreen,TRANSPARENCY,1
  471.         jmp  .menu_7
  472.     .menu_6:
  473.         aimgtoimg menu4,150,350,vscreen,TRANSPARENCY,0
  474.     .menu_7:
  475.  
  476.         cmp  word[intro],200
  477.         je   .menu_75
  478.         inc  word[intro]
  479.  
  480.     .menu_75:
  481.         cmp  word[intro],0
  482.         jl   .menu_8
  483.         aimgtoimg enemy1,390,180,vscreen,TRANSPARENCY,0
  484.  
  485.         cmp  word[intro],15
  486.         jl   .menu_8
  487.         mov  esi,points_50
  488.         mov  ebx,470
  489.         mov  ecx,180
  490.         call printtext
  491.  
  492.         cmp  word[intro],30
  493.         jl   .menu_8
  494.         aimgtoimg enemy2,390,220,vscreen,TRANSPARENCY,0
  495.  
  496.         cmp  word[intro],45
  497.         jl   .menu_8
  498.         mov  esi,points_100
  499.         mov  ebx,450
  500.         mov  ecx,220
  501.         call printtext
  502.  
  503.         cmp  word[intro],60
  504.         jl   .menu_8
  505.         aimgtoimg enemy3,390,260,vscreen,TRANSPARENCY,0
  506.  
  507.         cmp  word[intro],75
  508.         jl   .menu_8
  509.         mov  esi,points_150
  510.         mov  ebx,450
  511.         mov  ecx,260
  512.         call printtext
  513.  
  514.         cmp  word[intro],90
  515.         jl   .menu_8
  516.         aimgtoimg enemy4,390,300,vscreen,TRANSPARENCY,0
  517.  
  518.         cmp  word[intro],105
  519.         jl   .menu_8
  520.         mov  esi,points_200
  521.         mov  ebx,450
  522.         mov  ecx,300
  523.         call printtext
  524.  
  525.         cmp  word[intro],120
  526.         jl   .menu_8
  527.         aimgtoimg enemy5,390,340,vscreen,TRANSPARENCY,0
  528.  
  529.         cmp  word[intro],135
  530.         jl   .menu_8
  531.         mov  esi,points_250
  532.         mov  ebx,450
  533.         mov  ecx,340
  534.         call printtext
  535.  
  536.         cmp  word[intro],150
  537.         jl   .menu_8
  538.         aimgtoimg alien,380,380,vscreen,TRANSPARENCY,0
  539.  
  540.         cmp  word[intro],165
  541.         jl   .menu_8
  542.         mov  esi,points_1000
  543.         mov  ebx,430
  544.         mov  ecx,380
  545.         call printtext
  546.  
  547.     .menu_8:
  548.         ret
  549. @@:
  550.     cmp  byte[status],5 ;highscorelist
  551.     jne  @f
  552.  
  553.         aimgtoimg highscore,60,40,vscreen,TRANSPARENCY,0
  554.  
  555.         mov  ebx,100                ; print names
  556.         mov  ecx,120
  557.         mov  esi,gif_hash_area
  558.         call printtext
  559.  
  560.         mov  edi,gif_hash_area+100  ; print scores
  561.         mov  esi,scorenumb
  562.         mov  ebx,420
  563.         mov  ecx,120
  564.  
  565. .highscoreloop:
  566.         mov  eax,[edi]
  567.         push ecx
  568.         call convertscore
  569.         pop  ecx
  570.         push esi
  571.         call printtext
  572.         pop  esi
  573.         add  ecx,26
  574.         add  edi,4
  575.         cmp  edi,gif_hash_area+140
  576.         jl  .highscoreloop
  577.  
  578. @@:
  579.     cmp  byte[status],7 ;highscore
  580.     jne  @f
  581.  
  582.         aimgtoimg highscore,60,40,vscreen,TRANSPARENCY,0
  583.  
  584.         mov  ebx,60
  585.         mov  ecx,200
  586.         mov  esi,entername
  587.         call printtext
  588.  
  589.         mov  ebx,250
  590.         mov  ecx,250
  591.         mov  esi,name
  592.         call printtext
  593.  
  594.         mov  esi,scoretext
  595.         mov  ebx,0
  596.         mov  ecx,SCREEN_Y-24
  597.         call printtext
  598.  
  599.         mov  esi,leveltext
  600.         mov  ebx,300
  601.         call printtext
  602. @@:
  603.  
  604.     ret
  605.  
  606.  
  607. drawenemys:
  608. ; check if direction should change
  609.         test byte[enemy_d],2
  610.         jz   @f
  611.  
  612.         add  dword[enemy_y],5
  613.  
  614.         mov  eax,[enemy_y]
  615.         shr  eax,5
  616.         add  al, byte[level]
  617.         mov  byte[enemy_speed],al
  618.  
  619.         and  byte[enemy_d],1
  620.  
  621.        @@:
  622. ; move the aliens to left or right
  623.         movzx eax,byte[enemy_speed]
  624.         test byte[enemy_d],1
  625.         jz   other_dir
  626.  
  627.         sub  dword[enemy_x],eax
  628.         jmp  no_other_dir
  629.  
  630.      other_dir:
  631.         add  dword[enemy_x],eax
  632.      no_other_dir:
  633.  
  634. ; initialization
  635.         mov  byte[alldeadb],1
  636.         mov  edi,enemy_table
  637.         mov  eax,dword[enemy_x]
  638.         mov  dword[current_enemy_x],eax
  639.         mov  eax,dword[enemy_y]
  640.         mov  dword[current_enemy_y],eax
  641.  
  642.      loopit:
  643.         cmp  byte[edi],1
  644.         je   drawenemy1
  645.  
  646.         cmp  byte[edi],2
  647.         je   drawenemy2
  648.  
  649.         cmp  byte[edi],3
  650.         je   drawenemy3
  651.  
  652.         cmp  byte[edi],4
  653.         je   drawenemy4
  654.  
  655.         cmp  byte[edi],5
  656.         je   drawenemy5
  657.  
  658.         jmp  dead_alien
  659.  
  660.      drawenemy1:
  661.         mov  byte[alldeadb],0
  662.         pusha
  663.         aimgtoimg enemy1,dword[current_enemy_x],dword[current_enemy_y],vscreen,TRANSPARENCY,0
  664.         popa
  665.  
  666.         jmp  checknext
  667.  
  668.      drawenemy2:
  669.         mov  byte[alldeadb],0
  670.         pusha
  671.         aimgtoimg enemy2,dword[current_enemy_x],dword[current_enemy_y],vscreen,TRANSPARENCY,0
  672.         popa
  673.  
  674.         jmp  checknext
  675.  
  676.      drawenemy3:
  677.         mov  byte[alldeadb],0
  678.         pusha
  679.         aimgtoimg enemy3,dword[current_enemy_x],dword[current_enemy_y],vscreen,TRANSPARENCY,0
  680.         popa
  681.  
  682.         jmp  checknext
  683.  
  684.      drawenemy4:
  685.         mov  byte[alldeadb],0
  686.         pusha
  687.         aimgtoimg enemy4,dword[current_enemy_x],dword[current_enemy_y],vscreen,TRANSPARENCY,0
  688.         popa
  689.  
  690.         jmp  checknext
  691.  
  692.      drawenemy5:
  693.         mov  byte[alldeadb],0
  694.         pusha
  695.         aimgtoimg enemy5,dword[current_enemy_x],dword[current_enemy_y],vscreen,TRANSPARENCY,0
  696.         popa
  697.  
  698. ;        jmp  checknext
  699.  
  700.      checknext:
  701.         cmp  byte[enemy_d],2
  702.         jge  dont_change_dir
  703.  
  704.            movzx eax,byte[enemy_speed]
  705.  
  706.            cmp  byte[enemy_d],0
  707.            jbe  change_dir
  708.  
  709.            cmp  dword[current_enemy_x],eax
  710.            jg   dont_change_dir
  711.  
  712.            mov  byte[enemy_d],2
  713.  
  714.            jmp  dont_change_dir
  715.  
  716.         change_dir:
  717.            mov  ebx, SCREEN_X-ENEMY_X
  718.            sub  ebx, eax
  719.            cmp  dword[current_enemy_x],ebx
  720.            jl   dont_change_dir
  721.  
  722.            mov  byte[enemy_d],3
  723.  
  724.         dont_change_dir:
  725.            cmp  dword[current_enemy_y],SHIP_Y_POS-ENEMY_Y-BOUNDARY
  726.            je   gameover_
  727.  
  728.      dead_alien:
  729.         cmp  edi,enemy_table+20
  730.         jge  alldead
  731.  
  732.         inc  edi
  733.         add  dword[current_enemy_x],ENEMY_X+BOUNDARY
  734.         mov  eax,dword[current_enemy_x]
  735.         sub  eax,dword[enemy_x]
  736.         cmp  eax,5*(ENEMY_X+BOUNDARY)
  737.         jl   no_newline
  738.  
  739.         sub  dword[current_enemy_x],5*(ENEMY_X+BOUNDARY)
  740.         add  dword[current_enemy_y],ENEMY_Y+BOUNDARY
  741.       no_newline:
  742.         jmp  loopit
  743.  
  744.      alldead:
  745.         cmp  byte[alldeadb],0
  746.         je   enemy_end
  747.  
  748.         mov  byte[status],6
  749.         jmp  mainloop
  750.  
  751.      enemy_end:
  752. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  753.         cmp  dword[alien_x],5                                                     ;
  754.         jge  @f
  755.  
  756.         call random_generator
  757.         cmp  eax,0xffffffff/50 ; one out of 500 chances that it appears during this frame
  758.         jl   alien_end
  759.  
  760.         mov  dword [alien_x],SCREEN_X-ALIEN_X
  761.  
  762.        @@:
  763.         push  eax
  764.  
  765.         mov  eax, SCREEN_X                                                                                                                                                                                                                                 ;        mov  eax, SCREEN_X
  766.         sub  eax, dword [alien_x]
  767.  
  768.         cmp  eax, ALIEN_X
  769.         jle  @f
  770.         mov  eax, ALIEN_X
  771.        @@:
  772.  
  773.         getimg alien,0,0,10,ALIEN_Y,alienpiece
  774.         aimgtoimg alien,dword [alien_x],ALIEN_Y_POS,vscreen,TRANSPARENCY,0
  775.         sub  dword[alien_x],5                                                     ;
  776.                                                                                   ;
  777.         pop  eax                                                                  ;
  778.                                                                                   ;
  779.       alien_end:                                                                  ;
  780.                                                                                   ;
  781. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  782.         ret
  783.  
  784. drawbullet:
  785.         cmp  dword[bullet_y],BULLETSPEED
  786.         jl   nobullet
  787.         sub  dword[bullet_y],BULLETSPEED
  788.  
  789.         aimgtoimg bullet,dword[bullet_x],dword[bullet_y],vscreen,TRANSPARENCY,0
  790.  
  791.       nobullet:
  792.         ret
  793.  
  794. checkbullet:
  795.         cmp  dword[bullet_y],BULLETSPEED                              ; does the bullet hit top of the screen?
  796.         jle  hidebullet                                               ; yes, hide bullet
  797.  
  798. ;        ; check if bullet is inside the enemy field (you can disble this if you want)
  799. ;        mov  eax,dword[enemy_y]
  800. ;        cmp  dword[bullet_y],eax
  801. ;        jl   nohit
  802. ;
  803. ;        add  eax,4*(ENEMY_Y+BOUNDARY)
  804. ;        cmp  dword[bullet_y],eax
  805. ;        jg   nohit
  806. ;
  807. ;        mov  eax,dword[enemy_x]
  808. ;        cmp  dword[bullet_x],eax
  809. ;        jl   nohit
  810. ;
  811. ;        add  eax,5*(ENEMY_Y+BOUNDARY)
  812. ;        cmp  dword[bullet_x],eax
  813. ;        jg   nohit
  814. ;
  815.         mov  edi,enemy_table
  816.         mov  eax,dword[enemy_x]
  817.         mov  dword[current_enemy_x],eax
  818.         mov  eax,dword[enemy_y]
  819.         mov  dword[current_enemy_y],eax
  820.  
  821.        check:
  822.         cmp  byte[edi],0                 ; is the enemy at this position alive?
  823.         je   nextcheck                   ; no, try next enemy
  824.         ; check if bullet hits current enemy
  825.  
  826.         mov  eax,dword[current_enemy_y]  ; move the enemy y position into eax
  827.         cmp  dword[bullet_y],eax         ; is the bullet's y position less than eax (enemy y pos)
  828.         jl   nextcheck                   ; yes, bullet can't be colliding, check next enemy
  829.  
  830.         add  eax,ENEMY_Y                 ; add the width of the enemy to the enemy's y position (wich is still stored in eax)
  831.         cmp  dword[bullet_y],eax         ; is the bullet's y position greater than eax (the end of the enemy)
  832.         jg   nextcheck                   ; yes, bullet can't be colliding, check next enemy
  833.  
  834.         mov  eax,dword[current_enemy_x]  ; now do the same but for the x positions
  835.         cmp  dword[bullet_x],eax         ;
  836.         jl   nextcheck                   ;
  837.                                          ;
  838.         add  eax,ENEMY_Y                 ;
  839.         cmp  dword[bullet_x],eax         ;
  840.         jg   nextcheck                   ;
  841.  
  842.         jmp  hit
  843.  
  844.       nextcheck:
  845.         inc  edi
  846.         add  dword[current_enemy_x],ENEMY_X+BOUNDARY
  847.         mov  eax,dword[current_enemy_x]
  848.         sub  eax,dword[enemy_x]
  849.         cmp  eax,5*(ENEMY_X+BOUNDARY)
  850.         jl   no_newline_
  851.  
  852.         sub  dword[current_enemy_x],5*(ENEMY_X+BOUNDARY)
  853.         add  dword[current_enemy_y],ENEMY_Y+BOUNDARY
  854.       no_newline_:
  855.  
  856.         cmp  edi,enemy_table+20         ; is this the last enemy?
  857.         jg   nohit                      ; yes, none of them was hit
  858.         jmp  check                      ; no, check if enemy is alive and draw it
  859.  
  860.       hit:
  861.         movzx ebx,byte[edi]             ; mov the enemy number onto ebx
  862.         add  dword[score],ebx           ; add this number to the score dword
  863.  
  864.         mov  eax,[score]
  865.         call convertscore
  866.  
  867.         mov  byte[edi],0                ; hide the enemy
  868.      hidebullet:
  869.         mov  dword[bullet_y],1          ; mov the bullet to top of screen (hide it)
  870.         jmp  noalienhit
  871.  
  872.      nohit:
  873.         mov  eax,[alien_x]              ; check if we hit the big alien in the ufo
  874.         cmp  [bullet_x],eax
  875.         jl   noalienhit
  876.         add  eax,ALIEN_X-BULLET_X
  877.         cmp  [bullet_x],eax
  878.         jg   noalienhit
  879.         cmp  [bullet_y],ALIEN_Y_POS+ALIEN_Y
  880.         jg   noalienhit
  881.  
  882.         add  dword[score],100/5
  883.         mov  eax,[score]
  884.         call convertscore
  885.  
  886.         mov  [alien_x],0
  887.  
  888.      noalienhit:
  889.  
  890. ret
  891.  
  892. convertscore:
  893.         test al,1
  894.         jz   .1
  895.         mov  byte[scorenumb+5],'5'
  896.         jmp  .2
  897. .1:
  898.         mov  byte[scorenumb+5],'0'
  899. .2:
  900.         shr  eax,1
  901.         mov  ecx,10
  902.         xor  edx,edx
  903.         div  ecx
  904.         add  dl,'0'
  905.         mov  byte[scorenumb+4],dl
  906.         xor  edx,edx
  907.         div  ecx
  908.         add  dl,'0'
  909.         mov  byte[scorenumb+3],dl
  910.         xor  edx,edx
  911.         div  ecx
  912.         add  dl,'0'
  913.         mov  byte[scorenumb+2],dl
  914.         xor  edx,edx
  915.         div  ecx
  916.         add  dl,'0'
  917.         mov  byte[scorenumb+1],dl
  918.         xor  edx,edx
  919.         div  ecx
  920.         add  dl,'0'
  921.         mov  byte[scorenumb+0],dl
  922.  
  923. ret
  924.  
  925.  
  926. fillscreen: ; eax - screen color ( 0x00RRGGBB )
  927.  
  928.         mov  edi,vscreen+8
  929.         cld
  930.         mov  ecx,SCREEN_X*SCREEN_Y
  931.     .lab1:
  932.         mov  [edi],eax
  933.         add  edi,3
  934.         loop .lab1
  935.  
  936.         ret
  937.  
  938.  
  939. printtext:
  940.         push  ebx
  941.  
  942.      loadbyte:
  943.         movzx eax, byte[esi]
  944.         test  eax, eax
  945.         jnz   checkbyte
  946.  
  947.         pop   ebx
  948.  
  949.         ret
  950.  
  951.     checkbyte:
  952.         cmp  al,13
  953.         je   nextline
  954.         cmp  al,' '
  955.         je   space
  956.  
  957.         cmp  al,'0'
  958.         jl   nextchar
  959.         cmp  al,'9'
  960.         jle  usenumbers
  961.  
  962.         cmp  al,'z'
  963.         jg   nextchar
  964.         cmp  al,'a'
  965.         jge  usesmallfont
  966.  
  967.         cmp  al,'Z'
  968.         jg   nextchar
  969.         cmp  al,'A'
  970.         jge  usebigfont
  971.  
  972.         jmp  nextchar
  973.  
  974.  
  975.     usesmallfont:
  976.         mov  edx,eax
  977.         sub  edx,'a'
  978.         mov  eax,12
  979.         mul  edx
  980.         mov  edx,eax
  981.  
  982.         pusha
  983.         getimg smallfont,0,edx,20,12,char
  984.         popa
  985.  
  986.         pusha
  987.         add  ecx,4
  988.         aimgtoimg char,ebx,ecx,vscreen,TRANSPARENCY,0
  989.         popa
  990.  
  991.         add  ebx,20
  992.  
  993.         jmp  nextchar
  994.  
  995.     usebigfont:
  996.         mov  edx,eax
  997.         sub  edx,'A'
  998.         mov  eax,20
  999.         mul  edx
  1000.         mov  edx,eax
  1001.  
  1002.         pusha
  1003.         getimg bigfont,0,edx,28,20,char
  1004.         popa
  1005.  
  1006.         pusha
  1007.         aimgtoimg char,ebx,ecx,vscreen,TRANSPARENCY,0
  1008.         popa
  1009.  
  1010.         add  ebx,28
  1011.  
  1012.         jmp  nextchar
  1013.  
  1014.     usenumbers:
  1015.         mov  edx,eax
  1016.         sub  edx,'0'
  1017.         mov  eax,20
  1018.         mul  edx
  1019.         mov  edx,eax
  1020.  
  1021.         pusha
  1022.         getimg numbers,0,edx,16,20,char
  1023.         popa
  1024.  
  1025.         pusha
  1026.         aimgtoimg char,ebx,ecx,vscreen,TRANSPARENCY,0
  1027.         popa
  1028.  
  1029.         add  ebx,20
  1030.  
  1031.         jmp  nextchar
  1032.  
  1033.     space:
  1034.         add  ebx,20
  1035.  
  1036.     nextchar:
  1037.         inc  esi
  1038.  
  1039.         jmp  loadbyte
  1040.  
  1041.     nextline:
  1042.         pop  ebx
  1043.         push ebx
  1044.         add  ecx,26
  1045.         inc  esi
  1046.  
  1047.         jmp  loadbyte
  1048.  
  1049. gameover_:
  1050.     mov  byte[status],2
  1051.  
  1052.     ret
  1053.  
  1054.  
  1055. drawstars:
  1056.     mov   esi, STARS
  1057.  
  1058. .loop:
  1059.     cmp   esi, STARS+(STARS_*5)
  1060.     jge   .done
  1061.  
  1062.     movzx eax, byte[esi]    ; z (speed, brightness)
  1063.     movzx ebx, word[esi+1]  ; x
  1064.     movzx ecx, word[esi+3]  ; y
  1065.     add   bx , ax
  1066.     cmp   bx , SCREEN_X
  1067.     jl    .moveit
  1068.  
  1069.     xor   ebx,ebx
  1070.     inc   ebx
  1071.  
  1072.     call  random_generator
  1073.     mov   ecx, [generator]
  1074.     and   ecx, SCREEN_Y-1
  1075.     inc   ecx
  1076.     mov   word[esi+3],cx
  1077.  
  1078.     call  random_generator
  1079.     and   al, STARLEVELS
  1080.     test  al,al
  1081.     jnz   @f
  1082.     inc   al
  1083.    @@:
  1084.     mov   [esi],al
  1085.  
  1086. .moveit:
  1087.     mov   word [esi+1],bx
  1088.  
  1089.     movzx eax, byte[esi]
  1090.     inc   eax
  1091.     mov   edx, 0xff/(STARLEVELS+1)
  1092.     mul   edx
  1093.  
  1094.     mov   ah,al
  1095.     shl   eax,8
  1096.     mov   al,ah
  1097.     mov   ebp, eax
  1098.  
  1099.     mov   eax, SCREEN_X
  1100.     mul   ecx
  1101.     add   eax, ebx
  1102.     mov   edx, 3
  1103.     mul   edx
  1104.  
  1105.     cmp   eax, SCREEN_X*SCREEN_Y*3
  1106.     jg    @f
  1107.     add   eax, vscreen+8
  1108.     and   dword[eax],0xff000000
  1109.     or    dword[eax],ebp
  1110.    @@:
  1111.  
  1112.     add   esi, 5
  1113.     jmp   .loop
  1114. .done:
  1115.  
  1116.     ret
  1117.  
  1118.  
  1119. createstars:
  1120.  
  1121.     mov   ebx, STARS
  1122. .loop:
  1123.     cmp   ebx, STARS+(STARS_*5)
  1124.     jge   .done
  1125.  
  1126.     call  random_generator
  1127.     and   al, STARLEVELS
  1128.     test  al,al
  1129.     jnz   @f
  1130.     inc   al
  1131.    @@:
  1132.     mov   byte[ebx],al
  1133.  
  1134.     call  random_generator
  1135.     and   eax, SCREEN_X-1
  1136.     inc   eax
  1137.     mov   word[ebx+1],ax
  1138.  
  1139.     call  random_generator
  1140.     and   eax, SCREEN_Y-1
  1141.     inc   eax
  1142.     mov   word[ebx+3],ax
  1143.  
  1144.     add   ebx, 5
  1145.     jmp   .loop
  1146. .done:
  1147.  
  1148.     ret
  1149.  
  1150.  
  1151. random_generator:  ; (pseudo random, actually :)
  1152.  
  1153.     xor   eax,[generator]
  1154.     imul  eax,214013
  1155.     xor   eax,0xdeadbeef
  1156.     rol   eax,9
  1157.     mov   [generator],eax
  1158.     ror   eax,16
  1159.     and   eax,0x7fff
  1160.  
  1161.     ret
  1162.  
  1163.  
  1164.  
  1165.  
  1166. level1:
  1167. db 4,4,4,4,4
  1168. db 3,3,3,3,3
  1169. db 2,2,2,2,2
  1170. db 1,1,1,1,1
  1171.  
  1172. level2:
  1173. db 4,1,3,1,4
  1174. db 4,3,2,3,4
  1175. db 0,4,1,4,0
  1176. db 0,0,2,0,0
  1177.  
  1178. level3:
  1179. db 1,5,5,5,1
  1180. db 1,2,2,2,1
  1181. db 3,1,2,1,3
  1182. db 4,3,1,3,4
  1183.  
  1184. level4:
  1185. db 4,5,2,5,4
  1186. db 5,3,3,3,5
  1187. db 4,5,4,5,4
  1188. db 1,5,5,5,1
  1189.  
  1190. level5:
  1191. db 5,4,3,4,5
  1192. db 5,4,4,4,5
  1193. db 4,5,4,5,4
  1194. db 3,5,1,5,3
  1195.  
  1196. level6:
  1197. db 1,2,5,4,5
  1198. db 5,4,5,2,1
  1199. db 1,2,5,4,5
  1200. db 1,1,5,1,1
  1201.  
  1202. level7:
  1203. db 1,2,3,2,1
  1204. db 1,3,3,3,1
  1205. db 3,4,3,4,3
  1206. db 5,5,5,5,5
  1207.  
  1208. level8:
  1209. db 1,2,3,4,5
  1210. db 3,5,3,5,4
  1211. db 4,2,3,2,3
  1212. db 5,4,3,2,1
  1213.  
  1214. enemy_table:
  1215. db 0,0,0,0,0
  1216. db 0,0,0,0,0
  1217. db 0,0,0,0,0
  1218. db 0,0,0,0,0
  1219.  
  1220.  
  1221. msg1            db 'Vesa mode not supported',13,'Press any key to exit.',13,0
  1222. msgAbout        db 'Hidnplayrs invaders',13,'KolibriOS version',13,13,'released under GPL',13,'make this game better',13,'if you want to',0
  1223. msgdone         db 'You have saved the planet!',0
  1224. entername       db 'Enter your name highscorer!',0
  1225. highscorefile   db 'invaders.dat',0
  1226. points_50       db '5 pt',0
  1227. points_100      db '10 pt',0
  1228. points_150      db '15 pt',0
  1229. points_200      db '20 pt',0
  1230. points_250      db '25 pt',0
  1231. points_1000     db '100 pt',0
  1232. ship_x          dd SHIP_X_POS
  1233. enemy_x         dd 0
  1234. enemy_y         dd 0
  1235. enemy_d         db 0
  1236. current_enemy_x dd 0
  1237. current_enemy_y dd 0
  1238. bullet_x        dd 0
  1239. bullet_y        dd 1
  1240. score           dd 0
  1241. alldeadb        db 0
  1242. status          db 0        ; status: 0=menu  1=game  2=gameover   3=paused  4=about 5=highscorelist 6=levelup 7=highscore...
  1243. menu            db 0        ; menu:   0=start 1=about 2=highscores 3=exit...
  1244. generator       dd 0x45dd4d15
  1245. alien_x         dd 0
  1246. drawroutine     dd 0
  1247. returnaddr      dd 0
  1248. intro           dw 0
  1249. scoretext       db 'score '
  1250. scorenumb       db 0,0,0,0,0,0,0
  1251. leveltext       db 'level '
  1252. levelnumb       db 0,0,0
  1253. lives           db 0
  1254. level           db 1
  1255. enemy_speed     db 1
  1256. namepos         db 0
  1257. name            db 0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x0d,0x00
  1258.  
  1259.  
  1260. gif_bullet    file 'bullet2.gif'
  1261. rb 4
  1262.  
  1263. gif_bullet2   file 'bullet2.gif'
  1264. rb 4
  1265.  
  1266. gif_ship      file 'ship.gif'
  1267. rb 4
  1268.  
  1269. gif_enemy1    file 'enemy1.gif'
  1270. rb 4
  1271.  
  1272. gif_enemy2    file 'enemy2.gif'
  1273. rb 4
  1274.  
  1275. gif_enemy3    file 'enemy3.gif'
  1276. rb 4
  1277.  
  1278. gif_enemy4    file 'enemy4.gif'
  1279. rb 4
  1280.  
  1281. gif_enemy5    file 'enemy5.gif'
  1282. rb 4
  1283.  
  1284. gif_alien     file 'alien.gif'
  1285. rb 4
  1286.  
  1287. gif_menu1     file 'menu1.gif'
  1288. rb 4
  1289.  
  1290. gif_menu2     file 'menu2.gif'
  1291. rb 4
  1292.  
  1293. gif_menu3     file 'menu3.gif'
  1294. rb 4
  1295.  
  1296. gif_menu4     file 'menu4.gif'
  1297. rb 4
  1298.  
  1299. gif_logo      file 'logo.gif'
  1300. rb 4
  1301.  
  1302. gif_pause     file 'pause.gif'
  1303. rb 4
  1304.  
  1305. gif_highscore file 'highscores.gif'
  1306. rb 4
  1307.  
  1308. gif_smallfont file 'font_small.gif'
  1309. rb 4
  1310.  
  1311. gif_bigfont   file 'font_capital.gif'
  1312. rb 4
  1313.  
  1314. gif_numbers   file 'numbers.gif'
  1315. rb 4
  1316.  
  1317. gif_levelup   file 'nextlevel.gif'
  1318. rb 4
  1319.  
  1320. gif_gameover  file 'gameover.gif'
  1321. rb 4
  1322.  
  1323. vscreen:
  1324. dd SCREEN_X
  1325. dd SCREEN_Y
  1326. rb SCREEN_X*SCREEN_Y*3+10
  1327.  
  1328. IM_END:
  1329.  
  1330. STARS:
  1331. rb STARS_*5
  1332.  
  1333. bullet:
  1334. rb BULLET_X*BULLET_Y*3+8+10
  1335.  
  1336. bullet2:
  1337. rb BULLET_X*BULLET_Y*3+8+10
  1338.  
  1339. ship:
  1340. rb SHIP_X*SHIP_Y*3+10
  1341.  
  1342. enemy1:
  1343. rb ENEMY_X*ENEMY_Y*3+10
  1344.  
  1345. enemy2:
  1346. rb ENEMY_X*ENEMY_Y*3+10
  1347.  
  1348. enemy3:
  1349. rb ENEMY_X*ENEMY_Y*3+10
  1350.  
  1351. enemy4:
  1352. rb ENEMY_X*ENEMY_Y*3+10
  1353.  
  1354. enemy5:
  1355. rb ENEMY_X*ENEMY_Y*3+10
  1356.  
  1357. alien:
  1358. rb ALIEN_X*ALIEN_Y*3+10
  1359.  
  1360. menu1:
  1361. rb 220*18*3+10
  1362.  
  1363. menu2:
  1364. rb 135*18*3+10
  1365.  
  1366. menu3:
  1367. rb 245*18*3+10
  1368.  
  1369. menu4:
  1370. rb 110*18*3+10
  1371.  
  1372. logo:
  1373. rb 40*540*3+10
  1374.  
  1375. pause_:
  1376. rb 40*320*3+10
  1377.  
  1378. levelup:
  1379. rb 40*320*3+10
  1380.  
  1381. gameover:
  1382. rb 40*320*3+10
  1383.  
  1384. highscore:
  1385. rb 40*530*3+10
  1386.  
  1387. smallfont:
  1388. rb 20*312*3+10
  1389.  
  1390. bigfont:
  1391. rb 28*520*3+10
  1392.  
  1393. numbers:
  1394. rb 16*200*3+10
  1395.  
  1396. char:
  1397. rb 28*20*3+20 ; biggest char's are 28x20
  1398.  
  1399. alienpiece:
  1400. rb ALIEN_X*ALIEN_Y*3+20
  1401.  
  1402. gif_hash_area:
  1403. rd 4096+1                          ;hash area size for unpacking GIF
  1404.  
  1405. I_END:
  1406.  
  1407. ;include 'dex.inc'
  1408.  
  1409.