Subversion Repositories Kolibri OS

Compare Revisions

Regard whitespace Rev 1521 → Rev 1522

/programs/games/snake/trunk/level.asm
4,7 → 4,9
 
mov [score], 0
mov [action], 0
mov [number_of_free_dots], GRID_WIDTH*GRID_HEIGHT-3
mov eax, [gw_mul_gh]
sub eax, 3
mov [number_of_free_dots], ax
 
invoke ini.get_str, cur_dir_path, aScore, aChampion_name, champion_name, 15, champion_name
invoke ini.get_int, cur_dir_path, aScore, aHiscore, 0
16,9 → 18,12
 
mov esi, start_map
mov edi, field_map
mov ecx, GRID_WIDTH*GRID_HEIGHT/4
mov ecx, [gw_mul_gh]
shr ecx, 2
rep movsd
 
call Get_eat
 
Level_body:
;;===Level_body========================================================================================================
 
27,9 → 32,15
mov eax, [time_wait_limit]
mov [time_to_wait], eax
 
Redraw:
.redraw:
mcall 12,1
mcall 0,200*65536+WINDOW_WIDTH,326*65536+WINDOW_HEIGHT,[window_style], ,window_title
mov ebx, [wp_x]
shl ebx, 16
add ebx, dword[window_width]
mov ecx, [wp_y]
shl ecx, 16
add ecx, dword[window_height]
mcall 0, , ,[window_style], ,window_title
call Draw_decorations
call Draw_snake
38,7 → 49,7
 
mcall 12,2
Waiting:
.still:
mcall 26, 9
push eax
sub eax, [time_before_waiting]
59,19 → 70,19
mov [time_before_waiting], eax
mov eax, [time_wait_limit]
mov [time_to_wait], eax
jmp Waiting
jmp .still
@@:
 
Message: ; ok, what an event?
.message: ; ok, what an event?
dec al ; has the window been moved or resized?
jz Redraw ;
jz .redraw ;
dec al ; was a key pressed?
jz Key ;
jz .key ;
dec al ; was a button pressed?
jz Button ;
jz .button ;
 
 
Key:
.key:
mcall 2 ; get keycode
cmp ah, 0x1B ; Escape
79,64 → 90,60
cmp ah, 0x20 ; Space
je Pause_mode
cmp ah, 0xB0 ; Left
je .left
je .key.left
cmp ah, 0xB1 ; Down
je .down
je .key.down
cmp ah, 0xB2 ; Up
je .up
je .key.up
cmp ah, 0xB3 ; Right
je .right
je .key.right
jmp Waiting ; jump to wait for another event
jmp .still ; jump to wait for another event
.left:
cmp [action], 0
jne @f
.button: ; ¯à®æ¥¤ãà  ®¡à ¡®ª¨ ª­®¯®ª ¢ ¯à®£à ¬¬¥
mcall 17 ; äã­ªæ¨ï 17: ¯®«ãç¨âì ­®¬¥à ­ ¦ â®© ª­®¯ª¨
 
shr eax, 8 ; ᤢ¨£ ¥¬ ॣ¨áâà eax ­  8 ¡¨â ¢¯à ¢®, çâ®¡ë ¯®«ãç¨âì ­®¬¥à ­ ¦ â®© ª­®¯ª¨
cmp eax, 1
je Exit ; ¥á«¨ íâ® ­¥ ª­®¯ª  1 (§ à¥§¥à¢¨à®¢ ­  á¨á⥬®© ª ª ª­®¯ª  § ªàëâ¨ï ¯à®£à ¬¬ë), ¯à®¯ã᪠¥¬ 2 á«¥¤ãî騥 áâà®çª¨ ª®¤ 
 
jmp .still
 
 
.key.left:
bts dword[action], 0
jc @f
mov [time_to_wait], 0
@@:
mov [action], 1
mov [snake_napravlenie_next], 0
jmp Waiting
mov [snake_napravlenie_next], LEFT
jmp .still
.down:
cmp [action], 0
jne @f
.key.down:
bts dword[action], 0
jc @f
mov [time_to_wait], 0
@@:
mov [action], 1
mov [snake_napravlenie_next], 1
jmp Waiting
mov [snake_napravlenie_next], DOWN
jmp .still
.up:
cmp [action], 0
jne @f
.key.up:
bts dword[action], 0
jc @f
mov [time_to_wait], 0
@@:
mov [action], 1
mov [snake_napravlenie_next], 2
jmp Waiting
mov [snake_napravlenie_next], UP
jmp .still
.right:
cmp [action], 0
jne @f
.key.right:
bts dword[action], 0
jc @f
mov [time_to_wait], 0
@@:
mov [action], 1
mov [snake_napravlenie_next], 3
jmp Waiting
mov [snake_napravlenie_next], RIGHT
jmp .still
 
Button: ; ¯à®æ¥¤ãà  ®¡à ¡®ª¨ ª­®¯®ª ¢ ¯à®£à ¬¬¥
mcall 17 ; äã­ªæ¨ï 17: ¯®«ãç¨âì ­®¬¥à ­ ¦ â®© ª­®¯ª¨
 
shr eax, 8 ; ᤢ¨£ ¥¬ ॣ¨áâà eax ­  8 ¡¨â ¢¯à ¢®, çâ®¡ë ¯®«ãç¨âì ­®¬¥à ­ ¦ â®© ª­®¯ª¨
cmp eax, 1
je Exit ; ¥á«¨ íâ® ­¥ ª­®¯ª  1 (§ à¥§¥à¢¨à®¢ ­  á¨á⥬®© ª ª ª­®¯ª  § ªàëâ¨ï ¯à®£à ¬¬ë), ¯à®¯ã᪠¥¬ 2 á«¥¤ãî騥 áâà®çª¨ ª®¤ 
 
jmp Waiting
Game_step:
 
cmp [snake_napravlenie], LEFT ; are we moving to left?
192,7 → 199,8
dec al
cmp al, -1
jne @f
mov al, GRID_WIDTH-1
mov al, byte[g_w]
dec al
@@:
jmp Snake_move
 
200,7 → 208,7
mov [snake_napravlenie], DOWN
mov ax, [edx]
inc ah
cmp ah, GRID_HEIGHT
cmp ah, byte[g_h]
jne @f
mov ah, 0
@@:
212,7 → 220,8
dec ah
cmp ah, -1
jne @f
mov ah, GRID_HEIGHT-1
mov ah, byte[g_h]
dec ah
@@:
jmp Snake_move
220,7 → 229,7
mov [snake_napravlenie], RIGHT
mov ax, [edx]
inc al
cmp al, GRID_WIDTH
cmp al, byte[g_w]
jne @f
mov al, 0
@@:
274,16 → 283,21
Draw_level_strings:
;;===Draw_level_strings================================================================================================
 
call Draw_menu_esc
mov ebx, [window_width]
shr ebx, 1
sub ebx, (string_resume_space-string_pause_space-1)*3+6
shl ebx, 16
add ebx, [top_strings]
mcall 4, ,[navigation_strings_color],string_pause_space ; Draw 'PAUSE - SPACE' string
 
; call Draw_menu_esc
call Draw_score_string
call Draw_score_number ; Draw score (number)
call Draw_champion_string
call Draw_champion_name
call Draw_hiscore_string
call Draw_hiscore_number
call Draw_champion_string
call Draw_champion_name
 
mcall 4,225*65536+BOTTOM_MIDDLE_STRINGS,[navigation_strings_color],string_pause_space ; Draw 'PAUSE - SPACE' string
ret
 
;;---Draw_level_strings------------------------------------------------------------------------------------------------
299,16 → 313,13
add edi, [snake_length_x2]
 
@@:
 
mov ax, [edi]
xchg ax, [esi]
mov [edi], ax
 
dec cx
add esi, 2
sub edi, 2
 
test cx, cx
dec cx
jnz @b
 
ret
357,7 → 368,7
.place_found:
sub ebx, field_map
mov eax, ebx
mov bl, GRID_WIDTH
mov bl, byte[g_w]
div bl
xchg al, ah
391,36 → 402,40
mov ebx, snake_dots+2
 
mov cl, [eax] ; The last dot x_coord
mov dl, [ebx] ; The pre_last dot x_coord
mov ch, [ebx] ; The pre_last dot x_coord
 
cmp cl, dl
cmp cl, ch
je .X_ravny
cmp cl, 0
jne .skip2
cmp dl, 23
mov dl, byte[g_w]
dec dl
cmp ch, dl
jne .Normal_y_ravny
mov [snake_napravlenie_next], 3
mov [snake_napravlenie_next], RIGHT
ret
.skip2:
cmp cl, 23
mov dl, byte[g_w]
dec dl
cmp cl, dl
jne .Normal_y_ravny
cmp dl, 0
cmp ch, 0
jne .Normal_y_ravny
mov [snake_napravlenie_next], 0
mov [snake_napravlenie_next], LEFT
ret
.Normal_y_ravny:
 
cmp cl, dl
cmp cl, ch
jg .Napravlenie_to_right
mov [snake_napravlenie_next], 0
mov [snake_napravlenie_next], LEFT
ret
 
.Napravlenie_to_right:
mov [snake_napravlenie_next], 3
mov [snake_napravlenie_next], RIGHT
ret
 
.X_ravny:
427,33 → 442,37
inc eax
inc ebx
mov cl, [eax]
mov dl, [ebx]
mov ch, [ebx]
cmp cl, 0
jne .skip3
cmp dl, 10
mov dl, byte[g_h]
dec dl
cmp ch, dl
jne .Normal_x_ravny
mov [snake_napravlenie_next], 1
mov [snake_napravlenie_next], DOWN
ret
.skip3:
cmp cl, 10
mov dl, byte[g_h]
dec dl
cmp ch, dl
jne .Normal_x_ravny
cmp dl, 0
cmp ch, 0
jne .Normal_x_ravny
mov [snake_napravlenie_next], 2
mov [snake_napravlenie_next], UP
ret
.Normal_x_ravny:
 
cmp cl, dl ; !!!
cmp cl, ch ; !!!
jg .Napravlenie_to_down ; 0 1 2 ...
mov [snake_napravlenie_next], 2 ; 1
mov [snake_napravlenie_next], UP ; 1
ret ; 2
; .
.Napravlenie_to_down: ; .
mov [snake_napravlenie_next], 1 ; .
mov [snake_napravlenie_next], DOWN ; .
 
ret
 
489,9 → 508,14
 
.eat_and_new_head_are_different:
 
mov ecx, snake_dots-4
add ecx, [snake_length_x2]
push ax
 
mov ax, word[snake_dots]
mov cl, 0
call Draw_on_map
 
pop ax
 
call Get_from_map
test bl, bl
jnz Game_over
503,9 → 527,6
mov edx, [background_color]
call Draw_square
 
mov ax, word[snake_dots]
mov cl, 0
call Draw_on_map
call Sdvig
call Draw_head_prehead
522,8 → 543,8
mov [time_before_waiting], eax
mov eax, [time_wait_limit]
mov [time_to_wait], eax
jmp Waiting
jmp Level_body.still
 
;;---Snake_move--------------------------------------------------------------------------------------------------------
;;---Snake_move------------------------------------------------------------------------------------------------------------
 
;;---Some_functions------------------------------------------------------------------------------------------------------------