-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathkitty-jump.asm
2383 lines (1943 loc) · 45 KB
/
kitty-jump.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
#####################################################################
#
# Bitmap Display Configuration:
# - Unit width in pixels: 8
# - Unit height in pixels: 8
# - Display width in pixels: 256
# - Display height in pixels: 512
# - Base Address for Display: 0x10008000 ($gp)
#
#
# Which approved additional features have been implemented?
#
# 1. More platform types:
# - Vertically moving blocks (blue)
# - Horozontally moving blocks (grey)
# - “Fragile" blocks (dotted line)
#
# 2. Boosting / power-ups:
# - Magic Boots - grant higher jumping height (red boots)
# - Rocket suits - boost up the doodler for a long distance (blue arrow)
# - Springs - boost up the doodler for a medium distance (grey spring) (it may not look like a spring though XD)
#
# 3. Fancier graphics:
# - smoothly scrolling screen without flickers or glitches
# - well designed GAMEOVER / PAUSE / RESUME animations
# - a 5x5 cute kitty as the doodler
# - carefully designed item icons / platforms / font in pixelart style
# - dynamically updated scoreboard
#
# 4. Dynamic on-screen notifications:
# - Good! (at 200pts)
# - Wow! (at 500pts)
# - Cool! (at 1000pts)
# - POG! (at 2000pts)
#
# 5. Opponents / lethal creatures:
# - lethal traps (only occur on regular plats; looks like orange fences)
#
# 6. Shields (for protection of Doodler)
# - Shields - protect the doodler from traps (green cross)
#
#
#####################################################################
.data
PROMPT_BEGIN: .asciiz "----------------------------------\nWelcome to KITTY JUMP! Use J and K on your keyboard to move the doodler, and press P to pause the game.\n\n"
PROMPT_GG: .asciiz "Game Over! Press S to play again\n\n"
PROMPT_PAUSE: .asciiz "The kitty has been frozen. Press P again to resume\n\n"
PROMPT_RESUME: .asciiz "The kitty has been defrosted.\n\n"
displayAddress: .word 0x10008000
COLOR_BG: .word 0xfffcf0
COLOR_WHITE: .word 0xfffcf0
COLOR_GREEN: .word 0x82cfb5
COLOR_LIGHT_GREEN: .word 0xb5e3d3
COLOR_YELLOW: .word 0xfce8aa
COLOR_BLACK: .word 0x000000
COLOR_DARK_ORANGE: .word 0xe7a668
COLOR_RED: .word 0xff7373
COLOR_RED_1: .word 0xff8c8c
COLOR_RED_2: .word 0xd86060
COLOR_ORANGE: .word 0xf9cdad
COLOR_CREAM: .word 0xffdcc2
COLOR_BLUE: .word 0x62c1e5
COLOR_DARK_BLUE: .word 0x93bbca
COLOR_LIGHT_BLUE: .word 0xbcd8e2
COLOR_DARK_GREY: .word 0xa99a8e
COLOR_GREY: .word 0xc3b6ad
COLOR_GREY_0: .word 0xb3b3b3
COLOR_GREY_1: .word 0x868686
COLOR_DOODLE_BOOTS: .word 0xfce8aa # variable
COLOR_SHIELD: .word 0xb5e3d3
PLAT_LEN_K: .word 6
PLAT_MIN_DISTANCE: .word 9
JUMP_HEIGHT: .word 20
DOODLE_MAX_HEIGHT: .word 35
DOODLE_INITIAL_POS: .word 6740
MV_SPEED: .word 3 # movement speed for doodler & moving plats (higher value = lower speed)
STEP_LEN: .word 8 # the step length upon every key press
ITEM_GENERATOR_K: .word 20 # 1/20
PLAT_GENERATOR_K: .word 15 # 1/15
TRAP_GENERATOR_K: .word 15 # 1/15
shield_timer: .word -1
boots_timer: .word -1
prevDoodlePos: .word 0x10008000
currDoodlePos: .word 0x10008000 # $s3
prevRocketPos: .word 0x10008000
currScore: .word 0
prevScore: .word 0
face: .word 0 # 0 = facing left; 1 = facing right
platNum: .word 1
plat_list: .space 500
prev_plats_list: .space 500
# 0 4 8 12 16 20
# leftPos, rightPos, randomItem, randomItemPos, platformType, platformTypeArg
saved_list: .word 6980,7032,0,0,0,0, 5532,5568,0,0,0,0, 4168,4204,0,0,0,0, 2832,2872,0,0,0,0, 1740,1772,0,0,0,0
# every num takes 14 places 0 1 2 3 4 5 6 7 8 9
nums_list: .word 0,4,8,128,136,256,264,384,392,512,516,520,888,888, 0,4,132,260,388,512,516,520,888,888,888,888,888,888, 0,4,8,136,256,260,264,384,512,516,520,888,888,888, 0,4,8,136,256,260,264,392,512,516,520,888,888,888, 0,8,128,136,256,260,264,392,520,888,888,888,888,888, 0,4,8,128,256,260,264,392,512,516,520,888,888,888, 0,4,8,128,256,260,264,384,392,512,516,520,888,888, 0,4,8,136,264,392,520,888,888,888,888,888,888,888, 0,4,8,128,136,256,260,264,384,392,512,516,520,888, 0,4,8,128,136,256,260,264,392,512,516,520,888,888
# alphabet
letter_G: .word 4, 8, 128, 256, 384, 516, 520, 396, 268, 264 ,888
letter_A: .word 4,8,128,256,260,264,384,512,140,268,396,524,888
letter_M: .word 4,12,128,256,384,512,136,264,392,520,144,272,400,528,888
letter_E: .word 0,4,8,128,256,260,384,512,516,520,888
letter_O: .word 4,8,128,256,384,516,520,140,268,396,888
letter_V: .word 0,128,256,388,520,396,272,144,16,888
letter_R: .word 0,4,8,128,256,384,512,140,260,264,392,524,888
letter_P: .word 0,4,8,128,256,384,512,140,260,264,888
letter_S: .word 4,8,12,128,260,264,396,512,516,520,888
letter_U: .word 0,12,128,256,384,516,520,140,268,396,888
letter_D: .word 0,4,8,128,256,384,512,516,520,140,268,396,888
letter_C: .word 4,8,128,256,384, 396,516,520,140,888
letter_W: .word 0,16,128,256,384,516,136,264,392,524,144,272,400,888
letter_L: .word 0,128,256,384,512,516,520,888
letter_K: .word 0,128,256,384,512, 12,136,260,392,524, 888
letter_I: .word 0,4,8, 132,260,388, 512,516,520, 888
letter_T: .word 0,4,8, 132,260,388,516, 888
letter_Y: .word 0,132,264,140,16,392,520, 888
letter_J: .word 0,4,8,12, 136,264,392,516,384, 888
letter_block: .word 0,4,8,12,16, 128,132,136,140,144, 256,260,264,268,272, 384,388,392,396,400, 512,516,520,524,528, 888
letter_excl_mark: .word 0,128,256,512, 888
_6x1_bar: .word 0,128,256,384,512,640, 888
_5x1_bar: .word 0,128,256,384,512, 888
rocket_icon: .word 0,-124,-116,-248,-244,-380,-376,-372, 888
shield: .word 8,12,16,20,24, 132, 156, 256,384,512,640,768, 900,904, 1032,1036,1040,1044,1048, 924,920, 288,416,544,672,800, 888
.text
main:
li $v0, 4
la $a0, PROMPT_BEGIN
syscall
lw $t0, displayAddress # $t0 stores the base address for display
jal reset_canva # set the canva to COLOR_BG
lw $t1, DOODLE_INITIAL_POS
add $s3, $t0, $t1 # reset initial position
la $s0, currScore
sw $0, 0($s0) # reset currScore
la $t1, platNum
li $t2, 3
sw $t2, 0($t1) # reset platNum
li $t1, -1
sw $t1, shield_timer # reset shield timer
li $t1, -1
sw $t1, boots_timer # reset boots timer
jal disarm_boots
jal to_difficulty_0 # reset the difficulty to level 0
jal reset_platform_lists # reset plats_list & prev_plats_list
jal add_platform
jal add_platform
jal add_platform
jal add_platform
jal add_platform
jal add_platform
jal add_platform
jal add_platform
jal add_platform # add initial plats
WHILE:
lw $t8, 0xffff0000
bne $t8, 1, skip_check_keyboard_input
#check_keyboard_input
lw $t1, 0xffff0004
bne $t1, 0x6A, skip_j_call
jal respond_to_j
skip_j_call:
bne $t1, 0x6B, skip_k_call
jal respond_to_k
skip_k_call:
bne $t1, 0x70, skip_p_call
jal respond_to_p
skip_p_call:
skip_check_keyboard_input:
#sleep
li $v0, 32
li $a0, 10
syscall
jal refresh_screen
addi $t8, $t0, 8064 # if doodler falls to bottom, game over
bge $s3, $t8, game_over
j WHILE
Exit:
li $v0, 10 # terminate the program
syscall
respond_to_j:
addi $sp, $sp, -4 # move the stack pointer to increase stack size
sw $ra, 0($sp)
lw $t2, STEP_LEN
sub $s3, $s3, $t2
#change the facing direction of doodler
lw $t2, face
li $t2, 0
sw $t2, face
lw $ra, 0($sp) # load the word at the top of the stack
addi $sp, $sp, 4 # decrease the size of the stack
jr $ra
respond_to_k:
addi $sp, $sp, -4
sw $ra, 0($sp)
lw $t2, STEP_LEN
add $s3, $s3, $t2
#change the facing direction of doodler
lw $t2, face
li $t2, 1
sw $t2, face
lw $ra, 0($sp)
addi $sp, $sp, 4
jr $ra
respond_to_p: # pause/ continue
addi $sp, $sp, -4
sw $ra, 0($sp)
li $v0, 4
la $a0, PROMPT_PAUSE
syscall
add $a1, $t0, 3860 # 31*128 + 5*4
jal pause_display
pause_while:
li $v0, 32
li $a0, 10
syscall
lw $t8, 0xffff0000
bne $t8, 1, skip_check_keyboard_input_during_pause
#check_keyboard_input
lw $t1, 0xffff0004
bne $t1, 0x70, pause_while
jal reset_canva
jal draw
add $a1, $t0, 3848
jal resume_display
jal reset_canva
li $v0, 4
la $a0, PROMPT_RESUME
syscall
j WHILE
skip_check_keyboard_input_during_pause:
j pause_while
lw $ra, 0($sp)
addi $sp, $sp, 4
jr $ra
refresh_screen: # 'jal draw' 3 times
addi $sp, $sp, -4
sw $ra, 0($sp)
jal get_doodle_height
add $v0, $v0, $s4 # $v0 = expected height
lw $t6, DOODLE_MAX_HEIGHT
sub $t6, $v0, $t6 # difference between DOODLE_MAX_HEIGHT and expected height
blez $t6, skip_scroll_plat # if expected height <= 0, skip scrolling
# scroll_plat
addi $a0, $0, 1
subi $t6, $t6, 1 #
subi $s4, $s4, 1 # jump -1
lw $t7, currScore
add $t7, $t7, 1
sw $t7, currScore # add score by 1
jal scroll_platform
jal draw
skip_scroll_plat:
beqz $s5, start_move_cond
addi $s5, $s5, -1
j fall_exit
# every "MV_SPEED" frames
start_move_cond:
lw $s5, MV_SPEED
jal notifi_display
# for shield
lw $t2, shield_timer
bltz $t2, skip_shield_countdown
addi $t2, $t2, -1
sw $t2, shield_timer
skip_shield_countdown:
# for boots
lw $t2, boots_timer
bltz $t2, skip_disarm_boots
beqz $t2, disarm_boots_call
addi $t2, $t2, -1
sw $t2, boots_timer
j skip_disarm_boots
disarm_boots_call:
jal disarm_boots
addi $t2, $0, -1
sw $t2, boots_timer
skip_disarm_boots:
# for mobile plats
la $t1, plat_list
lw $t2, platNum
check_mobile_plat_loop:
beqz $t2, check_mobile_plat_loop_exit
lw $t3, 16($t1)
bne $t3, 1, skip_move_hori_mobile_plat
# move_hori
move $a0, $t1
jal move_horizontal_mobile_platform
skip_move_hori_mobile_plat:
bne $t3, 3, skip_move_vert_mobile_plat
#move_vert
move $a0, $t1
jal move_vertical_mobile_platform
skip_vert:
skip_move_vert_mobile_plat:
addi $t1, $t1, 24
subi $t2, $t2, 1
j check_mobile_plat_loop
check_mobile_plat_loop_exit:
ble $s4, 0, fall_call # $s4 == 0 means it is falling
j jump_call
fall_call:
addi $s3, $s3, 128
addi $t8, $s3, 16 # $t8 is the left margin of the doodler
la $t1, plat_list
lw $s6, platNum
# {loop START
check_fall_on_plat_loop:
blez $s6, check_fall_on_plat_loop_exit
lw $t3, 0($t1)
lw $t9, 16($t1)
bge $t8, $t3, check_right_edge # if left edge < leftPos. then it can't be on a plat, skip checking right edge
beq $t9, 3, go_rough_check1
j skip_check_right_edge
check_right_edge:
lw $t4, 4($t1) # load word "rightPos" -> $t4
blt $s3, $t4, collide_with_plat # if right edge < rightPos, change to jump
beq $t9, 3, go_rough_check1
j skip_check_right_edge
go_rough_check1:
addi $t9, $s3, 144
blt $t9, $t3, skip_rough_check1
addi $t9, $s3, 128
lw $t4, 4($t1) # load word "rightPos" -> $t4
blt $t9, $t4, add_128 # if right edge < rightPos, change to jump
skip_rough_check1:
go_rough_check2:
addi $t9, $s3, -112
blt $t9, $t3, skip_check_right_edge
addi $t9, $s3, -128
lw $t4, 4($t1) # load word "rightPos" -> $t4
blt $t9, $t4, add_128
j skip_check_right_edge
add_128:
add $s3, $s3, 128
j collide_with_plat # if right edge < rightPos, change to jump
collide_with_plat:
lw $t7, 8($t1)
bne $t7, 1, skip_rocket_trigger
lw $t6, 12($t1)
sub $t5, $s3, $t3
div $t5, $t5, 128 #distance between s3 and the item
mfhi $t5
sub $t5, $t6, $t5
ble $t5, -16, skip_items_trigger
bge $t5, 20, skip_items_trigger
li $a0, 10
jal rocket
jal reset_canva
j skip_items_trigger
skip_rocket_trigger:
# boots check
bne $t7, 2, skip_boots_trigger
lw $t6, 12($t1)
sub $t5, $s3, $t3
div $t5, $t5, 128 #distance between s3 and the item
mfhi $t5
sub $t5, $t6, $t5
ble $t5, -16, skip_items_trigger
bge $t5, 20, skip_items_trigger
jal get_boots
j skip_items_trigger
skip_boots_trigger:
# spring check
bne $t7, 3, skip_spring_trigger
lw $t6, 12($t1)
sub $t5, $s3, $t3
div $t5, $t5, 128 #distance between s3 and the item
mfhi $t5
sub $t5, $t6, $t5
ble $t5, -16, skip_items_trigger
bge $t5, 20, skip_items_trigger
li $a0, 4
jal rocket
j skip_items_trigger
skip_spring_trigger:
# SHIELD check
bne $t7, 4, skip_shield_trigger
lw $t6, 12($t1)
sub $t5, $s3, $t3
div $t5, $t5, 128 #distance between s3 and the item
mfhi $t5
sub $t5, $t6, $t5
ble $t5, -16, skip_items_trigger
bge $t5, 20, skip_items_trigger
jal get_shield
j skip_items_trigger
skip_shield_trigger:
# TRAP check
bne $t7, 5, skip_trap_trigger
lw $t6, 12($t1)
sub $t5, $s3, $t3
div $t5, $t5, 128 #distance between s3 and the item
mfhi $t5
sub $t5, $t6, $t5
ble $t5, -16, skip_items_trigger
bge $t5, 20, skip_items_trigger
lw $t5, shield_timer
bgtz $t5, skip_items_trigger
j game_over
j skip_items_trigger
skip_trap_trigger:
skip_items_trigger:
# fragile check
lw $t7, 16($t1)
bne $t7, 2, skip_fragile
add $t7, $0, 0
sw $t7, 0($t1)
add $t7, $0, 0
sw $t7, 4($t1)
skip_fragile:
j change_to_jump
skip_check_right_edge:
addi $s6, $s6, -1
addi $t1, $t1, 24
j check_fall_on_plat_loop
check_fall_on_plat_loop_exit:
# loop END }
jal draw
j fall_exit
change_to_jump:
lw $t5, platNum
sub $t5, $t5, $s6
sub $t5, $t5, 2
refresh_plats_loop:
blez $t5, refresh_plats_loop_exit
jal add_platform
jal remove_lowest_platform
addi $t5, $t5, -1
j refresh_plats_loop
refresh_plats_loop_exit:
lw $s4, JUMP_HEIGHT
j jump_call
jump_call:
addi $s3, $s3, -128
addi $s4, $s4, -1
jal draw
fall_exit:
lw $ra, 0($sp)
addi $sp, $sp, 4
jr $ra
draw:
addi $sp, $sp, -12
sw $ra, 0($sp)
sw $t6, 4($sp)
sw $t5, 8($sp)
jal draw_doodle # draw doodle
la $t1, plat_list
la $t3, prev_plats_list
lw $t2, platNum
draw_plats_loop: # draw platforms
blez $t2, draw_plats_loop_exit
add $a0, $0, $t1
add $a1, $0, $t3
jal draw_platform
lw $t5, 0($a0) # store data into prev_plat_list
sw $t5, 0($a1)
lw $t5, 4($a0)
sw $t5, 4($a1)
lw $t5, 8($a0)
sw $t5, 8($a1)
lw $t5, 12($a0)
sw $t5, 12($a1)
lw $t5, 16($a0)
sw $t5, 16($a1)
lw $t5, 20($a0)
sw $t5, 20($a1)
addi $t3, $t3, 24
addi $t1, $t1, 24
subi $t2, $t2, 1
j draw_plats_loop
draw_plats_loop_exit:
jal draw_doodle # draw doodler again to avoid glitches
jal draw_scoreboard # draw scoreboard
lw $t1, currScore
beq $t1, 6 reset_title
bge $t1, 6, skip_title
add $a1, $t0, 396
lw $a2, COLOR_DARK_GREY
jal title_display
j skip_title
reset_title:
add $a1, $t0, 396
lw $a2, COLOR_BG
jal title_display
add $t1, $t1, 1
sw $t1, currScore
skip_title:
lw $ra, 0($sp)
lw $t6, 4($sp)
lw $t5, 8($sp)
addi $sp, $sp, 12
jr $ra
get_shield:
addi $sp, $sp, -8
sw $ra, 0($sp)
sw $t5, 4($sp)
#lw $t5, COLOR_LIGHT_GREEN
#sw $t5, COLOR_SHIELD
li $t5, 100
sw $t5, shield_timer
lw $ra, 0($sp)
lw $t5, 4($sp)
addi $sp, $sp, 8
jr $ra
get_boots:
addi $sp, $sp, -8
sw $ra, 0($sp)
sw $t5, 4($sp)
lw $t5, COLOR_RED
sw $t5, COLOR_DOODLE_BOOTS
li $t5, 35
sw $t5, JUMP_HEIGHT
li $t5, 100
sw $t5, boots_timer
lw $ra, 0($sp)
lw $t5, 4($sp)
addi $sp, $sp, 8
jr $ra
disarm_boots:
addi $sp, $sp, -8
sw $ra, 0($sp)
sw $t5, 4($sp)
lw $t5, COLOR_YELLOW
sw $t5, COLOR_DOODLE_BOOTS
li $t5, 20
sw $t5, JUMP_HEIGHT
lw $ra, 0($sp)
lw $t5, 4($sp)
addi $sp, $sp, 8
jr $ra
rocket:
addi $sp, $sp, -8
sw $ra, 0($sp)
sw $t5, 4($sp)
move $t5, $a0
lw $t2, COLOR_BLUE # if > 8, rocket
bgt $t5, 8, skip_paint_boots_grey
lw $t2, COLOR_GREY_1
skip_paint_boots_grey:
sw $t2, COLOR_DOODLE_BOOTS
rocket_jump_loop:
blez $t5, rocket_jump_loop_exit
lw $t8, 0xffff0000
bne $t8, 1, skip_jk_calls
lw $t1, 0xffff0004
beq $t1, 0x6A, J_call2
beq $t1, 0x6B, K_call2
j skip_jk_calls
J_call2:
jal respond_to_j
j rocket_jump_loop
K_call2:
jal respond_to_k
j rocket_jump_loop
skip_jk_calls:
jal add_platform
lw $t6, PLAT_MIN_DISTANCE
addi $t6, $t6, 1
scroll_rocket_loop:
beqz $t6,scroll_rocket_loop_exit
addi $a0, $0, 1
jal scroll_platform
jal draw
lw $s0, currScore
addi $s0, $s0, 1
sw $s0, currScore
addi $t6, $t6, -1
li $v0, 32
li $a0, 5
syscall
j scroll_rocket_loop
scroll_rocket_loop_exit:
jal remove_lowest_platform
addi $t5, $t5, -1
j rocket_jump_loop
rocket_jump_loop_exit:
lw $s4, JUMP_HEIGHT
div $s4, $s4, 2
lw $t2, COLOR_YELLOW
sw $t2, COLOR_DOODLE_BOOTS
lw $ra, 0($sp)
lw $t5, 4($sp)
addi $sp, $sp, 8
jr $ra
# $a0 = the height of scroll
scroll_platform:
addi $sp, $sp, -16
sw $ra, 0($sp)
sw $t2, 4($sp)
sw $t4, 8($sp)
sw $t5, 12($sp)
addi $t4, $0, 128
mult $a0, $t4
mflo $a0
la $t1, plat_list
lw $t2, platNum
scroll_plat_while:
beqz $t2, scroll_plat_exit
lw $t3, 0($t1)
beqz $t3, skip_this_plat
add $t3, $t3, $a0
sw $t3, 0($t1)
lw $t3, 4($t1)
add $t3, $t3, $a0
sw $t3, 4($t1)
skip_this_plat:
addi $t1, $t1, 24
subi $t2, $t2, 1
j scroll_plat_while
scroll_plat_exit:
#jal draw
lw $ra, 0($sp)
lw $t2, 4($sp)
lw $t4, 8($sp)
lw $t5, 12($sp)
addi $sp, $sp, 16
jr $ra
# $a0 = address of leftPos; $a1 = address of prevLeftPos; $a2 = address of itemPos
draw_platform:
addi $sp, $sp, -28
sw $ra, 0($sp)
sw $a0, 4($sp)
sw $a1, 8($sp)
sw $t1, 12($sp)
sw $t2, 16($sp)
sw $t3, 20($sp)
sw $t4, 24($sp)
lw $t1, 0($a0) # leftPos
lw $t2, 4($a0) # rightPos
lw $t3, 0($a1) # prevLeftPos
lw $t4, 4($a1) # prevRightPos
addi $t5, $t0, -256
ble $t3, $t5, draw_platform_exit #if the platform is outside the canva, go exit
lw $t5, 8($a1) # $t5 = itemArg of the previous platform
bne $t1, $t3, erasePrevPlat
beq $t2, $t4, erasePrevPlat_exit # if the plat did not move, then skip the erasing process
lw $s0, COLOR_BG
# erase the previous painted platform
erasePrevPlat:
bge $t3, $t4, erasePrevPlat_exit
sw $s0, 0($t3)
beqz $t5, skip_top_erase # if previously no item painted, skip some rerasing process
sw $s0, -128($t3)
sw $s0, -256($t3)
sw $s0, -384($t3)
sw $s0, -512($t3)
skip_top_erase:
sw $s0, 128($t3)
addi $t3, $t3, 4
j erasePrevPlat
erasePrevPlat_exit:
beqz $t1, draw_platform_exit # if something = 0 (generated after fragile plat disappears), skip drawing
## SET COLORS; $s1 = plat color; $t4 = plat base color
lw $s1, COLOR_ORANGE # 0 = regular plat; set the color to be orange
lw $t4, COLOR_CREAM
lw $s2, 16($a0)
beq $s2, 2, draw_fragile_plat_loop # 2 = fragile plat
bne $s2, 3, skip_paint_grey # 3 = vertically moving plat
lw $s1, COLOR_DARK_GREY # set the color to be grey
lw $t4, COLOR_GREY
skip_paint_grey:
bne $s2, 1, skip_paint_blue # 1 = horonzontally moving plat
lw $s1, COLOR_DARK_BLUE # set the color to be blue
lw $t4, COLOR_LIGHT_BLUE
skip_paint_blue:
# DRAW the platform (0/1/3)
addi $t3, $t1, 132 # $t3 = left position of plat base ( stored before $t1 changes )
draw_plat_loop:
bge $t1, $t2, draw_plat_loop_exit
sw $s1, 0($t1)
addi $t1, $t1, 4
j draw_plat_loop
draw_plat_loop_exit:
# DRAW the platform base
addi $t2, $t2, 124 # $t2 = right position of plat base
draw_plat_base_loop: # iterate from $t3 -> $t2
bge $t3, $t2, draw_plat_base_loop_exit
sw $t4, 0($t3)
addi $t3, $t3, 4
j draw_plat_base_loop
draw_plat_base_loop_exit:
j draw_fragile_plat_loop_exit
# DRAW fragile platform (2)
draw_fragile_plat_loop: # iterate from $t1 -> $t2
bge $t1, $t2, draw_fragile_plat_loop_exit
sw $s1, 0($t1)
addi $t1, $t1, 8
j draw_fragile_plat_loop
draw_fragile_plat_loop_exit:
# draw rocket icon
lw $t2, 8($a0)
bne $t2, 1, skip_rocket_draw
lw $t2, 12($a0)
lw $t3, 0($a0)
add $t2, $t2, $t3
addi $t2, $t2, -128
lw $a2, COLOR_BLUE
la $a0, rocket_icon
move $a1, $t2
sw $t2, prevRocketPos
jal draw_single_letter
skip_rocket_draw:
# draw boots icon
lw $t2, 8($a0)
bne $t2, 2, skip_boots_draw
lw $t2, 12($a0)
lw $t3, 0($a0)
add $t2, $t2, $t3
addi $t2, $t2, -256
lw $s2, COLOR_RED_2
sw $s2, 0($t2)
sw $s2, 4($t2)
sw $s2, 8($t2)
sw $s2, 12($t2)
lw $s2, COLOR_RED_1
sw $s2, -128($t2)
sw $s2, -256($t2)
lw $s2, COLOR_RED
sw $s2, -124($t2)
sw $s2, -120($t2)
sw $s2, -116($t2)
sw $s2, -252($t2)
skip_boots_draw:
# draw spring icon
lw $t2, 8($a0)
bne $t2, 3, skip_spring_draw
lw $t2, 12($a0)
lw $t3, 0($a0)
add $t2, $t2, $t3
addi $t2, $t2, -384
lw $s2, COLOR_GREY_1
sw $s2, 0($t2)
sw $s2, 4($t2)
sw $s2, 8($t2)
sw $s2, 12($t2)
sw $s2, 128($t2)
sw $s2, 132($t2)
sw $s2, 264($t2)
sw $s2, 268($t2)
lw $s2, COLOR_GREY_0
sw $s2, 136($t2)
sw $s2, 260($t2)
skip_spring_draw:
# draw shield icon
lw $t2, 8($a0)
bne $t2, 4, skip_shield_draw
lw $t2, 12($a0)
lw $t3, 0($a0)
add $t2, $t2, $t3
addi $t2, $t2, -384
lw $s2, COLOR_GREEN
sw $s2, 0($t2)
sw $s2, 4($t2)
sw $s2, 8($t2)
sw $s2, -124($t2)
sw $s2, 132($t2)
skip_shield_draw:
# draw trap icon
lw $t2, 8($a0)
bne $t2, 5, skip_trap_draw
lw $t2, 12($a0)
lw $t3, 0($a0)
add $t2, $t2, $t3
addi $t2, $t2, -128
lw $s2, COLOR_ORANGE
sw $s2, 0($t2)
sw $s2, 8($t2)
sw $s2, 16($t2)
skip_trap_draw:
draw_platform_exit:
lw $ra, 0($sp)
lw $a0, 4($sp)
lw $a1, 8($sp)
lw $t1, 12($sp)
lw $t2, 16($sp)
lw $t3, 20($sp)
lw $t4, 24($sp)
addi $sp, $sp, 28
jr $ra
remove_lowest_platform:
addi $sp, $sp, -4
sw $ra, 0($sp)
la $t1, plat_list
lw $t2, platNum # $t2 = platNum
addi $t2, $t2, -1 # $t2 -= 1
sw $t2, platNum # store it back to platNum
li $t3, 6
mult $t3, $t2
mflo $t2 # number of the nodes in the list
# e.g. if there were 3 plats in the list, 1 removed ($t2 = $t2 - 1), $t2 = 12
# shift all platform data left by 1 unit (24 nodes)
shift_list_down_loop: # iterate from $t2 -> 0
blez $t2, shift_list_down_loop_exit
lw $t3, 24($t1)
sw $t3, 0($t1)
addi $t1, $t1, 4
addi $t2, $t2, -1
j shift_list_down_loop
shift_list_down_loop_exit:
lw $ra, 0($sp)
addi $sp, $sp, 4
jr $ra
add_platform:
addi $sp, $sp, -8
sw $t5, 4($sp)
sw $ra, 0($sp)
la $t4, platNum
lw $t2, 0($t4)
addi $t3, $t2, 1