Subversion Repositories Kolibri OS

Rev

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

  1. ;;===Level_mode================================================================================================================
  2.  
  3. Level_begin:
  4.  
  5.     mov  [score],   0
  6.     mov  [action],  0
  7.     mov  eax,   [gw_mul_gh]
  8.     sub  eax, 3
  9.     mov  [number_of_free_dots], ax
  10.  
  11.       invoke  ini.get_str, cur_dir_path, aScore, aChampion_name, champion_name, 15, champion_name
  12.       invoke  ini.get_int, cur_dir_path, aScore, aHiscore, 0
  13.      
  14.     test eax, eax
  15.      jz  @f
  16.     mov  dword  [hi_score],    eax
  17.   @@:
  18.  
  19.     mov  esi, start_map
  20.     mov  edi, field_map
  21.     mov  ecx, [gw_mul_gh]
  22.     shr  ecx, 2
  23.     rep  movsd
  24.  
  25.       call      Get_eat
  26.  
  27. Level_body:
  28.     ;;===Level_body========================================================================================================
  29.  
  30. mcall     26, 9
  31.     mov  [time_before_waiting], eax
  32.     mov  eax, [time_wait_limit]
  33.     mov  [time_to_wait],    eax
  34.  
  35.   .redraw:
  36.       mcall     12,1
  37.     mov  ebx, [wp_x]
  38.     shl  ebx, 16
  39.     add  ebx, dword[window_width]
  40.     mov  ecx, [wp_y]
  41.     shl  ecx, 16
  42.     add  ecx, dword[window_height]
  43.       mcall     0, , ,[window_style], ,window_title
  44.    
  45.       call      Draw_decorations
  46.       call      Draw_snake
  47.       call      Draw_eat
  48.       call      Draw_level_strings
  49.  
  50.       mcall     12,2
  51.    
  52.   .still:
  53.       mcall     26, 9
  54.     push eax
  55.     sub  eax, [time_before_waiting]
  56.     pop  [time_before_waiting]
  57.     cmp  [time_to_wait],    eax
  58.      jg  @f
  59.     cmp  [action],  0
  60.      jne Game_step
  61.   @@:
  62.     sub  [time_to_wait],    eax
  63.       mcall     23, [time_to_wait]              ;
  64.  
  65.     test al,  al
  66.      jnz  @f
  67.     cmp  [action],  0
  68.      jne Game_step
  69.       mcall     26, 9
  70.     mov  [time_before_waiting], eax
  71.     mov  eax, [time_wait_limit]
  72.     mov  [time_to_wait],    eax
  73.      jmp .still
  74.   @@:
  75.  
  76.       .message:                                 ; ok, what an event?
  77.         dec  al                                 ; has the window been moved or resized?
  78.          jz  .redraw                            ;
  79.         dec  al                                 ; was a key pressed?
  80.          jz  .key                               ;
  81.         dec  al                                 ; was a button pressed?
  82.          jz  .button                            ;
  83.  
  84.  
  85.   .key:
  86.       mcall     2                               ; get keycode
  87.    
  88.     cmp  ah,  0x1B                              ; Escape
  89.      je  First_menu
  90.     cmp  ah,  0x20                              ; Space
  91.      je  Pause_mode
  92.     cmp  ah,  0xB0                              ; Left
  93.      je  .key.left
  94.     cmp  ah,  0xB1                              ; Down
  95.      je  .key.down
  96.     cmp  ah,  0xB2                              ; Up
  97.      je  .key.up
  98.     cmp  ah,  0xB3                              ; Right
  99.      je  .key.right
  100.    
  101.      jmp .still                                 ; jump to wait for another event
  102.  
  103.  
  104.   .button:                                       ; ¯à®æ¥¤ãà  ®¡à ¡®ª¨ ª­®¯®ª ¢ ¯à®£à ¬¬¥
  105.       mcall     17                              ; äã­ªæ¨ï 17: ¯®«ãç¨âì ­®¬¥à ­ ¦ â®© ª­®¯ª¨
  106.  
  107.     shr  eax, 8                                 ; ᤢ¨£ ¥¬ ॣ¨áâà eax ­  8 ¡¨â ¢¯à ¢®, çâ®¡ë ¯®«ãç¨âì ­®¬¥à ­ ¦ â®© ª­®¯ª¨
  108.     cmp  eax, 1
  109.      je  Exit                                   ; ¥á«¨ íâ® ­¥ ª­®¯ª  1 (§ à¥§¥à¢¨à®¢ ­  á¨á⥬®© ª ª ª­®¯ª  § ªàëâ¨ï ¯à®£à ¬¬ë), ¯à®¯ã᪠¥¬ 2 á«¥¤ãî騥 áâà®çª¨ ª®¤ 
  110.  
  111.      jmp .still
  112.  
  113.  
  114.   .key.left:
  115.     bts  dword[action], 0
  116.      jc  @f
  117.     mov  [time_to_wait],    0
  118.   @@:
  119.     mov  [snake_napravlenie_next],  LEFT
  120.      jmp .still
  121.            
  122.   .key.down:
  123.     bts  dword[action], 0
  124.      jc  @f
  125.     mov  [time_to_wait],    0
  126.   @@:
  127.     mov  [snake_napravlenie_next],  DOWN
  128.      jmp .still
  129.            
  130.   .key.up:
  131.     bts  dword[action], 0
  132.      jc  @f
  133.     mov  [time_to_wait],    0
  134.   @@:
  135.     mov  [snake_napravlenie_next],  UP
  136.      jmp .still
  137.            
  138.   .key.right:
  139.     bts  dword[action], 0
  140.      jc  @f
  141.     mov  [time_to_wait],    0
  142.   @@:
  143.     mov  [snake_napravlenie_next],  RIGHT
  144.      jmp .still
  145.  
  146.  
  147.   Game_step:
  148.  
  149.     cmp  [snake_napravlenie],   LEFT            ; are we moving to left?
  150.      jz  .left
  151.     cmp  [snake_napravlenie],   DOWN            ; ... down?
  152.      jz  .down
  153.     cmp  [snake_napravlenie],   UP              ; ... up?
  154.      jz  .up
  155.      jmp .right                                 ; then right
  156.      
  157.   .left:
  158.     cmp  [snake_napravlenie_next],  RIGHT       ; next step is to right?
  159.      jz  .with_rewerse
  160.      jmp .without_rewerse
  161.  
  162.   .down:
  163.     cmp  [snake_napravlenie_next],  UP          ; next step is to up?
  164.      jz  .with_rewerse
  165.      jmp .without_rewerse
  166.      
  167.   .up:
  168.     cmp  [snake_napravlenie_next],  DOWN        ; next step is to bottom?
  169.      jz  .with_rewerse
  170.      jmp .without_rewerse
  171.  
  172.   .right:
  173.     cmp  [snake_napravlenie_next],  LEFT        ; next step is to left?
  174.      jz  .with_rewerse
  175.      jmp .without_rewerse
  176.  
  177.  
  178.   .with_rewerse:
  179.       call      Set_reverse_napravlenie
  180.       call      Reverse
  181.        
  182.   .without_rewerse:
  183. ;    mov  [time_to_wait],   0
  184.     mov  edx, snake_dots-2
  185.     add  edx, [snake_length_x2]
  186.        
  187.     cmp  [snake_napravlenie_next],  LEFT
  188.      je  .to_left
  189.     cmp  [snake_napravlenie_next],  DOWN
  190.      je  .to_down
  191.     cmp  [snake_napravlenie_next],  UP
  192.      je  .to_up
  193.     cmp  [snake_napravlenie_next],  RIGHT
  194.      je  .to_right    
  195.        
  196.       .to_left:
  197.         mov  [snake_napravlenie],   LEFT
  198.         mov  ax,  [edx]
  199.         dec  al
  200.         cmp  al,  -1
  201.          jne @f
  202.         mov  al,  byte[g_w]
  203.         dec  al
  204.       @@:
  205.          jmp Snake_move
  206.  
  207.       .to_down:
  208.         mov  [snake_napravlenie],   DOWN
  209.         mov  ax,  [edx]
  210.         inc  ah
  211.         cmp  ah,  byte[g_h]
  212.          jne @f
  213.         mov  ah,  0
  214.       @@:
  215.          jmp Snake_move
  216.        
  217.       .to_up:
  218.         mov  [snake_napravlenie],   UP
  219.         mov  ax,  [edx]
  220.         dec  ah
  221.         cmp  ah,  -1
  222.          jne @f
  223.         mov  ah,  byte[g_h]
  224.         dec  ah
  225.       @@:
  226.          jmp Snake_move
  227.        
  228.       .to_right:
  229.         mov  [snake_napravlenie],   RIGHT
  230.         mov  ax,  [edx]
  231.         inc  al
  232.         cmp  al,  byte[g_w]
  233.          jne @f
  234.         mov  al,  0
  235.       @@:
  236.          jmp Snake_move
  237.  
  238.     ;;---Level_body--------------------------------------------------------------------------------------------------------
  239.  
  240. ;;---Level_mode----------------------------------------------------------------------------------------------------------------
  241.  
  242.  
  243. ;;===Some_functions============================================================================================================
  244.  
  245. Draw_snake:
  246.     ;;===Draw_snake========================================================================================================
  247.    
  248.       call      Draw_head_prehead
  249.     mov  edx, [snake_color]
  250.     mov  esi, snake_dots-6
  251.     add  esi, [snake_length_x2]
  252.  
  253.   @@:
  254.     mov  bx,  [esi]
  255.     sub  esi, 2
  256.       call      Draw_square
  257.     cmp  esi, snake_dots-2
  258.      jne @b
  259.  
  260.     ret
  261.        
  262.     ;;---Draw_snake--------------------------------------------------------------------------------------------------------
  263.  
  264.  
  265. Draw_head_prehead:
  266.     ;;===Draw_head_prehead=================================================================================================
  267.  
  268.     mov  edx, [snake_head_color]
  269.     mov  esi, snake_dots-2
  270.     add  esi, [snake_length_x2]
  271.     mov  bx,  [esi]
  272.       call      Draw_square
  273.     sub  esi, 2
  274.     mov  bx,  [esi]
  275.     mov  edx, [snake_color]
  276.       call      Draw_square
  277.  
  278.     ret
  279.  
  280.     ;;---Draw_head_prehead-------------------------------------------------------------------------------------------------
  281.  
  282.  
  283. Draw_level_strings:
  284.     ;;===Draw_level_strings================================================================================================
  285.  
  286.     mov  ebx, [window_width]
  287.     shr  ebx, 1
  288.     sub  ebx, (string_resume_space-string_pause_space-1)*3+6
  289.     shl  ebx, 16
  290.     add  ebx, [top_strings]
  291.       mcall     4, ,[navigation_strings_color],string_pause_space ; Draw 'PAUSE - SPACE' string
  292.  
  293. ;    call    Draw_menu_esc
  294.     call    Draw_score_string
  295.     call    Draw_score_number                   ; Draw score (number)
  296.     call    Draw_champion_string
  297.     call    Draw_champion_name
  298.     call    Draw_hiscore_string
  299.     call    Draw_hiscore_number
  300.  
  301.     ret
  302.  
  303.     ;;---Draw_level_strings------------------------------------------------------------------------------------------------
  304.    
  305.    
  306. Reverse:
  307.     ;;===Reverse===========================================================================================================
  308.  
  309.     mov  ecx, [snake_length_x2]
  310.     shr  ecx, 2
  311.     mov  esi, snake_dots
  312.     mov  edi, snake_dots-2
  313.     add  edi, [snake_length_x2]
  314.  
  315.   @@:
  316.     mov  ax,  [edi]
  317.     xchg ax,  [esi]
  318.     mov  [edi], ax
  319.  
  320.     add  esi, 2
  321.     sub  edi, 2
  322.     dec  cx
  323.      jnz @b
  324.  
  325.     ret
  326.  
  327.     ;;---Reverse-----------------------------------------------------------------------------------------------------------
  328.        
  329.        
  330. Draw_eat:
  331.     ;;===Draw_eat==========================================================================================================
  332.        
  333.     mov  bx,  word[eat]
  334.     mov  edx, [eat_color]
  335.        
  336.     call    Draw_square
  337.        
  338.     ret
  339.        
  340.     ;;---Draw_eat----------------------------------------------------------------------------------------------------------
  341.  
  342.  
  343. Get_eat:
  344.     ;;===Get_eat===========================================================================================================
  345.     ;;  in  :
  346.     ;;
  347.     ;;  out :
  348.     ;;          ax  =   coord's of the eat square (al=x, ah=y)
  349.     ;;
  350.    
  351.       mcall     26,9
  352. ;    xor  eax, esp
  353.     shl  eax, 1
  354.     xor  edx, edx
  355.     div  word[number_of_free_dots]
  356.     mov  ebx, field_map
  357.  
  358.   .loop:
  359.     cmp  byte[ebx], 0
  360.      jne @f
  361.     test dx,  dx
  362.      jz  .place_found
  363.     dec  dx
  364.   @@:
  365.     inc  ebx
  366.      jmp .loop
  367.      
  368.   .place_found:
  369.     sub  ebx, field_map
  370.     mov  eax, ebx
  371.     mov  bl,  byte[g_w]
  372.     div  bl
  373.     xchg al,  ah
  374.    
  375.     mov  word[eat], ax
  376.  
  377.     ret
  378.  
  379.     ;;---Get_eat-----------------------------------------------------------------------------------------------------------
  380.  
  381.  
  382. Sdvig:
  383.     ;;===Sdvig=============================================================================================================
  384.  
  385.     mov  esi, snake_dots+2
  386.     mov  edi, snake_dots
  387.     mov  ecx, [snake_length_x2]
  388.     shr  ecx, 1
  389.    
  390.     cld
  391.     rep  movsw
  392.  
  393.     ret
  394.  
  395.     ;;---Sdvig-------------------------------------------------------------------------------------------------------------
  396.  
  397.  
  398. Set_reverse_napravlenie:
  399.     ;;===Set_reverse_napravlenie===========================================================================================
  400.  
  401.     mov  eax, snake_dots
  402.     mov  ebx, snake_dots+2
  403.  
  404.     mov  cl,  [eax]                             ; The last dot x_coord
  405.     mov  ch,  [ebx]                             ; The pre_last dot x_coord
  406.  
  407.     cmp  cl,  ch
  408.      je  .X_ravny
  409.    
  410.     cmp  cl,  0
  411.      jne .skip2
  412.    
  413.     mov  dl,  byte[g_w]
  414.     dec  dl
  415.     cmp  ch,  dl
  416.      jne .Normal_y_ravny
  417.     mov  [snake_napravlenie_next],  RIGHT
  418.     ret
  419.        
  420.   .skip2:
  421.     mov  dl,  byte[g_w]
  422.     dec  dl
  423.     cmp  cl,  dl
  424.      jne .Normal_y_ravny
  425.     cmp  ch,  0
  426.      jne .Normal_y_ravny
  427.     mov  [snake_napravlenie_next],  LEFT
  428.     ret
  429.    
  430.   .Normal_y_ravny:
  431.  
  432.     cmp  cl,  ch
  433.      jg  .Napravlenie_to_right
  434.     mov  [snake_napravlenie_next],  LEFT
  435.     ret
  436.  
  437.   .Napravlenie_to_right:
  438.     mov  [snake_napravlenie_next],  RIGHT
  439.     ret
  440.  
  441.   .X_ravny:
  442.     inc  eax
  443.     inc  ebx
  444.     mov  cl,  [eax]
  445.     mov  ch,  [ebx]
  446.    
  447.     cmp  cl,  0
  448.      jne .skip3
  449.    
  450.     mov  dl,  byte[g_h]
  451.     dec  dl
  452.     cmp  ch,  dl
  453.      jne .Normal_x_ravny
  454.     mov  [snake_napravlenie_next],  DOWN
  455.     ret
  456.        
  457.   .skip3:
  458.     mov  dl,  byte[g_h]
  459.     dec  dl
  460.     cmp  ch,  dl
  461.      jne .Normal_x_ravny
  462.     cmp  ch,  0
  463.      jne .Normal_x_ravny
  464.     mov  [snake_napravlenie_next],  UP
  465.     ret
  466.    
  467.   .Normal_x_ravny:
  468.  
  469.     cmp  cl,  ch                                ; !!!
  470.      jg  .Napravlenie_to_down                   ; 0 1 2 ...
  471.     mov  [snake_napravlenie_next],  UP          ; 1
  472.     ret                                         ; 2
  473.                                                 ; .
  474.   .Napravlenie_to_down:                         ; .
  475.     mov  [snake_napravlenie_next],  DOWN        ; .
  476.  
  477.     ret
  478.  
  479.     ;;---Set_reverse_napravlenie-------------------------------------------------------------------------------------------
  480.    
  481.    
  482. Snake_move:
  483.     ;;===Snake_move========================================================================================================
  484.     ;;  in  :
  485.     ;;           ax =   coord's of new head
  486.     ;;          edx =   snake_dots+[snake_length_x2]-2 (snake head)
  487.     ;;
  488.  
  489.     add  edx, 2
  490.     mov  [edx], ax
  491.     cmp  ax,  word[eat]
  492.      jne .eat_and_new_head_are_different
  493.  
  494.     add  [snake_length_x2], 2
  495.     add  [score],   SCORE_EAT
  496.     dec  word[number_of_free_dots]
  497.     cmp  word[number_of_free_dots], 0
  498.      je  Game_over
  499.     mov  ax,  word[eat]
  500.     mov  cl,  1
  501.       call      Draw_on_map
  502.       call      Draw_head_prehead
  503.       call      Get_eat
  504.       call      Draw_eat
  505.  
  506.      jmp Keys_done
  507.  
  508.  
  509.   .eat_and_new_head_are_different:
  510.  
  511.     push ax
  512.    
  513.     mov  ax,  word[snake_dots]
  514.     mov  cl,  0
  515.       call      Draw_on_map
  516.  
  517.     pop ax
  518.  
  519.       call      Get_from_map
  520.     test bl,  bl
  521.      jnz Game_over
  522.  
  523.     mov  cl,  1
  524.       call      Draw_on_map
  525.      
  526.     mov  bx,  word[snake_dots]
  527.     mov  edx, [background_color]
  528.       call      Draw_square
  529.    
  530.       call      Sdvig
  531.      
  532.       call      Draw_head_prehead
  533.  
  534.  
  535.   Keys_done:
  536.  
  537.     cmp  [score],   0
  538.      je  @f
  539.     dec  [score]
  540.       call      Draw_score_number
  541.   @@:
  542.       mcall     26, 9
  543.     mov  [time_before_waiting], eax
  544.     mov  eax, [time_wait_limit]
  545.     mov  [time_to_wait],    eax
  546.      jmp Level_body.still
  547.  
  548.     ;;---Snake_move------------------------------------------------------------------------------------------------------------
  549.  
  550. ;;---Some_functions------------------------------------------------------------------------------------------------------------