-
Notifications
You must be signed in to change notification settings - Fork 0
/
brickbreaker.asm
1879 lines (1547 loc) · 39.4 KB
/
brickbreaker.asm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
;::::: BRICK BREAKER GAME ::::::::
;Created by Farzeen Qaiser and Mubeen Qaiser
brick struct
brick_x dw 0
brick_y dw 0
brick_height dw 0
brick_width dw 0
brick_color dw 0
hits dw 0
brick ends
.model small
.stack 100h
.data
;----------- <x, y, height, width, color, hits> ;colors: yellow = 14, red = 12,
blank_brick brick <20,90,10,30,11,1> ; error handling (for special ball)
brick_11 brick <20, 90, 10, 30, 11, 1>
brick_12 brick <55, 90, 10, 30, 9, 1>
brick_13 brick <90, 90, 10, 30, 11, 1>
brick_14 brick <125, 90, 10, 30, 9, 1>
brick_15 brick <160, 90, 10, 30, 11, 1>
brick_16 brick <195, 90, 10, 30, 9, 1>
brick_17 brick <230, 90, 10, 30, 11, 1>
brick_18 brick <265, 90, 10, 30, 9, 1>
brick_21 brick <40, 75, 10, 30, 12, 1>
brick_22 brick <75, 75, 10, 30, 14, 1>
brick_23 brick <110, 75, 10, 30, 12, 1>
brick_24 brick <145, 75, 10, 30, 14, 1>
brick_25 brick <180, 75, 10, 30, 12, 1>
brick_26 brick <215, 75, 10, 30, 14, 1>
brick_27 brick <250, 75, 10, 30, 12, 1>
brick_31 brick <20, 60, 10, 30, 11, 1>
brick_32 brick <55, 60, 10, 30, 9, 1>
brick_33 brick <90, 60, 10, 30, 11, 1>
brick_34 brick <125,60, 10, 30, 9, 1>
brick_35 brick <160,60, 10, 30, 11, 1>
brick_36 brick <195,60, 10, 30, 9, 1>
brick_37 brick <230,60, 10, 30, 11, 1>
brick_38 brick <265,60, 10, 30, 9, 1>
brick_41 brick <40, 45, 10, 30, 12, 1>
brick_42 brick <75, 45, 10, 30, 14, 1>
brick_43 brick <110, 45, 10, 30, 12, 1>
brick_44 brick <145, 45, 10, 30, 14, 1>
brick_45 brick <180, 45, 10, 30, 12, 1>
brick_46 brick <215, 45, 10, 30, 14, 1>
brick_47 brick <250, 45, 10, 30, 12, 1>
brick_51 brick <20, 30, 10, 30, 11, 1>
brick_52 brick <55, 30, 10, 30, 9, 1>
brick_53 brick <90, 30, 10, 30, 11, 1>
brick_54 brick <125, 30, 10, 30, 9, 1>
brick_55 brick <160, 30, 10, 30, 11, 1>
brick_56 brick <195, 30, 10, 30, 9, 1>
brick_57 brick <230, 30, 10, 30, 11, 1>
brick_58 brick <265, 30, 10, 30, 9, 1>
blank_brick2 brick <20,90,10,30,11,1> ; error handling (for special ball)
;---
time_aux db 0
; ball settings
ball_x dw 90
ball_y dw 100
ball_size dw 5 ; width x height
ball_velocity_x dw 5 ; default settings = 5
ball_velocity_y dw 1 ; default settings = 1
ball_velocity_x_left dw -5
ball_velocity_x_right dw 5
draw_ball_x dw 0 ; for drawing round ball
draw_ball_y dw 0 ; for drawing round ball
ball_color db 12
b_up dw 0
b_down dw 0
b_left dw 0
b_right dw 0
old_ball_x dw 0 ; for clearing old ball
old_ball_y dw 0 ; for clearing old ball
window_width dw 310
window_height dw 200
window_bounds dw 10
; paddle initial position
paddle_x dw 140
paddle_y dw 180
; paddle charcteristics
paddle_height dw 5
paddle_width dw 60
paddle_color dw 6
paddle_velocity dw 10
; to clear the old paddle position
old_paddle_x dw 140
old_paddle_y dw 180
; used for hiting the ball in 3 different directions (left, right, up)
upper_limit dw 0
middle_limit2 dw 0
middle_limit1 dw 0
lower_limit dw 0
paddle_portion_length dw 20
names db 20 dup("$")
heart_lives dw 3
counter dw 0 ; for while loops
counter2 db 0 ; for while loops
output_counter db 0 ; for myoutput proc
str1 db "Score:$"
score dw 0
dev_mode dw 0
temp_color dw 0
temp_counter dw 0
level2_switch dw 0
level3_switch dw 0
gameover_switch dw 0
str2 db "GAME OVER!$"
str3 db "NEW GAME$"
str4 db "RESUME$"
str5 db "INSTRUCTIONS$"
str6 db "HIGH SCORE$"
str7 db "EXIT$"
str8 db "BRICK BREAKER GAME$"
str9 db "ENTER YOUR NAME$"
str10 db "INSTRUCTIONS$"
str11 db "LEFT KEY: MOVE PADDLE LEFT$"
str12 db "RIGHT KEY: MOVE PADDLE RIGHT$"
str13 db "PRESS ESCAPE TO GO BACK$"
str14 db "LEVEL 1$" ; for level selection menu
str15 db "LEVEL 2$" ; for level selection menu
str16 db "LEVEL 3$" ; for level selection menu
str17 db "NAME$"
str18 db "SCORES$"
str19 db "LEVEL$"
display_level db "LEVEL 0$" ; for scorebar
; special object variables
object_x dw 0
object_y dw 0
object_color db 13
old_object_y dw 0
object_size dw 5
special_object_switch dw 0
special_brick_count dw 0
; file handling variables
fname db "scores.txt", 0
fhandle dw ?
string_scores db 4 dup('$')
string_level db 2 dup ('$')
string_highscores db 100 dup('$')
.code
;--- draw pixel ---
draw_pixel macro row, col, color
MOV CX, col ;column
MOV DX, row ;row
MOV AL, color ;color
MOV AH, 0CH
INT 10H
endm
;------------------
;--- cursor reset ---
set_cursor macro row, columun
mov bh, 0
mov ah, 2
mov dh, row ;row
mov dl, columun ;column
int 10h
endm
;------------------
;--- print string ---
mymessage macro str0
mov dx, offset str0
mov ah, 9
int 21h
endm
;------------------
;--- print string ---
mymessage2 macro
mov dx, si
mov ah, 9
int 21h
endm
;------------------
;--- Draw box ---
draw_box macro top, bottom, left, right, color
mov ah, 6
mov al, 0
mov bh, color ; color
mov ch, top ; top row of window
mov cl, left ; left most column of window
mov dh, bottom ; Bottom row of window
mov dl, right ; Right most column of window
int 10h
endm
main proc
mov ax, @data
mov ds, ax
mov ax, 0
call username_input
;--- main menu ---
main_menu:
;--- video mode (graphic)
mov ah, 0
mov al, 13h ;320x200
int 10h
;--- set background black
mov ax, 0
mov ah, 0Bh
mov bh, 00
mov bl, 00
int 10h
set_cursor 2, 10 ; prints brick breaker game
mymessage str8
;--- Initial setup ---
draw_box 5, 7, 10, 27, 11 ; new game box
draw_box 9, 11, 10, 27, 11 ; resume box
draw_box 13, 15, 10, 27, 11 ; instructions box
draw_box 17, 19, 10, 27, 11 ; high scores box
draw_box 21, 23, 10, 27, 11 ; exit box
set_cursor 6, 15 ; new game
mymessage str3
set_cursor 10, 15 ; resume
mymessage str4
set_cursor 14, 15 ; instructions
mymessage str5
set_cursor 18, 15 ; high scores
mymessage str6
set_cursor 22, 15 ; exit
mymessage str7
;---------------------------------------
;--- Interactive Setup ---
newgame:
draw_box 21, 23, 10, 27, 11 ; exit box ; blue
set_cursor 22, 15 ; exit
mymessage str7
draw_box 5, 7, 10, 27, 10 ; new game box ; green
set_cursor 6, 15 ; new game
mymessage str3
draw_box 9, 11, 10, 27, 11 ; resume box ; blue
set_cursor 10, 15 ; resume
mymessage str4
call beep
mov ah,0 ; key input
int 16h
cmp ah, 48h
je exit ;<---- select exit tab when up key is pressed
cmp ah, 50h
je resume ;<---- select resume tab when down key is pressed
cmp al, 13
je start_game ;<---- start game when Enter key is pressed
resume:
draw_box 5, 7, 10, 27, 11 ; new game box ; blue
set_cursor 6, 15 ; new game
mymessage str3
draw_box 9, 11, 10, 27, 10 ; resume box ; green
set_cursor 10, 15 ; resume
mymessage str4
draw_box 13, 15, 10, 27, 11 ; instructions box ; blue
set_cursor 14, 15 ; instructions
mymessage str5
call beep
mov ah,0 ; key input
int 16h
cmp ah, 48h
je newgame ;<---- select newgame tab when up key is pressed
cmp ah, 50h
je instructions ;<---- select instructions tab when down key is pressed
cmp al, 13
je resume_game ;<---- resume/unpause game when Enter key is pressed
instructions:
draw_box 9, 11, 10, 27, 11 ; resume box ; blue
set_cursor 10, 15 ; resume
mymessage str4
draw_box 13, 15, 10, 27, 10 ; instructions box ; green
set_cursor 14, 15 ; instructions
mymessage str5
draw_box 17, 19, 10, 27, 11 ; high scores box ; blue
set_cursor 18, 15 ; high scores
mymessage str6
call beep
mov ah,0 ; key input
int 16h
cmp ah, 48h
je resume ;<---- select resume tab when up key is pressed
cmp ah, 50h
je highscores ;<---- select highscores tab when down key is pressed
cmp al, 13
je instructions_page
highscores:
draw_box 13, 15, 10, 27, 11 ; instructions box ; blue
set_cursor 14, 15 ; instructions
mymessage str5
draw_box 17, 19, 10, 27, 10 ; high scores box ; green
set_cursor 18, 15 ; high scores
mymessage str6
draw_box 21, 23, 10, 27, 11 ; exit box ; blue
set_cursor 22, 15 ; exit
mymessage str7
call beep
mov ah,0 ; key input
int 16h
cmp ah, 48h
je instructions ;<---- select instructions tab when up key is pressed
cmp ah, 50h
je exit ;<---- select exit tab when down key is pressed
cmp al, 13
je highscores_page
exit:
draw_box 17, 19, 10, 27, 11 ; high scores box ; blue
set_cursor 18, 15 ; high scores
mymessage str6
draw_box 21, 23, 10, 27, 10 ; exit box ; green
set_cursor 22, 15 ; exit
mymessage str7
draw_box 5, 7, 10, 27, 11 ; new game box ; blue
set_cursor 6, 15 ; new game
mymessage str3
call beep
mov ah,0 ; key input
int 16h
cmp ah, 48h
je highscores ;<---- select highscores tab when up key is pressed
cmp ah, 50h
je newgame ;<---- select newgame tab when down key is pressed
cmp al, 13
je exit_game ;<---- exit game when Enter key is pressed
jmp newgame ;<------------ error handling (whenever a different key is pressed, other than arrow up and arrow down)
;--- main menu end ---
instructions_page:
;--- video mode (graphic)
mov ah, 0
mov al, 13h ;320x200
int 10h
;--- set background black
mov ax, 0
mov ah, 0Bh
mov bh, 00
mov bl, 00
int 10h
set_cursor 2, 10 ; prints brick breaker game
mymessage str8
set_cursor 6, 13
mymessage str10
set_cursor 8, 4
mymessage str11
set_cursor 10, 4
mymessage str12
set_cursor 22, 8
mymessage str13
mov ah, 00h ; checks which key is pressed
int 16h
cmp ah, 01h ; go to main menu when escape is pressed
je main_menu
jmp instructions_page
highscores_page:
;--- video mode (graphic)
mov ah, 0
mov al, 13h ;320x200
int 10h
;--- set background black
mov ax, 0
mov ah, 0Bh
mov bh, 00
mov bl, 00
int 10h
set_cursor 2, 10 ; prints brick breaker game
mymessage str8
set_cursor 6, 4 ; prints "NAME"
mymessage str17
set_cursor 6, 16 ; prints "SCORES"
mymessage str18
set_cursor 6, 28 ; prints "LEVEL"
mymessage str19
call read_file
mov si, offset string_highscores
mov counter2, 8
.while (counter2 < 12)
set_cursor counter2, 4 ; prints Player names
mymessage2
call index_moving
set_cursor counter2, 16 ; prints Player scores
mymessage2
call index_moving
set_cursor counter2, 28 ; prints Player level#
mymessage2
call index_moving
inc counter2
.endw
set_cursor 22, 8 ; prints "press escape to go back"
mymessage str13
mov ah, 00h ; checks which key is pressed
int 16h
cmp ah, 01h ; go to main menu when escape is pressed
je main_menu
jmp highscores_page
start_game:
;--- video mode (graphic)
mov ah, 0
mov al, 13h ;320x200
int 10h
;--- set background black
mov ax, 0
mov ah, 0Bh
mov bh, 00
mov bl, 00
int 10h
set_cursor 2, 10 ; prints brick breaker game
mymessage str8
level1_label:
draw_box 13, 15, 10, 27, 11 ; level3 box ; blue
set_cursor 14, 15
mymessage str16
draw_box 5, 7, 10, 27, 10 ; level1 box ; green
set_cursor 6, 15
mymessage str14
draw_box 9, 11, 10, 27, 11 ; level2 box ; blue
set_cursor 10, 15
mymessage str15
call beep
mov ah,0 ; key input
int 16h
cmp ah, 48h
je level3_label ;<---- select level3 tab when up key is pressed
cmp ah, 50h
je level2_label ;<---- select level2 tab when down key is pressed
cmp al, 13
je jump_level1 ;<---- Enter level1 game
level2_label:
draw_box 5, 7, 10, 27, 11 ; level1 box ; blue
set_cursor 6, 15
mymessage str14
draw_box 9, 11, 10, 27, 10 ; level2 box ; green
set_cursor 10, 15
mymessage str15
draw_box 13, 15, 10, 27, 11 ; level3 box ; blue
set_cursor 14, 15
mymessage str16
call beep
mov ah,0 ; key input
int 16h
cmp ah, 48h
je level1_label ;<---- select level1 tab when up key is pressed
cmp ah, 50h
je level3_label ;<---- select level3 tab when down key is pressed
cmp al, 13
je jump_level2 ;<---- Enter level2 game
level3_label:
draw_box 9, 11, 10, 27, 11 ; level2 ; blue
set_cursor 10, 15
mymessage str15
draw_box 13, 15, 10, 27, 10 ; level3 box ; green
set_cursor 14, 15
mymessage str16
draw_box 5, 7, 10, 27, 11 ; level1 box ; blue
set_cursor 6, 15
mymessage str14
call beep
mov ah,0 ; key input
int 16h
cmp ah, 48h
je level2_label ;<---- select level2 tab when up key is pressed
cmp ah, 50h
je level1_label ;<---- select level1 tab when down key is pressed
cmp al, 13
je jump_level3 ;<---- Enter level3 game
jmp start_game
;--- used for the "New Game" tab feature
;--- reset the game level 1 --- ; ERROR: once the brick is broken, I can't visaully redraw it.
jump_level1:
call level_1
jmp skip_level
jump_level2:
call level_2
jmp skip_level
jump_level3:
call level_3
skip_level:
;----------------------
resume_game: ; label used to resume/unpause the game
;video mode (graphic)
mov ah, 0
mov al, 13h ;320x200
int 10h
call map ;<-------- call map here
;--- MAIN GAME LOOP ---
game_loop:
mov ah, 2ch
int 21h ; ch = hour, cl = minute, dh = second, dl = 1/100 seconds
cmp dl, time_aux
je game_loop
mov time_aux, dl ; update time
;--- paddle functionality ---
call move_paddle
call draw_paddle
;----------------------------
;--- Dev Mode ---
.if (dev_mode == 1)
call control_ball
.endif
;--- ball functionality ---
call move_ball
call clear_ball
call draw_ball
;--------------------------
;--- special object ---
.if (special_object_switch == 1)
call draw_special_object
call special_object
call clear_special_object
.endif
;-----------------------
call score_bar ; draws score bar
.if (score == 6)
mov paddle_width, 60
mov paddle_portion_length, 20
mov paddle_velocity, 10
mov paddle_color, 6
.endif
;--- move to level 2 when score == 38 ---
.if (score >= 38) && (level2_switch == 0) ; 38 blocks, 1 score each (38)
call level_2
inc score
mov level2_switch, 1
mov ball_color, 12
.endif
;--- move to level 3 when score == 115 ---
.if (score >= 115) && (level3_switch == 0) ; 38 blocks, 2 score ech (115)
call level_3
inc score
mov level3_switch, 1
.endif
;--- move to Game Over screen when score == 192 ---
.if (score >= 180) ; game end... you win (192)
jmp exit_game
.endif
;--- move to Game Over screen when heart_lives == 0 ---
.if (heart_lives < 1) ; 0 hearts, game over
jmp exit_game
.endif
;--- key inputs ---
mov ah, 01h
int 16h
jz skip_controls ; checks if key is pressed
mov ah, 00h ; checks which key is pressed
int 16h
cmp al, 8 ; exit when back space is pressed
je exit_game
cmp ah, 01h ; pause game when escape key is pressed/ go to menu
je main_menu
.if(al == "z") ; special ball activated
mov ball_color, 13
.elseif (al == "x") ; special ball deactivated
mov ball_color, 12
.elseif (al == "o") ; control ball activated
mov dev_mode, 1
.elseif (al == "p") ; control ball deactivated
mov dev_mode, 0
.endif
skip_controls:
;--------------------------------------
jmp game_loop
exit_game:
call exit_menu
call write_file
mov ah, 4ch
int 21h
main endp
;--- put colors in loop for resume to work --- (Important!!!!!)
level_1 proc
mov si, offset brick_11
;--- 1 hit bricks ---
.while (counter < 38)
mov ax, 1
mov [si+10], ax ; brick hits = 1
inc counter
add si, 12 ; move to next brick
.endw
;--------------------
mov counter, 0
mov score, 0
mov ball_x, 10
mov ball_y, 105 ; last digit should be 5
mov ball_velocity_x, 5
mov ball_velocity_y, 1
mov heart_lives, 3
mov paddle_x, 140
mov paddle_width, 60
mov paddle_portion_length, 20
mov paddle_velocity, 10
mov si, offset brick_14
mov ax, 13
mov [si+8], ax
mov si, offset brick_15
mov ax, 13
mov [si+8], ax
mov si, offset brick_16
mov ax, 13
mov [si+8], ax
mov string_level, "1"
mov display_level[6], "1"
ret
level_1 endp
level_2 proc
mov si, offset brick_11 ;<---- set blocks to double hit
;--- 2 hit bricks
mov counter, 0
.while (counter < 38) ;<---- not sure should be equal to 38//////////////
mov ax, 2
mov [si+10], ax ; brick hits = 2
mov ax, 14 ; 14 = yellow color
mov [si+8], ax ; brick color = yellow
inc counter
add si, 12 ; move to next brick
.endw
mov counter, 0
mov ball_x, 20
mov ball_y, 105 ; last digit should be 5
mov ball_velocity_x, 5 ;<---- increase ball speed
mov ball_velocity_y, 5
inc heart_lives ;<---- increase health when move to next level
mov paddle_x, 60 ;<---- setting initial coordinates of the paddle
mov paddle_width, 30 ;<---- reduce size of paddle in level 2
mov paddle_portion_length, 10 ;<---- reduce size of paddle in level 2
mov paddle_velocity, 20
mov paddle_color, 6
;---- to erase the old paddle and ball, redraw black screen ---
;--- video mode (graphic)
mov ah, 0
mov al, 13h ;320x200
int 10h
;--- set background black
mov ax, 0
mov ah, 0Bh
mov bh, 00
mov bl, 00
int 10h
call map ;<----- redraws map after clearing level 1
mov string_level, "2"
mov display_level[6], "2"
ret
level_2 endp
level_3 proc
call level_2 ;<---- error handling: called level 2 for direct selection of level 3 (new game tab ---> level 3 tab)
mov si, offset brick_11 ;<---- set blocks to triple hit
;--- 3 hit blocks ---
mov counter, 0
.while (counter < 8) ;<---- lower 8 bricks are 3 hit bricks
; reset brick hits
mov ax, 3
mov [si+10], ax ; brick hits = 3
mov ax, 11 ; 11 = cyan
mov [si+8], ax ; brick color = cyan
inc counter
add si, 12 ; move to next brick
.endw
mov counter, 0
;--------------------
;--- unbreakable blocks ---
mov si, offset brick_21
.while (counter < 4) ;<---- not sure should be equal to 38//////////////
; reset brick hits
mov ax, 100
mov [si+10], ax
; set color grey
mov ax, 7
mov [si+8], ax
inc counter
add si, 24
.endw
;-------------------------
mov counter, 0
mov ball_x, 10
mov ball_y, 105 ; last digit should be 5
mov ball_velocity_y, 5
mov ball_velocity_x, 10 ;<---- increase ball speed
mov ball_velocity_x_left, -10
mov ball_velocity_x_right, 10
inc heart_lives ;<---- increase health when move to next level
mov paddle_x, 100 ;<---- setting initial coordinates of the paddle
mov paddle_width, 60 ;<---- reset size of paddle in level 3
mov paddle_portion_length, 20 ;<---- reset size of paddle in level 3
mov paddle_velocity, 20
mov paddle_color, 6
;---- to erase the old paddle and ball, redraw black screen ---
;--- video mode (graphic)
mov ah, 0
mov al, 13h ;320x200
int 10h
;--- set background black
mov ax, 0
mov ah, 0Bh
mov bh, 00
mov bl, 00
int 10h
;--- special brick ---
mov si, offset brick_11
mov ax, 15
mov [si+8], ax
call map ;<----- redraws map after clearing level 2
mov string_level, "3"
mov display_level[6], "3"
ret
level_3 endp
map proc
mov si, offset brick_11
.while (counter < 38) ; 38 blocks
call draw_block ; draws the bricks with the right characteristics
inc counter
add si, 12
.endw
mov counter, 0
;--- drawing end ---
ret
map endp
score_bar proc
;--- scorebar ---
draw_box 0, 2, 0, 50, 5
;----------------
;--- Score Display ---
set_cursor 1, 15
mymessage str1
set_cursor 1, 21
mov ax, score
call myoutput
;---------------------
;--- lives ---
set_cursor 1, 1
mov al, 3 ; ASCII code of Character (Heart)
mov bx,0
mov bl,4 ; color
mov cx, heart_lives ; repetition count
mov ah,09h
int 10h
;-------------
;--- Display Name ---
set_cursor 0, 30
mymessage names
;--------------------
;--- Display level ---
set_cursor 2, 30
mymessage display_level
;--------------------
ret
score_bar endp
username_input proc
;--- video mode (graphic)
mov ah, 0
mov al, 13h ;320x200
int 10h
;--- set background black
mov ax, 0
mov ah, 0Bh
mov bh, 00
mov bl, 00
int 10h
set_cursor 2, 10 ; prints "brick breaker game"
mymessage str8
;--- user name input ---
set_cursor 6, 11
mymessage str9
set_cursor 7, 11
mov dx, offset names
mov ah, 3fh
int 21h
;-----------------------
ret
username_input endp
move_paddle proc
;--- key input ---
mov ah, 01h
int 16h
jz skip_controls ; checks if key is pressed
mov ah, 00h ; checks which key is pressed
int 16h
cmp ah, 4bh ; checks for left key
je left
cmp ah, 4dh ; checks for right key
je right
jmp skip_controls
;------------------
;--- moving paddle right ---
right:
call clear_paddle
mov ax, paddle_x
add ax, paddle_width
;cmp ax, window_width ; checks for right boundary collision
.if (ax >= window_width)
jmp skip_controls
.endif
mov ax, paddle_velocity
add paddle_x, ax
jmp skip_controls
;---------------------------
;--- moving paddle left ---
left:
call clear_paddle
;cmp paddle_x, 10 ; checks for left boundary collision
je skip_controls
.if (paddle_x <= 10)
jmp skip_controls
.endif
mov ax, paddle_velocity
sub paddle_x, ax
;---------------------------
skip_controls:
ret
move_paddle endp
draw_paddle proc
;--- drawing paddle after setting the position
mov cx, paddle_x ; (column)
mov dx, paddle_y ; (row)
mov old_paddle_x, cx
mov old_paddle_y, dx
mov si, offset paddle_x