-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbrick_breaker_final
2005 lines (1714 loc) · 36.7 KB
/
brick_breaker_final
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
######################## Bitmap Display Configuration ########################
# - Unit width in pixels: 8
# - Unit height in pixels: 8
# - Display width in pixels: 256
# - Display height in pixels: 256
# - Base Address for Display: 0x10008000 ($gp)
##############################################################################
.eqv BALL_SIZE, 1
.eqv BALL_COLOUR, 0xFFFFFF
.eqv BRICK_WIDTH, 4
.eqv PADDLE_SIZE, 7
.eqv PADDLE_COLOUR, 0xBA55D3
.eqv WALL_WIDTH, 2
.data
##############################################################################
# Immutable Data
##############################################################################
ADDR_DSPL:
.word 0x10008000 # DISPLAY ADDRESS
ADDR_KBRD:
.word 0xffff0000
MY_COLOURS:
.word 0xFFBF15 # Yellow \0/
.word 0xF2541B # Orange \4/
.word 0xC91853 # Magenta \8/
.word 0x6A0487 # Purple \12/
.word 0x301D7D # Indigo \16/
.word 0x708090 # Grey \20/
.word 0x000000 # Black \24/
.word 0x647C90 # Blue-Grey \28/
.word 0x2F4F4F # Dark-Slate-Grey \32/
DELAY: .word 15000 #default delay/speed
WALL:
.word WALL_WIDTH # WALL WIDTH
BRICK:
# BRICK ATTRIBUTES
.word 0x10008388 # POSITION OF TOP LEFT BRICK
TIME_LIMIT:
.word 0x000000F8 # TIME LIMIT OF GAME 75sec = 124F8
##############################################################################
# Mutable Data
##############################################################################
BALL:
# BALL ATTRIBUTE
# POSITION: CAN OFFSET BY DOING 4X + 128Y
.word BALL_COLOUR # COLOUR \0/
.word 0x10008EC0 # position \4/
.word 0x00000001 # direction ball moving 1-4 inclusive. 1 = TR 2 = TL 3 = DR 4 = DL \8/
PADDLE:
# PADDLE ATTRIBUTES
.word PADDLE_SIZE # PADDLE SIZE
.word PADDLE_COLOUR # PADDLE COLOUR
.word 0x10008FB4 # LEFTMOST PIXEL OF PADDLE
LIVES:
.word 0x00000003 # NUMBER OF LIVES: 3
PADDLE2:
.word PADDLE_SIZE # PADDLE SIZE
.word PADDLE_COLOUR # PADDLE COLOUR
.word 0x10008F34 # LEFTMOST PIXEL OF PADDLE
##############################################################################
# Code
##############################################################################
.text
main:
start_time:
lw $s3, TIME_LIMIT
li $v0, 30
syscall
move $s0 ,$a0
j initialize_screen
pre_game:
lw $t0, ADDR_KBRD # $t0 = base address for keyboard
lw $a3, 0($t0) # Load first word from keyboard
beq $a3, 1, pre_keyboard_input # branch if key is pressed
j pre_game
game_loop: # main game loop
lw $t0, ADDR_KBRD # $t0 = base address for keyboard
lw $a3, 0($t0) # Load first word from keyboard
beq $a3, 1, keyboard_input # branch if key is pressed
before_collision: # label before collission check
j check_collision # check collision
after_collision: # label for after collision check
j check_ball_position # check if player lost
after_ball_check: # label for after checking player has not lost
j check_time
after_time_check:
j check_win_condition
j game_loop # loop back to game loop
check_colour_sound:
la $t1, MY_COLOURS
lw $t2, 20($t1) # wall colour
lw $t1, 28($t1) # ceiling colour
la $t3, PADDLE
lw $t3, 4($t3)
# correction sound
lw $t4, -128($a0)
seq $t0, $t4, $t1
beq $t0, 1, ceiling_sound
bnez $t4, brick_sound
lw $t4, 128($a0)
seq $t0, $t4, $t3
beq $t0, 1, paddle_sound
bnez $t4, brick_sound
# projection sound (regular)
lw $t4, 0($a1)
seq $t0, $t4, $t1
beq $t0, 1, ceiling_sound
seq $t0, $t4, $t2
beq $t0, 1, wall_sound
seq $t0, $t4, $t3
beq $t0, 1, paddle_sound
bnez $t4, brick_sound
lw $t4, 4($a0)
seq $t0, $t4, $t3
beq $t0, 1, paddle_sound
bnez $t4, brick_sound
lw $t4, -4($a0)
seq $t0, $t4, $t3
beq $t0, 1, paddle_sound
bnez $t4, brick_sound
after_sound:
beq $t7, 1, after_colour_sound
beq $t7, 2, after_wall_bounce_sound
beq $t7, 3, after_brick_corner_sound
beq $t7, 4, after_iso_up_sound
beq $t7, 5, after_iso_down_sound
beq $t7, 6, after_correction_sound
beq $t7, 7, after_wall_brick_sound
beq $t7, 8, after_brick_collision_sound
w_sound:
move $s6,$a0
move $s4, $a1
move $s5, $a2
# Ab
li $v0, 33
li $a0, 68
li $a1, 500
li $a2, 6
li $a3, 127
syscall
# B
li $v0, 33
li $a0, 71
li $a1, 500
li $a2, 6
li $a3, 127
syscall
# Eb
li $v0, 33
li $a0, 75
li $a1, 500
li $a2, 6
li $a3, 127
syscall
# E
li $v0, 33
li $a0, 76
li $a1, 500
li $a2, 6
li $a3, 127
syscall
# Ab
li $v0, 33
li $a0, 68
li $a1, 500
li $a2, 6
li $a3, 127
syscall
# Db
li $v0, 33
li $a0, 73
li $a1, 500
li $a2, 6
li $a3, 127
syscall
# E
li $v0, 33
li $a0, 76
li $a1, 500
li $a2, 6
li $a3, 127
syscall
# Eb
li $v0, 33
li $a0, 75
li $a1, 500
li $a2, 6
li $a3, 127
syscall
# Ab
li $v0, 33
li $a0, 68
li $a1, 500
li $a2, 6
li $a3, 127
syscall
# B
li $v0, 33
li $a0, 71
li $a1, 500
li $a2, 6
li $a3, 127
syscall
# Eb
li $v0, 33
li $a0, 75
li $a1, 500
li $a2, 6
li $a3, 127
syscall
# E
li $v0, 33
li $a0, 76
li $a1, 500
li $a2, 6
li $a3, 127
syscall
# Ab
li $v0, 33
li $a0, 68
li $a1, 500
li $a2, 6
li $a3, 127
syscall
# Db
li $v0, 33
li $a0, 73
li $a1, 500
li $a2, 6
li $a3, 127
syscall
# E
li $v0, 33
li $a0, 76
li $a1, 500
li $a2, 6
li $a3, 127
syscall
# Eb
li $v0, 33
li $a0, 75
li $a1, 500
li $a2, 6
li $a3, 127
syscall
# E
li $v0, 33
li $a0, 76
li $a1, 500
li $a2, 6
li $a3, 127
syscall
# Eb
li $v0, 33
li $a0, 75
li $a1, 500
li $a2, 6
li $a3, 127
syscall
# B
li $v0, 33
li $a0, 71
li $a1, 500
li $a2, 6
li $a3, 127
syscall
# Ab
li $v0, 33
li $a0, 68
li $a1, 500
li $a2, 6
li $a3, 127
syscall
move $a0, $s6
move $a1, $s4
move $a2, $s5
j after_no_lives
l_sound:
move $s6,$a0
move $s4, $a1
move $s5, $a2
li $v0, 33
li $a0, 54
li $a1, 500
li $a2, 100
li $a3, 127
syscall
li $v0, 33
li $a0, 52
li $a1, 500
li $a2, 100
li $a3, 127
syscall
li $v0, 33
li $a0, 50
li $a1, 500
li $a2, 100
li $a3, 127
syscall
move $a0, $s6
move $a1, $s4
move $a2, $s5
j after_no_lives
brick_sound:
move $s6,$a0
move $s4, $a1
move $s5, $a2
li $v0, 33
li $a0, 65
li $a1, 200
li $a2, 15
li $a3, 127
syscall
move $a0, $s6
move $a1, $s4
move $a2, $s5
j after_sound
paddle_sound:
move $s6,$a0
move $s4, $a1
move $s5, $a2
li $v0, 33
li $a0, 60
li $a1, 100
li $a2, 25
li $a3, 127
syscall
move $a0, $s6
move $a1, $s4
move $a2, $s5
j after_sound
wall_sound:
move $s6,$a0
move $s4, $a1
move $s5, $a2
li $v0, 33
li $a0, 50
li $a1, 100
li $a2, 99
li $a3, 127
syscall
move $a0, $s6
move $a1, $s4
move $a2, $s5
j after_sound
ceiling_sound:
move $s6,$a0
move $s4, $a1
move $s5, $a2
li $v0, 33
li $a0, 50
li $a1, 150
li $a2, 127
li $a3, 127
syscall
move $a0, $s6
move $a1, $s4
move $a2, $s5
j after_sound
check_win_condition:
li $a3, 0
li $t5, 0
li $t3, 158
la $t6, BRICK
lw $t6, 0($t6)
win_loop:
lw $t0, 0($t6)
la $t1, MY_COLOURS
lw $t1, 20($t1)
la $t4, BALL
lw $t4, 0($t4)
beq $t0, $t1, not_brick
beq $t0, $t4, not_brick
seq $t5, $t0, 0
beqz $t5, add_one
not_brick:
addi $t6, $t6, 4
addi $t3, $t3, -1
bnez $a3, game_loop
bnez $t3, win_loop
beq $a3, 0, win_screen
add_one:
addi $a3, $a3, 1
j not_brick
win_screen:
li $t0 0xFFFFFF
la $t1, ADDR_DSPL
lw $t1, 0($t1)
addi $t2, $t1, 20
sw $t0, 2048($t2)
addi $t2, $t1, 20
sw $t0, 2176($t2)
addi $t2, $t1, 24
sw $t0, 2304($t2)
addi $t2, $t1, 24
sw $t0, 2432($t2)
addi $t2, $t1, 28
sw $t0, 2560($t2)
addi $t2, $t1, 28
sw $t0, 2688($t2)
addi $t2, $t1, 32
sw $t0, 2816($t2)
addi $t2, $t1, 32
sw $t0, 2944($t2)
addi $t2, $t1, 36
sw $t0, 3072($t2)
addi $t2, $t1, 36
sw $t0, 3200($t2)
addi $t2, $t1, 40
sw $t0, 3328($t2)
addi $t2, $t1, 40
sw $t0, 3456($t2)
addi $t2, $t1, 44
sw $t0, 3584($t2)
addi $t2, $t1, 48
sw $t0, 3456($t2)
addi $t2, $t1, 52
sw $t0, 3328($t2)
addi $t2, $t1, 52
sw $t0, 3200($t2)
addi $t2, $t1, 56
sw $t0, 3072($t2)
addi $t2, $t1, 56
sw $t0, 2944($t2)
addi $t2, $t1, 60
sw $t0, 2816($t2)
# second half of w
addi $t2, $t1, 64
sw $t0, 2816($t2)
addi $t2, $t1, 104
sw $t0, 2048($t2)
addi $t2, $t1, 104
sw $t0, 2176($t2)
addi $t2, $t1, 100
sw $t0, 2304($t2)
addi $t2, $t1, 100
sw $t0, 2432($t2)
addi $t2, $t1, 96
sw $t0, 2560($t2)
addi $t2, $t1, 96
sw $t0, 2688($t2)
addi $t2, $t1, 92
sw $t0, 2816($t2)
addi $t2, $t1, 92
sw $t0, 2944($t2)
addi $t2, $t1, 88
sw $t0, 3072($t2)
addi $t2, $t1, 88
sw $t0, 3200($t2)
addi $t2, $t1, 84
sw $t0, 3328($t2)
addi $t2, $t1, 84
sw $t0, 3456($t2)
addi $t2, $t1, 80
sw $t0, 3584($t2)
addi $t2, $t1, 76
sw $t0, 3456($t2)
addi $t2, $t1, 72
sw $t0, 3328($t2)
addi $t2, $t1, 72
sw $t0, 3200($t2)
addi $t2, $t1, 68
sw $t0, 3072($t2)
addi $t2, $t1, 68
sw $t0, 2944($t2)
j w_sound
check_time:
li $v0, 30
syscall
move $s1 ,$a0
sub $s2, $s1, $s0
bge $s2, $s3, no_lives
j after_time_check
check_ball_position:
la $t7, BALL
lw $t7, 4($t7)
li $t5, 4096
la $t6, ADDR_DSPL
lw $t6, 0($t6)
add $t5, $t5, $t6
bge $t7, $t5, check_lives # if ball position off screen ==> quit
j after_ball_check
check_lives:
addi $t8, $t8, -1
sle $t7, $t8, 0
beq $t7, 1, no_lives
li $t7, 0x10008EC0
la $t6, BALL
sw $t7, 4($t6)
la $t1, PADDLE
lw $a2, 0($t1) # Paddle size
lw $a0, 8($t1) # Paddle position
la $a1, MY_COLOURS
lw $a1, 24($a1) # LOAD BLACK
jal draw_row
li $t7, 0x10008FB4
sw $t7, 8($t1)
lw $a0, 8($t1) # Paddle position
lw $a1, 4($t1) # Paddle colour
lw $a2, 0($t1) # Paddle size
jal draw_row
la $t1, PADDLE2
lw $a2, 0($t1) # Paddle size
lw $a0, 8($t1) # Paddle position
la $a1, MY_COLOURS
lw $a1, 24($a1) # LOAD BLACK
jal draw_row
li $t7, 0x10008F34
sw $t7, 8($t1)
lw $a0, 8($t1) # Paddle position
lw $a1, 4($t1) # Paddle colour
lw $a2, 0($t1) # Paddle size
jal draw_row
la $t1, BALL
lw $a2, 0($t1)
lw $a1, 4($t1)
sw $a2, 0($a1)
j randomize_direction
no_lives:
li $v0, 33
li $a0, 50
li $a1, 1000
li $a2, 126
li $a3, 127
syscall
li $t0 0xFFFFFF
la $t1, ADDR_DSPL
lw $t1, 0($t1)
# G
addi $t2, $t1, 20
sw $t0, 2048($t2)
addi $t2, $t1, 24
sw $t0, 2048($t2)
addi $t2, $t1, 28
sw $t0, 2048($t2)
addi $t2, $t1, 16
sw $t0, 2176($t2)
addi $t2, $t1, 16
sw $t0, 2304($t2)
addi $t2, $t1, 16
sw $t0, 2432($t2)
addi $t2, $t1, 20
sw $t0, 2560($t2)
addi $t2, $t1, 24
sw $t0, 2560($t2)
addi $t2, $t1, 28
sw $t0, 2560($t2)
addi $t2, $t1, 32
sw $t0, 2432($t2)
addi $t2, $t1, 32
sw $t0, 2304($t2)
addi $t2, $t1, 28
sw $t0, 2304($t2)
addi $t2, $t1, 24
sw $t0, 2304($t2)
# A
addi $t2, $t1, 48
sw $t0, 2048($t2)
addi $t2, $t1, 52
sw $t0, 2048($t2)
addi $t2, $t1, 44
sw $t0, 2176($t2)
addi $t2, $t1, 44
sw $t0, 2304($t2)
addi $t2, $t1, 44
sw $t0, 2432($t2)
addi $t2, $t1, 44
sw $t0, 2560($t2)
addi $t2, $t1, 48
sw $t0, 2304($t2)
addi $t2, $t1, 52
sw $t0, 2304($t2)
addi $t2, $t1, 56
sw $t0, 2176($t2)
addi $t2, $t1, 56
sw $t0, 2304($t2)
addi $t2, $t1, 56
sw $t0, 2432($t2)
addi $t2, $t1, 56
sw $t0, 2560($t2)
# M
addi $t2, $t1, 68
sw $t0, 2048($t2)
addi $t2, $t1, 68
sw $t0, 2176($t2)
addi $t2, $t1, 68
sw $t0, 2304($t2)
addi $t2, $t1, 68
sw $t0, 2432($t2)
addi $t2, $t1, 68
sw $t0, 2560($t2)
addi $t2, $t1, 84
sw $t0, 2048($t2)
addi $t2, $t1, 84
sw $t0, 2176($t2)
addi $t2, $t1, 84
sw $t0, 2304($t2)
addi $t2, $t1, 84
sw $t0, 2432($t2)
addi $t2, $t1, 84
sw $t0, 2560($t2)
addi $t2, $t1, 72
sw $t0, 2176($t2)
addi $t2, $t1, 76
sw $t0, 2304($t2)
addi $t2, $t1, 80
sw $t0, 2176($t2)
# E
addi $t2, $t1, 96
sw $t0, 2048($t2)
addi $t2, $t1, 96
sw $t0, 2176($t2)
addi $t2, $t1, 96
sw $t0, 2304($t2)
addi $t2, $t1, 96
sw $t0, 2432($t2)
addi $t2, $t1, 96
sw $t0, 2560($t2)
addi $t2, $t1, 100
sw $t0, 2048($t2)
addi $t2, $t1, 104
sw $t0, 2048($t2)
addi $t2, $t1, 108
sw $t0, 2048($t2)
addi $t2, $t1, 100
sw $t0, 2304($t2)
addi $t2, $t1, 104
sw $t0, 2304($t2)
addi $t2, $t1, 108
sw $t0, 2304($t2)
addi $t2, $t1, 100
sw $t0, 2560($t2)
addi $t2, $t1, 104
sw $t0, 2560($t2)
addi $t2, $t1, 108
sw $t0, 2560($t2)
# O
addi $t2, $t1, 20
sw $t0, 2944($t2)
addi $t2, $t1, 24
sw $t0, 2944($t2)
addi $t2, $t1, 28
sw $t0, 2944($t2)
addi $t2, $t1, 20
sw $t0, 3456($t2)
addi $t2, $t1, 24
sw $t0, 3456($t2)
addi $t2, $t1, 28
sw $t0, 3456($t2)
addi $t2, $t1, 16
sw $t0, 3072($t2)
addi $t2, $t1, 16
sw $t0, 3200($t2)
addi $t2, $t1, 16
sw $t0, 3328($t2)
addi $t2, $t1, 32
sw $t0, 3072($t2)
addi $t2, $t1, 32
sw $t0, 3200($t2)
addi $t2, $t1, 32
sw $t0, 3328($t2)
# V
addi $t2, $t1, 44
sw $t0, 2944($t2)
addi $t2, $t1, 44
sw $t0, 3072($t2)
addi $t2, $t1, 44
sw $t0, 3200($t2)
addi $t2, $t1, 60
sw $t0, 2944($t2)
addi $t2, $t1, 60
sw $t0, 3072($t2)
addi $t2, $t1, 60
sw $t0, 3200($t2)
addi $t2, $t1, 48
sw $t0, 3328($t2)
addi $t2, $t1, 52
sw $t0, 3456($t2)
addi $t2, $t1, 56
sw $t0, 3328($t2)
# E
addi $t2, $t1, 72
sw $t0, 2944($t2)
addi $t2, $t1, 72
sw $t0, 3072($t2)
addi $t2, $t1, 72
sw $t0, 3200($t2)
addi $t2, $t1, 72
sw $t0, 3328($t2)
addi $t2, $t1, 72
sw $t0, 3456($t2)
addi $t2, $t1, 76
sw $t0, 2944($t2)
addi $t2, $t1, 80
sw $t0, 2944($t2)
addi $t2, $t1, 84
sw $t0, 2944($t2)
addi $t2, $t1, 76
sw $t0, 3200($t2)
addi $t2, $t1, 80
sw $t0, 3200($t2)
addi $t2, $t1, 84
sw $t0, 3200($t2)
addi $t2, $t1, 76
sw $t0, 3456($t2)
addi $t2, $t1, 80
sw $t0, 3456($t2)
addi $t2, $t1, 84
sw $t0, 3456($t2)
# R
addi $t2, $t1, 96
sw $t0, 2944($t2)
addi $t2, $t1, 96
sw $t0, 3072($t2)
addi $t2, $t1, 96
sw $t0, 3200($t2)
addi $t2, $t1, 96
sw $t0, 3328($t2)
addi $t2, $t1, 96
sw $t0, 3456($t2)
addi $t2, $t1, 100
sw $t0, 2944($t2)
addi $t2, $t1, 104
sw $t0, 2944($t2)
addi $t2, $t1, 100
sw $t0, 3200($t2)
addi $t2, $t1, 104
sw $t0, 3200($t2)
addi $t2, $t1, 108
sw $t0, 3072($t2)
addi $t2, $t1, 104
sw $t0, 3328($t2)
addi $t2, $t1, 108
sw $t0, 3456($t2)
j l_sound
after_no_lives:
lw $t0, ADDR_KBRD
lw $a3, 0($t0)
beq $a3, 1, lose_keyboard_input
j after_no_lives
check_collision:
# branch accordingly depending on the direction of the ball
beq $t9, 1, moving_tr
beq $t9, 2, moving_tl
beq $t9, 3, moving_dr
beq $t9, 4, moving_dl
j after_collision
moving_tr:
# check if can move top right. Yes: draw, No: change dir draw
la $a0, BALL
lw $a0, 4($a0) # position of ball
addi $a1, $a0, -124
lw $a2, 0($a1)
bnez $a2 check_colour_collision # check if pixel is not on black
b check_brick_collision
moving_tl:
# check if can move top left. Yes: draw, No: change dir draw
la $a0, BALL
lw $a0, 4($a0) # position of ball
addi $a1, $a0, -132
lw $a2, 0($a1)
bnez $a2, check_colour_collision # check if pixel is not on black
b check_brick_collision
moving_dr:
# check if can move down right. Yes: draw, No: change dir draw
la $a0, BALL
lw $a0, 4($a0) # position of ball
addi $a1, $a0, 132
lw $a2, 0($a1)
bnez $a2, check_colour_collision # check if pixel is not on black
b check_brick_collision
moving_dl:
# check if can move down left. Yes: draw, No: change dir draw
la $a0, BALL
lw $a0, 4($a0) # position of ball
addi $a1, $a0, 124
lw $a2, 0($a1)
bnez $a2, check_colour_collision # check if pixel is not on black
li $t7, 8
j check_colour_sound
after_brick_collision_sound:
b check_brick_collision
check_colour_collision: # if the projected position of ball is not empty space
li $t7, 1
j check_colour_sound
after_colour_sound:
la $t2, MY_COLOURS
la $t1, PADDLE
lw $t1, 4($t1) # paddle colour
lw $t3, 20($t2)
lw $t2, 28($t2)
beq $a2, $t3, wall_bounce # if colour of where ball wants to go is grey
beq $a2, $t2, ceiling_bounce # if colour of where ball wants to go is blue-grey
beq $a2, $t1, after_corner_ceiling_cases # if colour of where ball wants to go is purple
b is_corner
is_corner:
# check if iso or brick brick if neither then go to check brick_collision
# moving up and blank spaces above ball and below projected ball
lw $a2, -128($a0)
lw $a3, 128($a1)
add $a2, $a2, $a3
div $t0, $t9, 3
mflo $t0
add $a2, $a2, $t0
beqz $a2, iso_up
# moving down and blank spaces below ball and above projected ball
lw $a2, 128($a0)
lw $a3, -128($a1)
add $a2, $a2, $a3
sll $a2, $a2, 1
div $t0, $t9, 3
mflo $t0
add $a2, $a2, $t0
beq $a2, 1, iso_down
# moving up and if above ball is brick and below projection is brick
la $t3, MY_COLOURS
lw $t3, 24($t3)
lw $a2, 128($a0)
lw $a3, -128($a1)
sgt $t1, $a2, $t3
sgt $t2, $a3, $t3
add $t1, $t1, $t2
beq $t1, 2, double_brick_corner
# moving down and if below ball is brick and above projection is brick
la $t3, MY_COLOURS
lw $t3, 24($t3)
lw $a2, -128($a0)
lw $a3, 128($a1)
sgt $t1, $a2, $t3
sgt $t2, $a3, $t3
add $t1, $t1, $t2
beq $t1, 2, double_brick_corner
# check brick bounce
# check moving up and if there is a brick under projection
lw $a3, 128($a1)
sgt $a3, $a3, 0