-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfinaldoodle.asm
1175 lines (858 loc) · 24.3 KB
/
finaldoodle.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
.data
displayAddress: .word 0x10008000
doodleGreen: .word 0x7fecad
backgroundwhite: .word 0xfffbf0
deadRed: .word 0xff2121
platformGreen: .word 0x00bc12
gameOverRed: .word 0xff461f
gameOverOrange: .word 0xff8936
gameOverYellow: .word 0xfff143
currentAddress: .space 1
randomPlat1: .word 0 # respect to Array,
randomPlat2: .word 0 # respect to Array
randomPlat3: .word 0 # respect to Array
randomPlat4: .word 0
randomPlat5: .word 0
bitMap: .space 6000 # only need 4096
newline: .asciiz "\n"
currentDoodlePosition: .word 0 # respect to Array
sHitTime: .word 0
noMoreJump: .word 0
height: .word 0
meet2: .word 0
disappear3: .word 0
platDown: .word 0
terminateTheGame: .word 0
level1: .word 0
level2: .word 0
level3: .word 0
.text
main:
# debug the scrolling
# randomly generate the first platform
# why we need to manually reset the value at 0xffff0004 to zero
chooseDifficulties:
# Fetching keyboard input
lw $t8, 0xffff0000
beq $t8, 1, recognizeDifficulties # if a key is pressed, check which key is pressed
j chooseDifficulties
recognizeDifficulties:
lw $t2, 0xffff0004
beq $t2, 0x31, difficulty1
beq $t2, 0x32, difficulty2
beq $t2, 0x33, difficulty3
j chooseDifficulties
difficulty1:
add $t1, $zero, $zero
sw $t1, 0xffff0004
addi $t2, $zero, 1
sw $t2, level1
j fetchKeyboard
difficulty2:
add $t1, $zero, $zero
sw $t1, 0xffff0004
addi $t2, $zero, 1
sw $t2, level2
j fetchKeyboard
difficulty3:
add $t1, $zero, $zero
sw $t1, 0xffff0004
addi $t2, $zero, 1
sw $t2, level3
j fetchKeyboard
fetchKeyboard:
# Fetching keyboard input
lw $t8, 0xffff0000
beq $t8, 1, gameStartSignal # if a key is pressed, check which key is pressed
j fetchKeyboard # if keyboard is not pressed, keep asking which key is pressed
gameStartSignal:
lw $t2, 0xffff0004
beq $t2, 0x73, gameStart
j fetchKeyboard # if key pressed is not s, keep asking which key is pressed
gameStart:
li $v0, 1
addi $a0, $zero, 520
syscall
# sw $zero, 0xffff0004 # restore value in 0xffff0004
jal calculatePlatformPosition # calculate the platform postion at the welcome page
jal welcomePage # draw Doodle on a platform
playFetchKeyBoard:
lw $t3, meet2
bne $t3, 1, doNotIncrease
lw $t2, height
addi $t2, $t2, 2
sw $t2, height
doNotIncrease:
jal jump # calculate current lcoation and height
# Fetching keyboard input
lw $t8, 0xffff0000
beq $t8, 1, keyboard_input # if keyboard is pressed, check which key is pressed
j drawMap # if no key is pressed, draw the Doodle jumping shoot
keyboard_input:
lw $t2, 0xffff0004
beq $t2, 0x6a, respond_to_j
beq $t2, 0x6b, respond_to_k
j drawMap # if neither j nor k is pressed, jump, and ask for the next key input
respond_to_j:
# sw $zero, 0xffff0004 # restore value in 0xffff0004
jal moveToLeft
li $v0, 1
addi $a0, $zero, 0
syscall
j drawMap
respond_to_k:
# sw $zero, 0xffff0004 # restore value in 0xffff0004
jal moveToRight
li $v0, 1
addi $a0, $zero, 1
syscall
drawMap:
jal checkScreen # check whether my doodler is at the bottom of the screen
lw $t3, terminateTheGame
beq $t3, 0, checkPlatforms # if terminateTheGame is set to 0, begin to move the platform and draw
jal drawEndScreen # if terminateTheGame is set to 1, terminate the game
# jal drawExplosion
# jal drawGameOver
j EXIT
checkPlatforms:
lw $t1, meet2 # otherwise, check the consider whether or not showr the platforms
beq $t1, 0, drawFinalBitMap # if meet2 = 0, don't move the platform
jal movePlatforms # if meet2 = 1, begin to move the platforms
drawFinalBitMap:
jal drawBitMap # draw background, platform, doodle based on currentDoodlePosition
sleep:
li $v0, 32 # sleep
li $a0, 25
syscall
# go back to playFetchKeyBoard
j playFetchKeyBoard
EXIT:
li $v0, 10
syscall
# functions
gameOver:
li $v0, 1
addi $a0, $zero, 1998
syscall
# letter g
lw $t9, gameOverYellow
lw $t8, gameOverRed
lw $t7, gameOverOrange
addi $a0, $zero, 1292 # load anchor of letter g
add $t2, $zero, $zero # clear index
while_g_1:
beq $t2, 4, letterG
sw $t9, bitMap($a0)
addi $a0, $a0, 4
addi $t2, $t2, 1
j while_g_1
letterG:
addi $a0, $zero, 1420
sw $t9, bitMap($a0)
addi $a0, $a0, 128
sw $t7, bitMap($a0)
addi $a0, $a0, 12
sw $t7, bitMap($a0)
addi $a0, $a0, 4
sw $t7, bitMap($a0)
addi $a0, $a0, 128
sw $t8, bitMap($a0)
addi $a0, $a0, 128
sw $t8, bitMap($a0)
addi $a0, $a0, -4
sw $t8, bitMap($a0)
addi $a0, $a0, -4
sw $t8, bitMap($a0)
addi $a0, $a0, -4
sw $t8, bitMap($a0)
addi $a0, $a0, -132
sw $t8, bitMap($a0)
add $t2, $zero, $zero # clear index
addi $a0, $zero, 1328 # 1292 + 8 * 4 (anchor of A)
while_a_1:
beq $t2, 3, letterA
sw $t9, bitMap($a0)
addi $a0, $a0, 4
addi $t2, $t2, 1
j while_a_1
letterA:
addi $a0, $zero, 1452
sw $t9, bitMap($a0)
addi $a0, $a0, 16
sw $t9, bitMap($a0)
addi $a0, $zero, 1580
add $t2, $zero, $zero # clear index
while_a_2:
beq $t2, 5, restOfLetterA
sw $t7, bitMap($a0)
addi $a0, $a0, 4
addi $t2, $t2, 1
j while_a_2
restOfLetterA:
addi $a0, $zero, 1708
sw $t8, bitMap($a0)
addi $a0, $a0, 128
sw $t8, bitMap($a0)
addi $a0, $zero, 1724
sw $t8, bitMap($a0)
addi $a0, $a0, 128
sw $t8, bitMap($a0)
addi $a0, $zero, 1352
sw $t9, bitMap($a0)
addi $a0, $a0, 16
sw $t9, bitMap($a0)
addi $a0, $a0, 128
sw $t9, bitMap($a0)
addi $a0, $a0, -4
sw $t9, bitMap($a0)
addi $a0, $a0, -8
sw $t9, bitMap($a0)
addi $a0, $a0, -4
sw $t9, bitMap($a0)
addi $a0, $a0, 128
sw $t7, bitMap($a0)
addi $a0, $a0, 8
sw $t7, bitMap($a0)
addi $a0, $a0, 8
sw $t7, bitMap($a0)
addi $a0, $a0, 128
sw $t8, bitMap($a0)
addi $a0, $a0, 128
sw $t8, bitMap($a0)
addi $a0, $a0, -16
sw $t8, bitMap($a0)
addi $a0, $a0, -128
sw $t8, bitMap($a0)
addi $a0, $zero, 1376
add $t2, $zero, $zero # clear index
while_e_1:
beq $t2, 5, restOfLetterE
sw $t9, bitMap($a0)
addi $a0, $a0, 4
addi $t2, $t2, 1
j while_e_1
restOfLetterE:
jr $ra
welcomePage:
addi $sp, $sp, -4 # save $ra
sw $ra, 0($sp)
#jal paintBackground # drawBackground
lw $a0, randomPlat1
jal drawPlatform
lw $a0, randomPlat2
jal drawPlatform
lw $a0, randomPlat3
jal drawPlatform
seeLevel2:
lw $t2, level2
beq $t2, 0, seeLevel1
lw $a0, randomPlat4 # if game level2 = 1, draw extra platform4
jal drawPlatform
j drawLevel3
seeLevel1:
lw $t1, level1
beq $t1, 0, drawLevel3
lw $a0, randomPlat4 # if game level1 = 1, draw extra platform4
jal drawPlatform
lw $a0, randomPlat5 # if game level1 = 1, draw extra platform5
jal drawPlatform
drawLevel3:
lw $a0, randomPlat3 # calculate the doodler position
addi $a0, $a0, -768
sw $a0, currentDoodlePosition # update current location
lw $a1, doodleGreen
jal drawMyDoodle # drawDoodle
jal readBitMap # readBitMap
lw $ra, 0($sp) # restore $ra
addi $sp, $sp, 4
jr $ra
# draw the explosion after the doodle is dead
drawExplosion:
addi $sp, $sp, -4 # save $ra
sw $ra, 0($sp)
jal drawExplosion1
#jal drawExplosion2
#jal drawExplosion3
lw $ra, 0($sp) # restore $ra
addi $sp, $sp, 4
jr $ra
drawExplosion1:
jal paintBackground # drawBackground
lw $a0, randomPlat1
jal drawPlatform
lw $a0, randomPlat2
jal drawPlatform
lw $a0, randomPlat3
jal drawPlatform
# $a0 is the start blank box before the first head piece
lw $a0, currentDoodlePosition
addi $a0, $a0, 4 # draw head that one unit later than the anchor
lw $t3, deadRed # load doodle color
add $s0, $zero, $zero # clear index to 0
while_deadHead1:
# draw head1
beq $s0, 3, draw_deadHead2
sw $t3, bitMap($a0) # colored as green
addi $a0, $a0, 4 # move to next MA
addi $s0, $s0, 1
j while_deadHead1
draw_deadHead2:
addi $a0, $a0, 112 # load head2 address
add $s0, $zero, $zero # clear index to 0
while_deadHead2:
beq $s0, 5, draw_deadHead3
sw $t3, bitMap($a0) # colored as green
addi $a0, $a0 4 # move to next MA
addi $s0, $s0, 1
j while_deadHead2
draw_deadHead3:
addi $a0, $a0, 108 # load head3 address
add $s0, $zero, $zero # clear index to 0
while_deadHead3:
beq $s0, 7, draw_deadHead4
sw $t3, bitMap($a0) # colored as green
addi $a0, $a0 4 # move to next MA
addi $s0, $s0, 1
j while_deadHead3
draw_deadHead4:
addi $a0, $a0, 100 # load head3 address
add $s0, $zero, $zero # clear index to 0
while_deadHead4:
beq $s0, 5, draw_deadLeg1
sw $t3, bitMap($a0) # colored as green
addi $a0, $a0 4 # move to next MA
addi $s0, $s0, 1
j while_deadHead4
draw_deadLeg1:
addi $a0, $a0, 112
add $s0, $zero, $zero # clear index to 0
while_deadLeg1:
beq $s0, 2, draw_deadLeg2
sw $t3, bitMap($a0) # colored as green
addi $a0, $a0 128 # move to next MA
addi $s0, $s0, 1
j while_deadLeg1
draw_deadLeg2:
addi $a0, $a0, -256
addi $a0, $a0, 8
add $s0, $zero, $zero # clear index to 0
while_deadLeg2:
beq $s0, 2, finishedDeadDoodle
sw $t3, bitMap($a0) # colored as green
addi $a0, $a0 128 # move to next MA
addi $s0, $s0, 1
j while_deadLeg2
finishedDeadDoodle:
jr $ra
# draw the gameOver scene
# draw the screen shown at the end of the program
drawEndScreen:
addi $sp, $sp, -4 # save $ra
sw $ra, 0($sp)
#jal paintBackground # drawBackground
lw $a0, randomPlat1
jal drawPlatform
lw $a0, randomPlat2
jal drawPlatform
lw $a0, randomPlat3
jal drawPlatform
lw $a1, deadRed
jal drawMyDoodle # drawDoodle
jal gameOver
jal readBitMap # readBitMap
lw $ra, 0($sp) # restore $ra
addi $sp, $sp, 4
jr $ra
# set terminateTheGame to 1 if my doodler is at the bottom of the screen
# no argument
checkScreen:
lw $t9, currentDoodlePosition
sge $s0, $t9, 3324 # $t9 > 991
beq $s0, 1, terminate
jr $ra
terminate:
addi $t4, $zero, 1
sw $t4, terminateTheGame
jr $ra
# calculate how to move platform to create scrolling screen effect
# precondition: one and one of level1, 2, 3 is set to 1 and the others are set to 0
# no argument
movePlatforms:
lw $t9, level1
lw $t8, level2
lw $t7, level3
beq $t7, 1, moveLevel3
beq $t8, 1, moveLevel2
beq $t9, 1, moveLevel1
moveLevel1: # move 5 platfroms
lw $t2, platDown
beq $t2, 6, resetMeet2_level1 # if platDown = 10, reset meet2, platDown to 0 and do
# nothing to randomPlats
addi $t2, $t2, 1 # increment platDown
sw $t2, platDown
lw $t7, randomPlat1 # if platDown != 10, move the platforms
addi $t7, $t7, 128
sw $t7, randomPlat1
lw $t6, randomPlat2
addi $t6, $t6, 128
sw $t6, randomPlat2
lw $t6, randomPlat3
addi $t6, $t6, 128
sw $t6, randomPlat3
lw $t6, randomPlat4
addi $t6, $t6, 128
sw $t6, randomPlat4
lw $t6, randomPlat5
addi $t6, $t6, 128
sw $t6, randomPlat5
lw $t3, height # change the height
addi $t3, $t3, -1
sw $t3, height
jr $ra
resetMeet2_level1:
add $t2, $zero, $zero # reset meet2 and platDown to 0
sw $t2, meet2
sw $t2, platDown
lw $t3, randomPlat5 # give value in randomPlat2 to randomPlat3,
sw $t3, randomPlat3
lw $t7, randomPlat2 # give value in randomPlat1 to randomPlat2
sw $t7, randomPlat5
lw $t7, randomPlat4 # give value in randomPlat1 to randomPlat2
sw $t7, randomPlat2
lw $t7, randomPlat1 # give value in randomPlat1 to randomPlat2
sw $t7, randomPlat4
li $v0, 42 # generate a random number and lw it to randomPlat1
li $a0, 0
li $a1, 14
syscall
addi $a0, $a0, 64 # 2 * 32
sll $a0, $a0, 2 # address from 0 = random box * 4
sw $a0, randomPlat1
jr $ra
moveLevel2: # move 4 platforms
lw $t2, platDown
beq $t2, 10, resetMeet2_level2 # if platDown = 8, reset meet2, platDown and disappear3 to 0 and do
# nothing to randomPlats
addi $t2, $t2, 1 # increment platDown
sw $t2, platDown
lw $t7, randomPlat1 # if platDown != 8, move the platforms
addi $t7, $t7, 128
sw $t7, randomPlat1
lw $t6, randomPlat2
addi $t6, $t6, 128
sw $t6, randomPlat2
lw $t6, randomPlat3 # if the third plat is not moved down twice, move it down
addi $t6, $t6, 128
sw $t6, randomPlat3
lw $t6, randomPlat4 # if the third plat is not moved down twice, move it down
addi $t6, $t6, 128
sw $t6, randomPlat4
lw $t3, height # decrement the height
addi $t3, $t3, -1
sw $t3, height
jr $ra
resetMeet2_level2:
add $t2, $zero, $zero # reset meet2 and platDown to 0
sw $t2, meet2
sw $t2, platDown
lw $t3, randomPlat2 # give value in randomPlat2 to randomPlat3,
sw $t3, randomPlat3
lw $t7, randomPlat4 # give value in randomPlat4 to randomPlat2
sw $t7, randomPlat2
lw $t7, randomPlat1 # give value in randomPlat1 to randomPlat4
sw $t7, randomPlat4
li $v0, 42 # generate a random number and lw it to randomPlat1
li $a0, 0
li $a1, 14
syscall
addi $a0, $a0, 96 # 3 * 32
sll $a0, $a0, 2 # address from 0 = random box * 4
sw $a0, randomPlat1
jr $ra
moveLevel3: # move 3 platforms
lw $t2, platDown
beq $t2, 10, resetMeet2_level3 # if platDown = 10, reset meet2, platDown and disappear3 to 0 and do
# nothing to randomPlats
addi $t2, $t2, 1 # increment platDown
sw $t2, platDown
lw $t7, randomPlat1 # if platDown != 10, move the platforms
addi $t7, $t7, 128
sw $t7, randomPlat1
lw $t6, randomPlat2
addi $t6, $t6, 128
sw $t6, randomPlat2
lw $t6, randomPlat3 # if the third plat is not moved down twice, move it down
addi $t6, $t6, 128
sw $t6, randomPlat3
lw $t3, height # decrement the height
addi $t3, $t3, -1
sw $t3, height
jr $ra
resetMeet2_level3:
add $t2, $zero, $zero # reset meet2 and platDown to 0
sw $t2, meet2
sw $t2, platDown
lw $t3, randomPlat2 # give value in randomPlat2 to randomPlat3,
sw $t3, randomPlat3
lw $t7, randomPlat1 # give value in randomPlat1 to randomPlat2
sw $t7, randomPlat2
li $v0, 42 # generate a random number and lw it to randomPlat1
li $a0, 0
li $a1, 14
syscall
addi $a0, $a0, 320 # 10 * 32
sll $a0, $a0, 2 # address from 0 = random box * 4
sw $a0, randomPlat1
jr $ra
# draw background, platform, Doodle according to the current location information
drawBitMap:
addi $sp, $sp, -4 # save $ra
sw $ra, 0($sp)
jal paintBackground # drawBackground
lw $a0, randomPlat1
jal drawPlatform
lw $a0, randomPlat2
jal drawPlatform
lw $a0, randomPlat3
jal drawPlatform
drawLevel2:
lw $t2, level2
beq $t2, 0, drawLevel1
lw $a0, randomPlat4 # if game level2 = 1, draw extra platform4
jal drawPlatform
j finallyDrawLevel3
drawLevel1:
lw $t1, level1
beq $t1, 0, finallyDrawLevel3
lw $a0, randomPlat4 # if game level1 = 1, draw extra platform4
jal drawPlatform
lw $a0, randomPlat5 # if game level1 = 1, draw extra platform5
jal drawPlatform
finallyDrawLevel3:
lw $a1, doodleGreen
jal drawMyDoodle # drawDoodle
jal readBitMap # readBitMap
lw $ra, 0($sp) # restore $ra
addi $sp, $sp, 4
jr $ra
# update currentDoodlePosition
moveToLeft:
lw $t2, currentDoodlePosition
addi $t2, $t2, -4
sw $t2, currentDoodlePosition
jr $ra
# update currentDoodlePosition
moveToRight:
lw $t2 currentDoodlePosition
addi $t2, $t2, 4
sw $t2, currentDoodlePosition
jr $ra
# calculate where to jump to and update:
# 1. the currentDoodlePosition
# 2. height
jump:
lw $t7, level3
beq $t7, 0, maybeLevel2
addi $s1, $zero, 13 # if $t7 = 1, set $s1 = 10
j jumpUp
maybeLevel2:
lw $t8, level2
beq $t8, 0, mustbeLevel1
addi $s1, $zero, 12 # if $t8 = 1, set $s1 = 12
j jumpUp
mustbeLevel1:
addi $s1, $zero, 8 # if not level3, not level2, then it must be level1
# $s1 = 8 for level3, 9 for level2, 13 for level1
jumpUp:
lw $t6 height
sge $s0, $t6, $s1 # original, the value of $s1 is based on the game level
beq $s0, 1, jumpDown # if $t7 > $s1
#beq $t7, 11, jumpDown # if already jumped up 5 grid
# if not, still jump up
addi $t6, $t6, 1 # update height
sw $t6, height
lw $t2, currentDoodlePosition # update currentDoodlePosition
addi $t2, $t2, -128
sw $t2, currentDoodlePosition
jr $ra
jumpDown:
lw $t7, currentDoodlePosition # update currentDoodlePosition
addi $t7, $t7, 128
sw $t7, currentDoodlePosition
# jump up by changing the value of height to 0
lw $t8, platformGreen # load platformGreen
lw $t9, currentDoodlePosition # load position to ask bitMap
addi $t9, $t9, 772 # currentDoodlePosition + 4 + 6*128 (left feet)
addi $t5, $t9, 8 # currentDoodlePosition + 4 + 6*128 + 8 (right feet)
lw $t7, bitMap($t9) # ask bitMap (left feet)
lw $t4, bitMap($t5) # ask bitMap (right feet)
beq $t7, $t8, meetPlatform # if the color underneath Doodle's left feet is platGreen, reset height to 0
beq $t4, $t8, meetPlatform
jr $ra # if the color is not platGreen, then keep the height = 5, then
# at the next shot, Doodle will still jumpdown
meetPlatform:
add $t6, $zero, $zero # reset the height to 0, then Doodle can jump up at the next shot
sw $t6, height
# check whether the platform hit is at the second platform, if it is true, set meet2 to 1
lw $t7, randomPlat2 # check randomPlat2
lw $t9, currentDoodlePosition # load position to ask bitMap
addi $t9, $t9, 772 # 4 + 6*128 (left feet)
# $t9: plat under left feet
#addi $t6, $t7, -8 # if $t9 < randomPlat2 - 8, don't set the value of meet2 to 1
#slt $s0, $t9, $t6 # $t9 < $t6
#beq $s0, 1, finishedJump
addi $t3, $t7, 36 # if $t9 > randomPlat2 + 28, don't set the value of meet2 to 1
sgt $s0, $t9, $t3 # $t9 > $t3
beq $s0, 1, finishedJump
li $v0, 1
addi $a0, $zero, 5
syscall
addi $t5, $zero, 1 # set meet2 = 1
sw $t5, meet2
finishedJump:
jr $ra
#addi $t8, $t7, 36 # if $t9 > randomPlat3 + 36, don't set the value of meet2 to 1
#sgt $s1, $t9, $t8 # $t9 > $t8
# Doodle
# $a1: color of doodle
drawMyDoodle:
# $a0 is the start blank box before the first head piece
lw $a0, currentDoodlePosition
addi $a0, $a0, 4 # draw head that one unit later than the anchor
add $t3, $zero,$a1 # load color to draw my doodler
add $s0, $zero, $zero # clear index to 0
while_head1:
# draw head1
beq $s0, 3, draw_head2
sw $t3, bitMap($a0) # colored as green
addi $a0, $a0, 4 # move to next MA
addi $s0, $s0, 1
j while_head1
draw_head2:
addi $a0, $a0, 112 # load head2 address
add $s0, $zero, $zero # clear index to 0
while_head2:
beq $s0, 5, draw_head3
sw $t3, bitMap($a0) # colored as green
addi $a0, $a0 4 # move to next MA
addi $s0, $s0, 1
j while_head2
draw_head3:
addi $a0, $a0, 108 # load head3 address
add $s0, $zero, $zero # clear index to 0
while_head3:
beq $s0, 7, draw_head4
sw $t3, bitMap($a0) # colored as green
addi $a0, $a0 4 # move to next MA
addi $s0, $s0, 1
j while_head3
draw_head4:
addi $a0, $a0, 100 # load head3 address
add $s0, $zero, $zero # clear index to 0
while_head4:
beq $s0, 5, draw_leg1
sw $t3, bitMap($a0) # colored as green
addi $a0, $a0 4 # move to next MA
addi $s0, $s0, 1
j while_head4
draw_leg1:
addi $a0, $a0, 112
add $s0, $zero, $zero # clear index to 0
while_leg1:
beq $s0, 2, draw_leg2
sw $t3, bitMap($a0) # colored as green
addi $a0, $a0 128 # move to next MA
addi $s0, $s0, 1
j while_leg1
draw_leg2:
addi $a0, $a0, -256
addi $a0, $a0, 8
add $s0, $zero, $zero # clear index to 0
while_leg2:
beq $s0, 2, finishedDoodle
sw $t3, bitMap($a0) # colored as green
addi $a0, $a0 128 # move to next MA
addi $s0, $s0, 1
j while_leg2
finishedDoodle:
jr $ra
# no argument
paintBackground:
add $t4, $zero, $zero # clear index
lw $t1, backgroundwhite # load background colour
while_paintBackground:
beq $t4, 4096, finishedBackground
sw $t1, bitMap($t4)
addi $t4, $t4, 4
j while_paintBackground
finishedBackground:
jr $ra
# no argument
# $t1: loop index
readBitMap:
lw $t9, displayAddress
# clear index
add $t1, $zero, $zero
while_readBitMap:
beq $t1, 4096, finishedBitMap
lw $t2, bitMap($t1) # load color from bitMap Array
sw $t2, 0($t9) # save color to bitMap display
addi $t1, $t1, 4
addi $t9, $t9, 4
j while_readBitMap
finishedBitMap:
jr $ra
# $a0: staring position of the platform
# draw a platform with length depends on the game level
drawPlatform:
lw $t9, level1
lw $t8, level2
lw $t7, level3
# this is level3
beq $t7, 0, check_level2
addi $s1, $zero, 8 # if $t7 = 1, (level3)platform has length 7
j draw_platform
check_level2:
beq $t8, 0, check_level1 # if $t8 = 1, (level2)platform has length 9
addi $s1, $zero, 9
j draw_platform
check_level1:
addi $s1, $zero, 11
draw_platform:
lw $t2, platformGreen # load platform color
add $t1, $zero, $zero # clear index
while_drawplatform:
beq $t1, $s1, finishedplatform