Subversion Repositories Kolibri OS

Rev

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