Subversion Repositories Kolibri OS

Rev

Rev 1522 | Rev 1677 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1518 dunkaist 1
;;===Level_mode================================================================================================================
2
 
3
Level_begin:
4
 
1566 dunkaist 5
      call      Load_level
1522 dunkaist 6
      call      Get_eat
7
 
1518 dunkaist 8
Level_body:
9
    ;;===Level_body========================================================================================================
10
 
1566 dunkaist 11
      call      Hide_cursor
1518 dunkaist 12
mcall     26, 9
13
    mov  [time_before_waiting], eax
14
    mov  eax, [time_wait_limit]
15
    mov  [time_to_wait],    eax
16
 
1522 dunkaist 17
  .redraw:
1518 dunkaist 18
      mcall     12,1
1522 dunkaist 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
1518 dunkaist 26
 
27
      call      Draw_decorations
1566 dunkaist 28
      call      Draw_stones
1518 dunkaist 29
      call      Draw_snake
30
      call      Draw_eat
31
      call      Draw_level_strings
32
 
33
      mcall     12,2
34
 
1522 dunkaist 35
  .still:
1518 dunkaist 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
1522 dunkaist 56
     jmp .still
1518 dunkaist 57
  @@:
58
 
1522 dunkaist 59
      .message:                                 ; ok, what an event?
1518 dunkaist 60
        dec  al                                 ; has the window been moved or resized?
1522 dunkaist 61
         jz  .redraw                            ;
1518 dunkaist 62
        dec  al                                 ; was a key pressed?
1522 dunkaist 63
         jz  .key                               ;
1518 dunkaist 64
        dec  al                                 ; was a button pressed?
1522 dunkaist 65
         jz  .button                            ;
1518 dunkaist 66
 
67
 
1566 dunkaist 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
 
1522 dunkaist 78
  .key:
1518 dunkaist 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
1522 dunkaist 86
     je  .key.left
1518 dunkaist 87
    cmp  ah,  0xB1                              ; Down
1522 dunkaist 88
     je  .key.down
1518 dunkaist 89
    cmp  ah,  0xB2                              ; Up
1522 dunkaist 90
     je  .key.up
1518 dunkaist 91
    cmp  ah,  0xB3                              ; Right
1522 dunkaist 92
     je  .key.right
1518 dunkaist 93
 
1522 dunkaist 94
     jmp .still                                 ; jump to wait for another event
95
 
96
 
97
  .key.left:
1566 dunkaist 98
    bts  [action],  0
1522 dunkaist 99
     jc  @f
1518 dunkaist 100
    mov  [time_to_wait],    0
101
  @@:
1566 dunkaist 102
    mov  [snake_direction_next],    LEFT
1522 dunkaist 103
     jmp .still
1518 dunkaist 104
 
1522 dunkaist 105
  .key.down:
1566 dunkaist 106
    bts  [action],  0
1522 dunkaist 107
     jc  @f
1518 dunkaist 108
    mov  [time_to_wait],    0
109
  @@:
1566 dunkaist 110
    mov  [snake_direction_next],    DOWN
1522 dunkaist 111
     jmp .still
1518 dunkaist 112
 
1522 dunkaist 113
  .key.up:
1566 dunkaist 114
    bts  [action],  0
1522 dunkaist 115
     jc  @f
1518 dunkaist 116
    mov  [time_to_wait],    0
117
  @@:
1566 dunkaist 118
    mov  [snake_direction_next],    UP
1522 dunkaist 119
     jmp .still
1518 dunkaist 120
 
1522 dunkaist 121
  .key.right:
1566 dunkaist 122
    bts  [action],  0
1522 dunkaist 123
     jc  @f
1518 dunkaist 124
    mov  [time_to_wait],    0
125
  @@:
1566 dunkaist 126
    mov  [snake_direction_next],    RIGHT
1522 dunkaist 127
     jmp .still
1518 dunkaist 128
 
129
 
130
  Game_step:
131
 
1566 dunkaist 132
    cmp  [snake_direction], LEFT                ; are we moving to left?
1518 dunkaist 133
     jz  .left
1566 dunkaist 134
    cmp  [snake_direction], DOWN                ; ... down?
1518 dunkaist 135
     jz  .down
1566 dunkaist 136
    cmp  [snake_direction], UP                  ; ... up?
1518 dunkaist 137
     jz  .up
138
     jmp .right                                 ; then right
139
 
140
  .left:
1566 dunkaist 141
    cmp  [snake_direction_next],    RIGHT       ; next step is to right?
142
     jz  .with_reverse
143
     jmp .without_reverse
1518 dunkaist 144
 
145
  .down:
1566 dunkaist 146
    cmp  [snake_direction_next],    UP          ; next step is to up?
147
     jz  .with_reverse
148
     jmp .without_reverse
1518 dunkaist 149
 
150
  .up:
1566 dunkaist 151
    cmp  [snake_direction_next],    DOWN        ; next step is to bottom?
152
     jz  .with_reverse
153
     jmp .without_reverse
1518 dunkaist 154
 
155
  .right:
1566 dunkaist 156
    cmp  [snake_direction_next],    LEFT        ; next step is to left?
157
     jz  .with_reverse
158
     jmp .without_reverse
1518 dunkaist 159
 
160
 
1566 dunkaist 161
  .with_reverse:
162
      call      Set_reverse_direction
1518 dunkaist 163
      call      Reverse
164
 
1566 dunkaist 165
  .without_reverse:
1518 dunkaist 166
    mov  edx, snake_dots-2
167
    add  edx, [snake_length_x2]
168
 
1566 dunkaist 169
    cmp  [snake_direction_next],    LEFT
1518 dunkaist 170
     je  .to_left
1566 dunkaist 171
    cmp  [snake_direction_next],    DOWN
1518 dunkaist 172
     je  .to_down
1566 dunkaist 173
    cmp  [snake_direction_next],    UP
1518 dunkaist 174
     je  .to_up
1566 dunkaist 175
    cmp  [snake_direction_next],    RIGHT
1518 dunkaist 176
     je  .to_right
177
 
178
      .to_left:
1566 dunkaist 179
        mov  [snake_direction], LEFT
1518 dunkaist 180
        mov  ax,  [edx]
181
        dec  al
182
        cmp  al,  -1
183
         jne @f
1566 dunkaist 184
        mov  al,  GRID_WIDTH
1522 dunkaist 185
        dec  al
1518 dunkaist 186
      @@:
187
         jmp Snake_move
188
 
189
      .to_down:
1566 dunkaist 190
        mov  [snake_direction], DOWN
1518 dunkaist 191
        mov  ax,  [edx]
192
        inc  ah
1566 dunkaist 193
        cmp  ah,  GRID_HEIGHT
1518 dunkaist 194
         jne @f
195
        mov  ah,  0
196
      @@:
197
         jmp Snake_move
198
 
199
      .to_up:
1566 dunkaist 200
        mov  [snake_direction], UP
1518 dunkaist 201
        mov  ax,  [edx]
202
        dec  ah
203
        cmp  ah,  -1
204
         jne @f
1566 dunkaist 205
        mov  ah,  GRID_HEIGHT
1522 dunkaist 206
        dec  ah
1518 dunkaist 207
      @@:
208
         jmp Snake_move
209
 
210
      .to_right:
1566 dunkaist 211
        mov  [snake_direction], RIGHT
1518 dunkaist 212
        mov  ax,  [edx]
213
        inc  al
1566 dunkaist 214
        cmp  al,  GRID_WIDTH
1518 dunkaist 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
 
1522 dunkaist 268
    mov  ebx, [window_width]
269
    shr  ebx, 1
1566 dunkaist 270
    sub  ebx, string_pause_space.size*3+6
1522 dunkaist 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
1518 dunkaist 276
    call    Draw_score_string
277
    call    Draw_score_number                   ; Draw score (number)
1522 dunkaist 278
    call    Draw_champion_string
279
    call    Draw_champion_name
1518 dunkaist 280
    call    Draw_hiscore_string
281
    call    Draw_hiscore_number
282
 
1566 dunkaist 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
 
1518 dunkaist 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
1522 dunkaist 324
    dec  cx
1518 dunkaist 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
1566 dunkaist 373
    mov  bl,  GRID_WIDTH
1518 dunkaist 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
 
1566 dunkaist 400
Set_reverse_direction:
401
    ;;===Set_reverse_direction==================================================================================================
1518 dunkaist 402
 
403
    mov  eax, snake_dots
404
    mov  ebx, snake_dots+2
405
 
406
    mov  cl,  [eax]                             ; The last dot x_coord
1522 dunkaist 407
    mov  ch,  [ebx]                             ; The pre_last dot x_coord
1518 dunkaist 408
 
1522 dunkaist 409
    cmp  cl,  ch
1518 dunkaist 410
     je  .X_ravny
411
 
412
    cmp  cl,  0
413
     jne .skip2
414
 
1566 dunkaist 415
    mov  dl,  GRID_WIDTH
1522 dunkaist 416
    dec  dl
417
    cmp  ch,  dl
1518 dunkaist 418
     jne .Normal_y_ravny
1566 dunkaist 419
    mov  [snake_direction_next],    RIGHT
1518 dunkaist 420
    ret
421
 
422
  .skip2:
1566 dunkaist 423
    mov  dl,  GRID_WIDTH
1522 dunkaist 424
    dec  dl
425
    cmp  cl,  dl
1518 dunkaist 426
     jne .Normal_y_ravny
1522 dunkaist 427
    cmp  ch,  0
1518 dunkaist 428
     jne .Normal_y_ravny
1566 dunkaist 429
    mov  [snake_direction_next],    LEFT
1518 dunkaist 430
    ret
431
 
432
  .Normal_y_ravny:
433
 
1522 dunkaist 434
    cmp  cl,  ch
1518 dunkaist 435
     jg  .Napravlenie_to_right
1566 dunkaist 436
    mov  [snake_direction_next],    LEFT
1518 dunkaist 437
    ret
438
 
439
  .Napravlenie_to_right:
1566 dunkaist 440
    mov  [snake_direction_next],    RIGHT
1518 dunkaist 441
    ret
442
 
443
  .X_ravny:
444
    inc  eax
445
    inc  ebx
446
    mov  cl,  [eax]
1522 dunkaist 447
    mov  ch,  [ebx]
1518 dunkaist 448
 
449
    cmp  cl,  0
450
     jne .skip3
451
 
1566 dunkaist 452
    mov  dl,  GRID_HEIGHT
1522 dunkaist 453
    dec  dl
454
    cmp  ch,  dl
1518 dunkaist 455
     jne .Normal_x_ravny
1566 dunkaist 456
    mov  [snake_direction_next],    DOWN
1518 dunkaist 457
    ret
458
 
459
  .skip3:
1566 dunkaist 460
    mov  dl,  GRID_HEIGHT
1522 dunkaist 461
    dec  dl
462
    cmp  ch,  dl
1518 dunkaist 463
     jne .Normal_x_ravny
1522 dunkaist 464
    cmp  ch,  0
1518 dunkaist 465
     jne .Normal_x_ravny
1566 dunkaist 466
    mov  [snake_direction_next],    UP
1518 dunkaist 467
    ret
468
 
469
  .Normal_x_ravny:
470
 
1522 dunkaist 471
    cmp  cl,  ch                                ; !!!
1518 dunkaist 472
     jg  .Napravlenie_to_down                   ; 0 1 2 ...
1566 dunkaist 473
    mov  [snake_direction_next],    UP          ; 1
1518 dunkaist 474
    ret                                         ; 2
475
                                                ; .
476
  .Napravlenie_to_down:                         ; .
1566 dunkaist 477
    mov  [snake_direction_next],    DOWN        ; .
1518 dunkaist 478
 
479
    ret
480
 
1566 dunkaist 481
    ;;---Set_reverse_direction--------------------------------------------------------------------------------------------------
1518 dunkaist 482
 
483
 
484
Snake_move:
1566 dunkaist 485
    ;;===Snake_move=============================================================================================================
1518 dunkaist 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
1566 dunkaist 498
    dec  [number_of_free_dots]
499
    cmp  [number_of_free_dots], 0
1518 dunkaist 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
 
1522 dunkaist 513
    push ax
514
 
515
    mov  ax,  word[snake_dots]
516
    mov  cl,  0
517
      call      Draw_on_map
1518 dunkaist 518
 
1522 dunkaist 519
    pop ax
520
 
1518 dunkaist 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
1522 dunkaist 531
 
1518 dunkaist 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
  @@:
1566 dunkaist 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
 
1518 dunkaist 551
      mcall     26, 9
552
    mov  [time_before_waiting], eax
553
    mov  eax, [time_wait_limit]
554
    mov  [time_to_wait],    eax
1522 dunkaist 555
     jmp Level_body.still
1518 dunkaist 556
 
1522 dunkaist 557
    ;;---Snake_move------------------------------------------------------------------------------------------------------------
1518 dunkaist 558
 
1566 dunkaist 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
 
1518 dunkaist 667
;;---Some_functions------------------------------------------------------------------------------------------------------------