-
Notifications
You must be signed in to change notification settings - Fork 0
/
game
6017 lines (5023 loc) · 97.1 KB
/
game
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
#####################################################################
#
# CSCB58 Winter 2022 Assembly Final Project
# University of Toronto, Scarborough
#
# Student: Howie Chen, 1007477687, chencun1, [email protected]
#
# Bitmap Display Configuration:
# - Unit width in pixels: 4
# - Unit height in pixels: 4
# - Display width in pixels: 512
# - Display height in pixels: 512
# - Base Address for Display: 0x10008000 ($gp)
#
# Which milestones have been reached in this submission?
# - Milestone 1/2/3
#
# Which approved features have been implemented for milestone 3?
# 1. Health/Score [2]
# 2. Fail Condition [1]
# 3. Win Condition [1]
# 4. Moving platforms [2]
# 5. Enemies shoot [2]
# 6. Double jump [1]
#
#
# Link to video demonstration for final submission:
# - https://play.library.utoronto.ca/watch/5364b96b077cb6d34b3b4ad1f4ac7f6f
#
# Are you OK with us sharing the video with people outside course staff?
# - yes, and please share this project github link as well!
# - https://github.com/Zeneos/B58FinalProject
#
# Any additional information that the TA needs to know:
# - A/D move side to side, Q/W/E jump left/up/right, red kills, green wins
#
#####################################################################
# Global registers
# $s0 - location of the address to store memory variables
# $s1 - position of the player pixel
# $s2 - key input
# $s3 - time
# $s4 - laser 1 pos
# $s5 - laser 2 pos
# $s6 - game timer, from 0 to 240
.eqv BASE_ADDRESS 0x10008000 # Base address for the bitmap
.data
padding: .space 66000 # Empty space to prevent the game data from being overwritten cause bitmap
variables: .space 100 # 0: base address, 4-12: jump right/up/left tracker, 16: lives, 20: invuln timer
# 24: momentum tracker, 28: double nump token, 32: game is over when 1
# 36+: enemy pos every 4
.text
.globl main
main:
# Reset everything
li $s0, 0
li $s1, 0
li $s2, 0
li $s3, 0
li $s4, 0
li $s5, 0
li $s6, 0
# Get base address
li $s1, BASE_ADDRESS
# Load variables
la $s0, variables
# Store base address
sw $s1, 0($s0)
# Store 0 vars
sw $zero, 4($s0)
sw $zero, 8($s0)
sw $zero, 12($s0)
sw $zero, 20($s0)
sw $zero, 24($s0)
sw $zero, 32($s0)
# Store non 0 vars
li $t0, 3
sw $t0, 16($s0)
li $t0, 1
sw $t0, 28($s0)
# Spawn the player pixel
addi $s1, $s1, 61960
# Spawn enemy
lw $t0, 0($s0)
addi $t0, $t0, 12028
sw $t0, 36($s0)
addi $t0, $t0, -3060
sw $t0, 40($s0)
# Clear the screen
jal clear_screen
# Draw
jal draw_floor
jal draw_menu
jal set_plats
# Run the game
jal run_cycle
li $v0, 10 # terminate the program gracefully
syscall
###################################################################
run_cycle: # Run the game cycle
# Save return
sw $ra, 0($sp)
addi $sp, $sp, -4
run_cycle_loop: # Start of the game loop
# Keeping time
li $v0, 30
syscall
move $a0, $s3
# Check for key input
li $t0, 0xffff0000
lw $t1, 0($t0)
bne $t1, 1, run_cycle_next
lw $s2, 4($t0)
# Check for restart command
beq $s2, 0x70, main
# Check for movement commands
jal check_move
run_cycle_next: # Skip movement checks
# Don't move plats if game is over
lw $t0, 32($s0)
addi $t0, $t0, -1
beqz $t0, run_cycle_next_2
# Move platforms
jal move_plat
# Move enemies
jal check_enemy
# Clear the shot if
li $t0, 140
div $s6, $t0
mfhi $t0
bnez $t0, run_cycle_next_2
jal clear_shot
run_cycle_next_2: # Jump to
# Check if win
jal check_win
# Check if damage
jal check_damage
# Check if jumping
jal check_jump
# Check if landed
jal check_double
# Decrement invuln counter
jal invuln_counter
# Increment counter or reset if at max
jal run_counter
# Check counter
jal momentum_counter
# Draw the player
jal draw_player
# Wait to next cycle
li $v0, 30
syscall
move $a0, $t0
sub $t0, $t0, $s3
addi $t1, $zero, 25
sub $t0, $t1, $t0
bgtz $t0, run_cycle_default_wait
li $t0, 25
run_cycle_default_wait:
li $v0, 32
addi $a0, $t0, 0
syscall
j run_cycle_loop
run_cycle_stop: # Stop the program
# Return
addi $sp, $sp, 4
lw $ra, 0($sp)
jr $ra
######################################################################
#### CALCULATION FUNCTIONS ###########################################
######################################################################
check_enemy: # Move the enemies
# Save return
sw $ra, 0($sp)
addi $sp, $sp, -4
# Enemy shoots every 120th frame
li $t0, 120
div $s6, $t0
mfhi $t0
beqz $t0, check_enemy_shoot
# Move enemies every 8th frame
li $t0, 8
div $s6, $t0
mfhi $t0
beq $t0, $zero, check_enemy_1
check_enemy_next: # Jump to
# Move enemies every 3th frame
li $t0, 3
div $s6, $t0
mfhi $t0
beq $t0, $zero, check_enemy_2
check_enemy_end: # Function end
# Return
addi $sp, $sp, 4
lw $ra, 0($sp)
jr $ra
check_enemy_shoot:
# Get the enemy pos
lw $t0, 36($s0)
li $t1, 512
div $t0, $t1
mfhi $t1
# Get the starting position
lw $t2, 36($s0)
addi $s4, $t2, 0
# Get the end position
addi $t3, $t2, 65536
# Get black and red
li $t4, 0x00fe0000
li $t5, 0x00000000
check_enemy_shoot_loop: # Loop for drawing plats
# End loop
beq $t2, $t3, check_enemy_shoot_loop_end
# Draw a plat if tile is black
lw $t6, 0($t2)
beq $t5, $t6, check_enemy_shoot_loop_draw
# Next loop
addi $t2, $t2, 512
j check_enemy_shoot_loop
check_enemy_shoot_loop_end: # End of loop
# Return
j check_enemy_shoot_2
check_enemy_shoot_loop_draw: # Draw red
# Draw and end
sw $t4, 0($t2)
j check_enemy_shoot_loop
check_enemy_shoot_2:
# Get the enemy pos
lw $t0, 40($s0)
li $t1, 512
div $t0, $t1
mfhi $t1
# Get the starting position
lw $t2, 40($s0)
addi $s5, $t2, 0
# Get the end position
addi $t3, $t2, 65536
# Get black and red
li $t4, 0x00fe0000
li $t5, 0x00000000
check_enemy_shoot_2_loop: # Loop for drawing plats
# End loop
beq $t2, $t3, check_enemy_shoot_2_loop_end
# Draw a plat if tile is black
lw $t6, 0($t2)
beq $t5, $t6, check_enemy_shoot_2_loop_draw
# Next loop
addi $t2, $t2, 512
j check_enemy_shoot_2_loop
check_enemy_shoot_2_loop_end: # End of loop
# Return
addi $sp, $sp, 4
lw $ra, 0($sp)
jr $ra
check_enemy_shoot_2_loop_draw: # Draw red
# Draw and end
sw $t4, 0($t2)
j check_enemy_shoot_2_loop
check_enemy_1: # Move enemy
# Get player pos
li $t0, 512
div $s1, $t0
mfhi $t1
# Get the enemy pos
lw $t2, 36($s0)
div $t2, $t0
mfhi $t2
# Get the relative position
sub $t1, $t2, $t1
bltz $t1, check_enemy_1_right
bgtz $t1, check_enemy_1_left
j check_enemy_next
check_enemy_1_right: # Move enemy right
# Move enemy right
lw $t0, 36($s0)
sw $t0, 0($sp)
addi $sp, $sp, -4
jal move_enemy_right
addi $sp, $sp, 4
lw $t0, 0($sp)
sw $t0, 36($s0)
j check_enemy_next
check_enemy_1_left: # Move enemy left
# Move enemy left
lw $t0, 36($s0)
sw $t0, 0($sp)
addi $sp, $sp, -4
jal move_enemy_left
addi $sp, $sp, 4
lw $t0, 0($sp)
sw $t0, 36($s0)
j check_enemy_next
check_enemy_2: # Move enemy
# Get timer
li $t0, 120
blt $s6, $t0, check_enemy_2_left
bge $s6, $t0, check_enemy_2_right
j check_enemy_end
check_enemy_2_right: # Move enemy right
# Move enemy right
lw $t0, 40($s0)
sw $t0, 0($sp)
addi $sp, $sp, -4
jal move_enemy_right
addi $sp, $sp, 4
lw $t0, 0($sp)
sw $t0, 40($s0)
j check_enemy_end
check_enemy_2_left: # Move enemy left
# Move enemy left
lw $t0, 40($s0)
sw $t0, 0($sp)
addi $sp, $sp, -4
jal move_enemy_left
addi $sp, $sp, 4
lw $t0, 0($sp)
sw $t0, 40($s0)
j check_enemy_end
######################################################################
check_double: # Check for double jump refresh
# Get black
li $t0, 0x00000000
# Check below the player
lw $t1, 1020($s1)
bne $t0, $t1, check_double_yes
lw $t1, 1024($s1)
bne $t0, $t1, check_double_yes
lw $t1, 1028($s1)
bne $t0, $t1, check_double_yes
jr $ra
check_double_yes: # Is landed
# Set the double jump token
li $t0, 1
sw $s0, 28($s0)
jr $ra
######################################################################
check_win: # Check if the player wins
# Save return
sw $ra, 0($sp)
addi $sp, $sp, -4
# Get red
li $t0, 0x0000ff00
# Check every tile touching the player
lw $t1, -1028($s1)
beq $t0, $t1, check_win_win
lw $t1, -1024($s1)
beq $t0, $t1, check_win_win
lw $t1, -1020($s1)
beq $t0, $t1, check_win_win
lw $t1, -520($s1)
beq $t0, $t1, check_win_win
lw $t1, -8($s1)
beq $t0, $t1, check_win_win
lw $t1, 504($s1)
beq $t0, $t1, check_win_win
lw $t1, -504($s1)
beq $t0, $t1, check_win_win
lw $t1, 8($s1)
beq $t0, $t1, check_win_win
lw $t1, 520($s1)
beq $t0, $t1, check_win_win
lw $t1, 1020($s1)
beq $t0, $t1, check_win_win
lw $t1, 1024($s1)
beq $t0, $t1, check_win_win
lw $t1, 1028($s1)
beq $t0, $t1, check_win_win
# Return
addi $sp, $sp, 4
lw $ra, 0($sp)
jr $ra
check_win_win: # Take damage potentially
jal win_game
# Return
addi $sp, $sp, 4
lw $ra, 0($sp)
jr $ra
#####################################################################
check_damage: # Check if the player takes damage
# Save return
sw $ra, 0($sp)
addi $sp, $sp, -4
# Get red
li $t0, 0x00ff0000
# Check every tile touching the player
lw $t1, -1028($s1)
beq $t0, $t1, check_damage_damage
lw $t1, -1024($s1)
beq $t0, $t1, check_damage_damage
lw $t1, -1020($s1)
beq $t0, $t1, check_damage_damage
lw $t1, -520($s1)
beq $t0, $t1, check_damage_damage
lw $t1, -8($s1)
beq $t0, $t1, check_damage_damage
lw $t1, 504($s1)
beq $t0, $t1, check_damage_damage
lw $t1, -504($s1)
beq $t0, $t1, check_damage_damage
lw $t1, 8($s1)
beq $t0, $t1, check_damage_damage
lw $t1, 520($s1)
beq $t0, $t1, check_damage_damage
lw $t1, 1020($s1)
beq $t0, $t1, check_damage_damage
lw $t1, 1024($s1)
beq $t0, $t1, check_damage_damage
lw $t1, 1028($s1)
beq $t0, $t1, check_damage_damage
# Get red
li $t0, 0x00fe0000
# Check every tile touching the player
lw $t1, -1028($s1)
beq $t0, $t1, check_damage_damage
lw $t1, -1024($s1)
beq $t0, $t1, check_damage_damage
lw $t1, -1020($s1)
beq $t0, $t1, check_damage_damage
lw $t1, -520($s1)
beq $t0, $t1, check_damage_damage
lw $t1, -8($s1)
beq $t0, $t1, check_damage_damage
lw $t1, 504($s1)
beq $t0, $t1, check_damage_damage
lw $t1, -504($s1)
beq $t0, $t1, check_damage_damage
lw $t1, 8($s1)
beq $t0, $t1, check_damage_damage
lw $t1, 520($s1)
beq $t0, $t1, check_damage_damage
lw $t1, 1020($s1)
beq $t0, $t1, check_damage_damage
lw $t1, 1024($s1)
beq $t0, $t1, check_damage_damage
lw $t1, 1028($s1)
beq $t0, $t1, check_damage_damage
# Return
addi $sp, $sp, 4
lw $ra, 0($sp)
jr $ra
check_damage_damage: # Take damage potentially
jal lose_life
# Return
addi $sp, $sp, 4
lw $ra, 0($sp)
jr $ra
######################################################################
momentum_counter: # Manages momentum
# Save return
sw $ra, 0($sp)
addi $sp, $sp, -4
# Get momentum
lw $t0, 24($s0)
# Check if center pixel below the player is not black
lw $t2, 1024($s1)
li $t1, 0x00000000
bne $t2, $t1, momentum_counter_reset
# Check if left pixel below the player is not black
lw $t2, 1020($s1)
bne $t2, $t1, momentum_counter_reset
# Check if right pixel below the player is not black
lw $t2, 1028($s1)
bne $t2, $t1, momentum_counter_reset
# If right momentum
bgt $t0, $zero, momentum_counter_right
# If left momentum
blt $t0, $zero, momentum_counter_left
momentum_counter_end: # End of function
# Return
addi $sp, $sp, 4
lw $ra, 0($sp)
jr $ra
momentum_counter_right: # Right momentum
# Save $t0
sw $t0, 0($sp)
addi $sp, $sp, -4
# Move right
jal move_right
# Load $t0
addi $sp, $sp, 4
lw $t0, 0($sp)
addi $t0, $t0, -1
sw $t0, 24($s0)
j momentum_counter_end
momentum_counter_left: # Left momentum
# Save $t0
sw $t0, 0($sp)
addi $sp, $sp, -4
# Move left
jal move_left
# Load $t0
addi $sp, $sp, 4
lw $t0, 0($sp)
addi $t0, $t0, 1
sw $t0, 24($s0)
j momentum_counter_end
momentum_counter_reset: # Reset momentum
add $t0, $zero, $zero
sw $t0, 24($s0)
j momentum_counter_end
######################################################################
set_plats: # Sets up all the initial platforms
# Save return
sw $ra, 0($sp)
addi $sp, $sp, -4
# Setting win platform
li $t0, 9
sw $t0, 0($sp)
li $t0, 128
sw $t0, -4($sp)
li $t0, 0
sw $t0, -8($sp)
sw $zero, -12($sp)
li $t0, 0x0000ff00
sw $t0, -16($sp)
addi $sp, $sp, -20
jal draw_plat_row
# Setting first row/plat/space/offset/color
li $t0, 111
sw $t0, 0($sp)
li $t0, 112
sw $t0, -4($sp)
li $t0, 16
sw $t0, -8($sp)
sw $zero, -12($sp)
li $t0, 0x00ffffff
sw $t0, -16($sp)
addi $sp, $sp, -20
jal draw_plat_row
# Setting second row/plat/space/offset/color
li $t0, 95
sw $t0, 0($sp)
li $t0, 96
sw $t0, -4($sp)
li $t0, 32
sw $t0, -8($sp)
li $t0, 0
sw $t0, -12($sp)
li $t0, 0x00ffffff
sw $t0, -16($sp)
addi $sp, $sp, -20
jal draw_plat_row
# Setting third row/plat/space/offset/color
li $t0, 79
sw $t0, 0($sp)
li $t0, 64
sw $t0, -4($sp)
li $t0, 64
sw $t0, -8($sp)
li $t0, 0
sw $t0, -12($sp)
li $t0, 0x00ffffff
sw $t0, -16($sp)
addi $sp, $sp, -20
jal draw_plat_row
# Setting third row/plat/space/offset/color
li $t0, 79
sw $t0, 0($sp)
li $t0, 32
sw $t0, -4($sp)
li $t0, 16
sw $t0, -8($sp)
li $t0, 80
sw $t0, -12($sp)
li $t0, 0x00ff0000
sw $t0, -16($sp)
addi $sp, $sp, -20
jal draw_plat_row
# Setting fourth row/plat/space/offset/color
li $t0, 63
sw $t0, 0($sp)
li $t0, 32
sw $t0, -4($sp)
li $t0, 128
sw $t0, -8($sp)
li $t0, 0
sw $t0, -12($sp)
li $t0, 0x00ffffff
sw $t0, -16($sp)
addi $sp, $sp, -20
jal draw_plat_row
# Setting fourth row/plat/space/offset/color
li $t0, 63
sw $t0, 0($sp)
li $t0, 26
sw $t0, -4($sp)
li $t0, 128
sw $t0, -8($sp)
li $t0, 44
sw $t0, -12($sp)
li $t0, 0x00ff0000
sw $t0, -16($sp)
addi $sp, $sp, -20
jal draw_plat_row
# Setting fourth row/plat/space/offset/color
li $t0, 63
sw $t0, 0($sp)
li $t0, 26
sw $t0, -4($sp)
li $t0, 128
sw $t0, -8($sp)
li $t0, 90
sw $t0, -12($sp)
li $t0, 0x00ff0000
sw $t0, -16($sp)
addi $sp, $sp, -20
jal draw_plat_row
# Setting fourth row/plat/space/offset/color
li $t0, 63
sw $t0, 0($sp)
li $t0, 4
sw $t0, -4($sp)
li $t0, 128
sw $t0, -8($sp)
li $t0, 78
sw $t0, -12($sp)
li $t0, 0x00ffffff
sw $t0, -16($sp)
addi $sp, $sp, -20
jal draw_plat_row
# Setting fifth row/plat/space/offset/color
li $t0, 47
sw $t0, 0($sp)
li $t0, 16
sw $t0, -4($sp)
li $t0, 48
sw $t0, -8($sp)
li $t0, 0
sw $t0, -12($sp)
li $t0, 0x00ffffff
sw $t0, -16($sp)
addi $sp, $sp, -20
jal draw_plat_row
# Setting fifth row/plat/space/offset/color
li $t0, 31
sw $t0, 0($sp)
li $t0, 100
sw $t0, -4($sp)
li $t0, 128
sw $t0, -8($sp)
li $t0, 0
sw $t0, -12($sp)
li $t0, 0x00ffffff
sw $t0, -16($sp)
addi $sp, $sp, -20
jal draw_plat_row
# Setting fifth row/plat/space/offset/color
li $t0, 31
sw $t0, 0($sp)
li $t0, 50
sw $t0, -4($sp)
li $t0, 128
sw $t0, -8($sp)
li $t0, 0
sw $t0, -12($sp)
li $t0, 0x00ff0000
sw $t0, -16($sp)
addi $sp, $sp, -20
jal draw_plat_row
# Return
addi $sp, $sp, 4
lw $ra, 0($sp)
jr $ra
######################################################################
move_plat: # Manage the moving platforms
# Save return
sw $ra, 0($sp)
addi $sp, $sp, -4
# Move platforms every 4th frame
li $t0, 4
div $s6, $t0
mfhi $t0
bne $t0, $zero, move_plat_2
# Loading row to move
li $t0, 111
sw $t0, 0($sp)
addi $sp, $sp, -4
jal move_left_plat
move_plat_2: # Next plat
# Move platforms every 6th frame
li $t0, 6
div $s6, $t0
mfhi $t0
bne $t0, $zero, move_plat_3
# Loading row to move
li $t0, 95
sw $t0, 0($sp)
addi $sp, $sp, -4
jal move_right_plat
move_plat_3: # Next plat
# Every 5th frame
li $t0, 5
div $s6, $t0
mfhi $t0
bne $t0, $zero, move_plat_4
# Loading row to move
li $t0, 79
sw $t0, 0($sp)
addi $sp, $sp, -4
jal move_left_plat
move_plat_4: # Next plat
# Every 3th frame
li $t0, 3
div $s6, $t0
mfhi $t0
bne $t0, $zero, move_plat_5
# Loading row to move
li $t0, 63
sw $t0, 0($sp)
addi $sp, $sp, -4
jal move_right_plat
move_plat_5: # Next plat
# Every 7th frame
li $t0, 7
div $s6, $t0
mfhi $t0
bne $t0, $zero, move_plat_6
# Loading row to move
li $t0, 47
sw $t0, 0($sp)
addi $sp, $sp, -4
jal move_left_plat
move_plat_6: # Next plat
# Every 2th frame
li $t0, 2
div $s6, $t0
mfhi $t0
bne $t0, $zero, move_plat_7
# Loading row to move
li $t0, 31
sw $t0, 0($sp)
addi $sp, $sp, -4
jal move_right_plat
move_plat_7: # Next plat
# Return
addi $sp, $sp, 4
lw $ra, 0($sp)
jr $ra
######################################################################
invuln_counter: # Manage the invuln counter
# Decrement counter if not 0
lw $t0, 20($s0)
beq $t0, $zero, invuln_counter_end
# Decrement and save
addi $t0, $t0, -1
sw $t0, 20($s0)
invuln_counter_end: # End of functions
# Return
jr $ra
######################################################################
run_counter: # Manage the run cycle counter
# Increment counter or reset if at max
addi $s6, $s6, 1
li $t0, 240
bne $s6, $t0, run_counter_end
# Set to 0
li $s6, 0
run_counter_end: # End os counter function
# Return
jr $ra
######################################################################
lose_life: # Lose a life
# Save return
sw $ra, 0($sp)
addi $sp, $sp, -4
# Do nothing if invuln
lw $t0, 20($s0)
bne $t0, $zero, lose_life_end
# Load the number of lives
lw $t0, 16($s0)
# Lose one
addi $t0, $t0, -1
sw $t0, 16($s0)