-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpowerups.asm
147 lines (118 loc) · 2.91 KB
/
powerups.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
# MAV120
# Mathew Varughese
.data
last_powerup_frame: .word 0
POWER_UP_FRAME_TIMING: .word 60
CHANCES_POWERUP_SHOWS: .word 10 # 1 in a __ chance
powerup_x: .word 0
powerup_y: .word 52
powerup_player_has_equipped: .byte 0
current_powerup_on_screen: .byte 0
# 0: Nothing
# 1: More Ammo
# 2: Extra Life
# 3: Temp Invincible
# 4: Freeze Ships
.eqv NUM_OF_POWERUPS 5 # this is actual one more than the actual number, to simplify some code
# Array that holds the addresses of the sprites. Makes code less complex.
powerup_sprite_array: .word 0:NUM_OF_POWERUPS
# Array that has pointers to functions.
powerup_fn_array: .word 0:NUM_OF_POWERUPS
.text
set_up_powerup_sprite_array:
enter
la t0 powerup_extra_bullets_sprite
la t1 powerup_extra_life_sprite
la t2 powerup_invincibility_sprite
la t3 powerup_freeze_sprite
li t9 4
sw t0 powerup_sprite_array(t9)
li t9 8
sw t1 powerup_sprite_array(t9)
li t9 12
sw t2 powerup_sprite_array(t9)
li t9 16
sw t3 powerup_sprite_array(t9)
leave
set_up_powerup_fn_array:
enter
la t0 add_bullets_powerup
la t1 add_extra_life_powerup
la t2 add_invincibility_powerup
la t3 add_freeze_powerup
li t9 4
sw t0 powerup_fn_array(t9)
li t9 8
sw t1 powerup_fn_array(t9)
li t9 12
sw t2 powerup_fn_array(t9)
li t9 16
sw t3 powerup_fn_array(t9)
leave
check_to_add_powerup:
enter s0
# Every POWER_UP_FRAME_TIMING frames, a power up has a 1 in
# CHANCES_POWERUP_SHOWS chance to show up.
lbu t1 current_powerup_on_screen
bne t1 0 _finish_check_to_add_power_up
# the following determines difference between last powerup
# or since start of game
lw t0 last_powerup_frame
lw t1 frame_counter
beq t0 0 _load_game_start_frame_instead
b _finish_loading_frame_counter
_load_game_start_frame_instead:
lw t0 game_start_frame
_finish_loading_frame_counter:
sub t0 t1 t0
# t0 = frames since last power up
lw t9 POWER_UP_FRAME_TIMING
blt t0 t9 _finish_check_to_add_power_up
sw t1 last_powerup_frame
# a0 = random [0,CHANCES_POWERUP_SHOWS-1]
li v0 sys_randRange
lw a1 CHANCES_POWERUP_SHOWS
syscall
bne a0 0 _finish_check_to_add_power_up
jal add_powerup
lw t1 frame_counter
sw t1 last_powerup_frame
_finish_check_to_add_power_up:
leave s0
add_powerup:
enter
li v0 sys_randRange
li a1 NUM_OF_POWERUPS
syscall
sb a0 current_powerup_on_screen
# a0 = 1 # uncomment this line to force a certain powerup
lw t0 player_y
sw t0 powerup_y
lw t0 player_x
bge t0 32 _place_power_up_on_left
_place_power_up_on_right:
li t0 51
b _set_powerup_position
_place_power_up_on_left:
li t0 8
_set_powerup_position:
sw t0 powerup_x
leave
check_if_touching_powerup:
enter
lw a0 powerup_x
add a0 a0 3
lw a1 powerup_y
add a1 a1 3
lw a2 player_x
lw a3 player_y
li v0 0
jal check_if_inside_hitbox
beq v0 0 _not_touching_powerup
lbu t0 current_powerup_on_screen
sb t0 powerup_player_has_equipped
sb zero current_powerup_on_screen
lw t0 frame_counter
sw t0 last_powerup_frame
_not_touching_powerup:
leave