-
Notifications
You must be signed in to change notification settings - Fork 0
/
game.asm
1723 lines (1443 loc) · 32.1 KB
/
game.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
;;; M. Anas Farooq, Usman Azam.
;;; I210813 , I210653.
;;; G.
;;; BRICK BREAKER GAME (masm x8086).
; STRUCTURE FOR THE BALL.
BALL struct
ball_size dw 0h ; Size of the ball.
ball_x dw 0h ; x position (column) 96H.
ball_y dw 0h ; y position (row) BEh.
ball_vx dw 0h ; Traverse the columns with the following speed.
ball_vy dw 0h ; Traverse the rows with the following speed.
ball_color db 2h
BALL ENDS
; STRUCTURE FOR THE PADDLE.
PADDLE struct
PADDLE_X DW 0d ; x position (column).
PADDLE_Y DW 0d ; y position (row).
PADDLE_VEL DW 0h ; The moving velocity of the paddle.
PADDLE_WIDTH DW 0d ; size of the paddle in horizontal direction.
PADDLE_HEIGHT DW 0d ; size of the paddle in vertical direction.
PADDLE_COLOR db 7d
PADDLE ENDS
; STRUCTURE FOR THE BRICKS.
BRICKS struct
bricks_x dw 100d ; x position (column).
bricks_y dw 150d ; y position (row).
bricks_life db 0h
bricks_color db 0bh
BRICKS ENDS
.model HUGE
.stack 01000h
.data
include game.inc
include maps.inc
bricks_height dw 10d
bricks_width dw 20d
objball_1 BALL < 4h, 150d, 183d, 1h, 1h, 2h >
objpaddle_1 PADDLE < 130, 190, 10h, 45d, 3d >
SCREEN_WIDTH dw 320d ; 140h.
SCREEN_HEIGHT dw 200d ; 08Ch.
ball_copy_x dw 150d ; Initial position x-coordinates of the ball.
ball_copy_y dw 185d ; Initial position y-coordinates of the ball.
ball_copy_vx dw 1d
ball_copy_vy dw 1d
paddle_copy_x dw 130d ; Initial position x-coordinates of the paddle.
paddle_copy_y dw 190d ; Initial position x-coordinates of the paddle.
; CHANGES TO DO
movement_check db 1 ; To move the ball and paddle left and right, at the start of the game and whenever a live is lost.
straight_check db 1 ; To move the ball straight, at the start of the game and whenever a live is lost.
reset_flag db 1 ; A bool for checking if the ball is reseted or not.
no_of_lives db 3d ; The number of lives in a round.
lives_str db "LIVES:$"
score_str db "SCORE:$"
total_score dw 0
counter db 0
name_str db "NAME:$"
Userstr db "A$$$$$$$$$$"
FILE_NAME db 'Scores.txt', 0
FILE_NAME_PTR dw 0
COL_DETECT db 0
UP_DOWN_COL db 0
level_back db 0
time_passed db 0
game_back db 0
reset_ball_check db 0
DESTROY DB 0
collision_count db 0
original_color db 2
paddle_check db 0
PADDLE_WIDTH_COPY dw 0
brick_hits db 0
level_1_end db 0
level_2_end db 0
level_3_end db 0
delay_time dw 111111111111111b
.code
; Removes the brick that has been passed.
REMOVE_BRICK MACRO obj
.IF obj.bricks_x != 0 && obj.bricks_color != 7 && obj.bricks_color != 5
DRAW_BLACK_BRICK obj
mov obj.bricks_x, 0
mov al, obj.bricks_color
mov ah, 0
add total_score, ax
inc DESTROY
inc brick_hits
.ENDIF
ENDM
Beep MACRO voice
mov ax, voice
mov freq, ax
CALL Sound
ENDM
; Draws the Borders
OUTLINE_UP_DOWN MACRO row, col
mov cx, col ; Initial (column).
mov dx, row ; Initial(row).
mov si, 0 ; Outer loop Constaint.
mov di, 0 ; Inner loop constraint.
.while si < 1 ; Stopping condition of the loop.
mov di, 0
.while di < SCREEN_WIDTH ; Stopping condition of the loop.
mov ah, 0Ch ; Writes a pixel.
mov al, 0101b ; color.
mov bh, 00h
int 10h
inc cx ; Traversing column-wise.
inc di
.ENDW
mov cx, 0 ; Resetting the column.
inc dx ; Traversing row-wise.
inc si
.ENDW
ENDM
; Draws the ball on the screen.
DRAW_BALL MACRO OBJ, color
mov cx, OBJ.ball_x ; Initial (column).
mov dx, OBJ.ball_y ; Initial(row).
mov si, 0 ; Outer loop Constaint.
mov di, 0 ; Inner loop constraint.
.while si <= OBJ.ball_size ; Stopping condition of the loop.
mov di, 0
.while di <= OBJ.ball_size ; Stopping condition of the loop.
mov ah, 0Ch ; Writes a pixel.
mov al, color ; Red color.
mov bh, 00h
int 10h
inc cx ; Traversing column-wise.
inc di
.ENDW
mov cx, OBJ.ball_x ; Resetting the column.
inc dx ; Traversing row-wise.
inc si
.ENDW
CALL Reshape
ENDM
; Resets the ball to the original position
RESET_BALL MACRO OBJ
MOV AX, ball_copy_x
mov OBJ.ball_x, AX ; original x-coordinates (ball).
MOV AX, ball_copy_y
mov OBJ.ball_y, AX ; original y-coordinates (ball).
MOV AX, ball_copy_vx
mov OBJ.ball_vx, AX ; original velocity-x.
MOV AX, ball_copy_vy
mov OBJ.ball_vy, AX ; original velocity-y.
MOV AX, paddle_copy_x
mov objpaddle_1.PADDLE_X, AX ; original x-coordinates (paddle).
MOV AX, paddle_copy_y
mov objpaddle_1.PADDLE_Y, AX ; original y-coordinates (paddle).
mov ax, PADDLE_WIDTH_COPY
mov objpaddle_1.PADDLE_WIDTH, ax
mov reset_flag, 1 ; setting the reset_flag.
dec no_of_lives ; reducing the number of lives.
mov movement_check, 1
mov straight_check, 1
mov reset_ball_check, 1
ENDM
; Resets the ball to the original position
RESET_POSTIONS MACRO OBJ
MOV AX, ball_copy_x
mov OBJ.ball_x, AX ; original x-coordinates (ball).
MOV AX, ball_copy_y
mov OBJ.ball_y, AX ; original y-coordinates (ball).
MOV AX, ball_copy_vx
mov OBJ.ball_vx, AX ; original velocity-x.
MOV AX, ball_copy_vy
mov OBJ.ball_vy, AX ; original velocity-y.
MOV AX, paddle_copy_x
mov objpaddle_1.PADDLE_X, AX ; original x-coordinates (paddle).
MOV AX, paddle_copy_y
mov objpaddle_1.PADDLE_Y, AX ; original y-coordinates (paddle).
mov ax, PADDLE_WIDTH_COPY
mov objpaddle_1.PADDLE_WIDTH, ax
mov reset_flag, 1 ; setting the reset_flag.
MOV collision_count, 0
mov bl, original_color
mov OBJ.ball_color, bl
mov movement_check, 1
mov straight_check, 1
ENDM
; fUNCTION TO DRAW THE PADDLE.
DRAW_PADDLE MACRO OBJ_PADDLE, color
mov cx, OBJ_PADDLE.PADDLE_X ; Initial (column).
mov dx, OBJ_PADDLE.PADDLE_Y ; Initial(row).
.IF paddle_check == 1
add OBJ_PADDLE.PADDLE_WIDTH, 5
mov paddle_check, 0
.ENDIF
mov si, 0
mov di, 0
.while si <= OBJ_PADDLE.PADDLE_HEIGHT
mov di, 0
.while di <= OBJ_PADDLE.PADDLE_WIDTH
mov ah, 0Ch ; Writes a pixel.
mov al, color ; Blue color.
mov bh, 00h
INT 10H
inc cx ; Traversing column-wise.
inc di
.ENDW
inc dx ; Traversing row-wise.
mov cx, OBJ_PADDLE.PADDLE_X ; Setting cx to inital position.
inc si
.ENDW
ENDM
; Move the paddle through keyboard inputs.
MOVE_PADDLE MACRO OBJ_PADDLE, OBJ_BALL
; checking if the right or left key is pressed, if not then exit.
mov ah, 1h
int 16h
jz NO_PADDLE_COLLISION
mov ah, 0h ; ah = scan-codes, al = ascii-codes.
int 16h
; For pausing the screen.
.IF movement_check != 1 ; At the start of the game, no need to check this condition.
cmp al, 32d ; Ascii of space.
jz pause_game
.ENDIF
jmp continue_game
; For pausing the game.
pause_game:
mov ah, 00h ; Sets the configuration to video mode.
mov al, 13h ; 320 * 200.
int 10h
call Pause_Screen
mov cursor, 1
mov row_cursor, 12
Print_Char_2 8, row_cursor, 14, 16
cursor_move:
mov ah, 0h ; ah = scan-codes, al = ascii-codes.
int 16h
.IF al == 32 ; Ascii of space.
.IF cursor == 1
CALL VIDEO_MODE ; Entering Video mode.
CALL STATUS_BAR
CALL MAKE_ALL_BRICKS
DRAW_PADDLE objpaddle_1, objpaddle_1.PADDLE_COLOR
JMP continue_game
.ELSEIF cursor == 2
mov game_back, 1
JMP continue_game
.ENDIF
.ENDIF
.if ah == 050h && cursor < 2 ;down
Beep 5672
Print_Char_2 8, row_cursor, 0, 16
inc cursor
add row_cursor, 6
Print_Char_2 8, row_cursor, 12, 16
Print 12,8,12,8,15
.elseif ah == 048h && cursor > 1 ;up
Beep 5672
dec cursor
Print_Char_2 8, row_cursor, 0, 16
sub row_cursor, 6
Print_Char_2 8, row_cursor, 14, 16
Print 18,8,18,8,15
.endif
jmp cursor_move
; For continuing the game.
continue_game:
.IF ah == 04Dh ; Right-key scan-code.
.IF movement_check == 1
DRAW_BALL objball_1, 0h
mov ax, OBJ_PADDLE.PADDLE_VEL
add OBJ_BALL.ball_x, ax
DRAW_BALL objball_1, objball_1.ball_color
.ENDIF
jmp move_right
.ENDIF
.IF ah == 04Bh ; Left-key scan-code.
.IF movement_check == 1
DRAW_BALL objball_1, 0h
mov ax, OBJ_PADDLE.PADDLE_VEL
sub OBJ_BALL.ball_x, ax
DRAW_BALL objball_1, objball_1.ball_color
.ENDIF
jmp move_left
.ENDIF
jmp NO_PADDLE_COLLISION
move_right:
DRAW_PADDLE OBJ_PADDLE, 0h
mov ax, OBJ_PADDLE.PADDLE_VEL
add OBJ_PADDLE.PADDLE_X, ax
mov bx, SCREEN_WIDTH
sub bx, OBJ_PADDLE.PADDLE_WIDTH
.IF OBJ_PADDLE.PADDLE_X >= bx ; paddle_x > SCREEN_WIDTH - ball_size , Right side collided.
SUB OBJ_PADDLE.PADDLE_X, ax
.IF movement_check == 1
DRAW_BALL objball_1, 0h
mov ax, OBJ_PADDLE.PADDLE_VEL
sub OBJ_BALL.ball_x, ax
DRAW_BALL objball_1, objball_1.ball_color
.ENDIF
.ENDIF
jmp movement_end
move_left:
DRAW_PADDLE OBJ_PADDLE, 0h
mov ax, OBJ_PADDLE.PADDLE_VEL
sub OBJ_PADDLE.PADDLE_X, ax
cmp OBJ_PADDLE.PADDLE_X, -5; ; paddle_x < 0 , Left side collided.
jg movement_end
add OBJ_PADDLE.PADDLE_X, ax
.IF movement_check == 1
DRAW_BALL objball_1, 0h
mov ax, OBJ_PADDLE.PADDLE_VEL
add OBJ_BALL.ball_x, ax
DRAW_BALL objball_1, objball_1.ball_color
.ENDIF
jmp movement_end
movement_end:
DRAW_PADDLE OBJ_PADDLE, OBJ_PADDLE.PADDLE_COLOR
NO_PADDLE_COLLISION:
ENDM
; FUNCTION TO DRAW THE BRICKS.
DRAW_BRICK MACRO OBJ_BRICK
.IF OBJ_BRICK.bricks_x != 0 && OBJ_BRICK.bricks_y != 0
mov cx, OBJ_BRICK.bricks_x ; Initial (column).
mov dx, OBJ_BRICK.bricks_y ; Initial(row).
mov si, 0
mov di, 0
.while si <= bricks_height
mov di, 0
.while di <= bricks_width
mov ah, 0Ch ; Writes a pixel.
mov al, OBJ_BRICK.bricks_color ; color.
.IF OBJ_BRICK.bricks_color != 15
.IF OBJ_BRICK.bricks_color == 16
mov OBJ_BRICK.bricks_color, 14
.ENDIF
; Bodering the bricks.
.IF si == 0 || di == 0
mov al, 0Fh
.ENDIF
.IF si == bricks_height || di == bricks_width
mov al, 0Fh
.ENDIF
.ENDIF
mov bh, 00h
INT 10H
inc cx ; Traversing column-wise.
inc di
.ENDW
inc dx ; Traversing row-wise.
mov cx, OBJ_BRICK.bricks_x ; Setting cx to inital position.
inc si
.ENDW
.ENDIF
ENDM
; FUNCTION TO DRAW THE BRICKS.
DRAW_BLACK_BRICK MACRO OBJ_BRICK
mov cx, OBJ_BRICK.bricks_x ; Initial (column).
mov dx, OBJ_BRICK.bricks_y ; Initial(row).
mov si, 0
mov di, 0
.while si <= bricks_height
mov di, 0
.while di <= bricks_width
mov ah, 0Ch ; Writes a pixel.
mov al, 0h
mov bh, 00h
INT 10H
inc cx ; Traversing column-wise.
inc di
.ENDW
inc dx ; Traversing row-wise.
mov cx, OBJ_BRICK.bricks_x ; Setting cx to inital position.
inc si
.ENDW
ENDM
DETECT_BRICK_COLLISION MACRO OBJ, OBJ_BRICK
.IF OBJ_BRICK.bricks_x != 0 && OBJ_BRICK.bricks_y != 0 && COL_DETECT == 0
mov ax, OBJ.ball_x
add ax, OBJ.ball_size
add ax, 3
.IF ax > OBJ_BRICK.bricks_x
mov ax, OBJ_BRICK.bricks_x
add ax, bricks_width
add ax, 2
.IF OBJ.ball_x < ax
mov ax, OBJ.ball_y
add ax, OBJ.ball_size
add ax, 2
mov bx, OBJ_BRICK.bricks_y
.IF ax > bx
mov ax, OBJ_BRICK.bricks_y
add ax, bricks_height
add ax, 3
.IF OBJ.ball_y < ax
.IF COL_DETECT == 0
mov straight_check, 0
inc collision_count
; Special Ball.
.IF collision_count >= 3
MOV OBJ_BRICK.bricks_life, 0
mov OBJ.ball_color, 39
.ELSE
dec OBJ_BRICK.bricks_life
.ENDIF
; Paddle size.
.IF collision_count >= 4
mov paddle_check, 1
.ENDIF
DRAW_BALL OBJ, OBJ.ball_color
.IF OBJ_BRICK.bricks_color == 5h
CALL SPECIAL_DESTROY
.ENDIF
.IF OBJ_BRICK.bricks_color != 7h
INC obj_BRICK.bricks_color
.IF OBJ_BRICK.bricks_color == 5h || OBJ_BRICK.bricks_color == 7h
INC obj_BRICK.bricks_color
.ENDIF
.ENDIF
mov COL_DETECT, 1
Beep 4923
.ENDIF
.IF OBJ_BRICK.bricks_color != 7h
.IF OBJ_BRICK.bricks_life == 0
inc brick_hits
mov ax, 0
mov al, OBJ_BRICK.bricks_color
add total_score, ax
DRAW_BLACK_BRICK OBJ_BRICK
mov OBJ_BRICK.bricks_x, 0
mov OBJ_BRICK.bricks_y, 0
.ENDIF
.ENDIF
CALL SCORE
OUTLINE_UP_DOWN 30, 0
CALL MAKE_ALL_BRICKS
.ENDIF
.ENDIF
.ENDIF
.ENDIF
.ENDIF
ENDM
start:
mov ax, @data
mov ds, ax
mov ax, 0
main PROC
;CALL Username_Screen
;CALL DELAY
CALL GAME_START
mov ah, 4ch
int 21h
main ENDP
; Takes the game to video mode.
VIDEO_MODE PROC
mov ah, 00h ; Sets the configuration to video mode.
;mov al, 0Dh ; 320x200 16 color graphics (EGA,VGA).
mov al, 13h ; 320 * 200.
int 10h
OUTLINE_UP_DOWN 30, 0
OUTLINE_UP_DOWN 199, 0
RET
VIDEO_MODE ENDP
STATUS_BAR PROC
CALL LIVES ; Displays the remaining lives.
CALL SCORE ; Displays the current score.
CALL NAME_DISP ; Displays the user's name.
RET
STATUS_BAR ENDP
; Moves the Ball
MOVE_BALL PROC
.IF straight_check == 0
mov ax, objball_1.ball_vx
add objball_1.ball_x, ax ; moves the ball horizontally.
.ENDIF
.IF UP_DOWN_COL == 0
DETECT_ALL_COLIISON
DRAW_BALL objball_1, 0h
.ENDIF
.IF COL_DETECT == 1
NEG objball_1.ball_vx
.ENDIF
cmp objball_1.ball_x, 3 ; ball_x < 0 , Left side collided.
jl neg_x
mov bx, SCREEN_WIDTH
sub bx, objball_1.ball_size
sub bx, 4
cmp objball_1.ball_x, bx ; ball_x > SCREEN_WIDTH - ball_size , Right side collided.
jg neg_x
mov ax, objball_1.ball_vy
sub objball_1.ball_y, ax ; moves the ball vertically.
mov UP_DOWN_COL, 0
.IF COL_DETECT == 0
DETECT_ALL_COLIISON
DRAW_BALL objball_1, 0h
.IF COL_DETECT == 1
NEG objball_1.ball_vy
mov UP_DOWN_COL, 1
.ENDIF
.ENDIF
mov COL_DETECT, 0
.IF objball_1.ball_y < 36 ; ball_y < 0 , Up side collided.
mov straight_check, 0
MOV collision_count, 0
mov bl, original_color
mov objball_1.ball_color, bl
jmp neg_y
.ENDIF
mov bx, SCREEN_HEIGHT ; Down side collided.
.IF objball_1.ball_y >= bx
MOV collision_count, 0
mov bl, original_color
mov objball_1.ball_color, bl
jmp reset_ball_pos
.ENDIF
; Detecting the collision of ball with the paddle
; ball_x + ball_size > PADDLE_X && ball_x < PADDLE_X + PADDLE_WIDTH
; ball_y + ball_size > PADDLE_Y && ball_y < PADDLE_Y + PADDLE_HEIGHT
mov ax, objball_1.ball_x
add ax, objball_1.ball_size
add ax, 6
.IF ax > objpaddle_1.PADDLE_X
mov ax, objpaddle_1.PADDLE_X
add ax, objpaddle_1.PADDLE_WIDTH
add ax, 8
.IF objball_1.ball_x < ax
mov ax, objball_1.ball_y
add ax, objball_1.ball_size
mov bx, objpaddle_1.PADDLE_Y
sub bx, 2 ; So, that the ball, it doesn't look like that the ball goes into the paddle.
.IF ax > bx
mov ax, objpaddle_1.PADDLE_Y
add ax, objpaddle_1.PADDLE_HEIGHT
add ax, 6
.IF objball_1.ball_y < ax
jmp neg_y
.ENDIF
.ENDIF
.ENDIF
.ENDIF
JMP EXIT_FOR_NOW
; Resets the ball position
reset_ball_pos:
RESET_BALL objball_1
JMP EXIT_FOR_NOW
; Reversing the y-velocity
neg_y:
mov ax, objball_1.ball_vy
mov bx, -1
mul bx
mov objball_1.ball_vy, ax ; Negating the ball_velocity-y.
MOV collision_count, 0
mov bl, original_color
mov objball_1.ball_color, bl
JMP EXIT_FOR_NOW
; Reversing the x-velocity
neg_x:
mov ax, objball_1.ball_vx
mov bx, -1
mul bx
mov objball_1.ball_vx, ax ; Negating the ball_velocity-x.
MOV collision_count, 0
mov bl, original_color
mov objball_1.ball_color, bl
JMP EXIT_FOR_NOW
EXIT_FOR_NOW:
RET
MOVE_BALL ENDP
out_it PROC
;OUTPUT multidigit number
output:
mov dx, 0
mov ax, total_score
mov bx, 10
Lk:
mov dx, 0
cmp ax, 0
jz disp
div bx
MOV cx, dx
push cx
inc counter
mov ah, 0
jmp Lk
disp:
cmp counter, 0
jz exit
pop dx
add dx, 48
mov ah, 02H
int 21H
dec counter
jmp disp
exit:
ret
out_it ENDP
delay_it proc
mov cx, 111111111111111b
delayloop:
loop delayloop
ret
delay_it endp
; Calls the clear screen and move the ball
DELAY PROC
start_again:
RESET_POSTIONS objball_1
CALL VIDEO_MODE ; Entering Video mode.
CALL STATUS_BAR
CALL MAKE_ALL_BRICKS
DRAW_PADDLE objpaddle_1, objpaddle_1.PADDLE_COLOR
check_time:
DRAW_BALL objball_1, 0h ; Delete the ball at previous position.
CALL MOVE_BALL ; Moves the ball, if collision occurs, deflects the ball.
.IF no_of_lives == 0
CALL DISPLAY
CALL GAME_OVER
MOV AH, 4CH
INT 21H
.ENDIF
.IF reset_ball_check == 1
mov reset_ball_check, 0
CALL LiveLost
jmp start_again
.ENDIF
; Level Changings
.IF level_1_end != 1
.IF brick_hits == 41 ; 41
CALL LEVEL_2_CHANGINGS
mov brick_hits, 0
mov level_1_end, 1
jmp start_again
.ENDIF
.ENDIF
.IF level_2_end != 1
.IF brick_hits == 57 ; 57
CALL LEVEL_3_CHANGINGS
mov brick_hits, 0
mov level_2_end, 1
jmp start_again
.ENDIF
.ENDIF
.IF level_3_end != 1
.IF brick_hits == 52 ; 52
CALL LEVEL_3_CHANGINGS
mov brick_hits, 0
mov level_1_end, 0
mov level_2_end, 0
mov level_3_end, 0
CALL DISPLAY
CALL You_Win
mov ah, 0h ; ah = scan-codes, al = ascii-codes.
int 16h
CALL File_Operations
CALL GAME_START
.ENDIF
.ENDIF
DRAW_BALL objball_1, objball_1.ball_color ; Draws the ball with color.
CALL RESET_REGISTERS ; Resets all the registers.
MOVE_PADDLE objpaddle_1, objball_1 ; Moves the padddle, if any key is pressed, then delete's the previous paddle and makes new.
.IF game_back == 1
mov level_1_end, 0
mov level_2_end, 0
mov level_3_end, 0
CALL GAME_START
.ENDIF
mov bh, 1
cmp bh, reset_flag
jnz just_display
take_again:
CALL CHANGES
cmp al, 32d ; Ascii of space.
jnz take_again
mov reset_flag, 0
mov movement_check, 0
just_display:
call delay_it
jmp check_time ; Go to the time loop to check the time again.
out_delay:
ret
DELAY ENDP
CHANGES PROC
MOVE_PADDLE objpaddle_1, objball_1
ret
CHANGES ENDP
MAKE_ALL_BRICKS PROC
DRAW_BRICK b_1
DRAW_BRICK b_2
DRAW_BRICK b_3
DRAW_BRICK b_4
DRAW_BRICK b_5
DRAW_BRICK b_6
DRAW_BRICK b_7
DRAW_BRICK b_8
DRAW_BRICK b_9
DRAW_BRICK b_10
DRAW_BRICK b_11
DRAW_BRICK b_12
DRAW_BRICK b_13
DRAW_BRICK b_14
DRAW_BRICK b_15
DRAW_BRICK b_16
DRAW_BRICK b_17
DRAW_BRICK b_18
DRAW_BRICK b_19
DRAW_BRICK b_20
DRAW_BRICK b_21
DRAW_BRICK b_22
DRAW_BRICK b_23
DRAW_BRICK b_24
DRAW_BRICK b_25
DRAW_BRICK b_26
DRAW_BRICK b_27
DRAW_BRICK b_28
DRAW_BRICK b_29
DRAW_BRICK b_30
DRAW_BRICK b_31
DRAW_BRICK b_32
DRAW_BRICK b_33
DRAW_BRICK b_34
DRAW_BRICK b_35
DRAW_BRICK b_36
DRAW_BRICK b_37
DRAW_BRICK b_38
DRAW_BRICK b_39
DRAW_BRICK b_40
DRAW_BRICK b_41
DRAW_BRICK b_42
DRAW_BRICK b_43
DRAW_BRICK b_44
DRAW_BRICK b_45
DRAW_BRICK b_46
DRAW_BRICK b_47
DRAW_BRICK b_48
DRAW_BRICK b_49
DRAW_BRICK b_50
DRAW_BRICK b_51
DRAW_BRICK b_52
DRAW_BRICK b_53
DRAW_BRICK b_54
DRAW_BRICK b_55
DRAW_BRICK b_56
DRAW_BRICK b_57
ret
MAKE_ALL_BRICKS ENDP
; Resets all the registers
RESET_REGISTERS PROC
mov ax, 0
mov bx, 0
mov cx, 0
mov dx, 0
mov si, 0
mov di, 0
ret
RESET_REGISTERS ENDP
BLINKING PROC
again_it:
mov ah, 2ch
int 21h
mov time_passed, dh
add time_passed, 2
go_take_again:
Print_string Continue, 20,25
mov ah, 6
mov al, 0
mov bh, 0 ;color
mov ch, 19 ;top row of window
mov dh, 20 ;Bottom row of window
mov cl, 28 ;left most column of window
mov dl, 70 ;Right most column of window
int 10h
; checking if the Enter key is pressed.
mov ah, 1h ; ah = scan-codes, al = ascii-codes.
int 16h
jnz here
mov ah, 2ch
int 21h
cmp time_passed, dh
jnz go_take_again
jmp again_it
here:
ret
BLINKING ENDP
DISPLAY PROC
; Setting the video mode.
mov ah, 0h
mov al, 12h
int 10h
ret
DISPLAY ENDP
File_Operations PROC
; Opening a existing file.
mov ah, 3dh
mov dx, offset FILE_NAME
mov al, 2 ; writing mode.
int 21h
mov FILE_NAME_PTR, ax
; At the end position.
mov cx, 0
mov dx, 0
mov ah, 42h
mov bx, FILE_NAME_PTR
mov al, 2 ; 0 beginning of file, 2 end of file
int 21h
mov cx, 0
.while [Userstr + si] != "$"
inc cx
inc si
.endw
; Writing in the file.
mov ah, 40h
mov bx, FILE_NAME_PTR
mov dx, offset Userstr ; The string to write.
add dx, 2
int 21h
; Closing the file
mov ah, 3eh
mov dx, FILE_NAME_PTR
int 21h
ret
File_Operations ENDP
; Starting The Game.
GAME_START PROC
.IF game_back != 1
CALL DISPLAY
call Boarders
call B_Letter
call R_Letter
call I_letter
call C_letter
call K_letter
call B_2Letter
call R_2letter
call E_2letter