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