Subversion Repositories Kolibri OS

Rev

Rev 1522 | Go to most recent revision | Details | Last modification | View Log | RSS feed

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