-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcollision.asm
125 lines (104 loc) · 2.38 KB
/
collision.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
# MAV120
# Mathew Varughese
.data
.text
check_if_bullet_hit_enemy:
enter s0, s1, s2, s3
# a0: bullet x
# a1: bullet y
# a3: bullet pos
# kills enemy
li s0, 0
li s1, 0
li s2, 0
move s3, a3
_checkbullet_hit_enemies_row_main_loop:
bge s0 ENEMY_PER_ROW _finish_checkbullet_hit_enemies_row
_checkbullet_hit_enemies_row_loop:
li, s1, 0
_checkbullet_hit_enemies_col_main_loop:
bge s1 ENEMY_PER_COL _finish_checkbullet_hit_enemies_col_loop
_checkbullet_hit_enemies_col_loop:
lb t0 enemy_active(s2)
bne t0 1 _do_not_kill_enemy_and_bullet
lw a2 enemy_x
lw a3 enemy_y
mul t0 s0, ENEMY_COL_SPACING
mul t1 s1 ENEMY_ROW_SPACING
add a2 a2 t0
add a3 a3 t1
li v0 0
jal check_if_inside_hitbox
beq v0 0 _do_not_kill_enemy_and_bullet
# bullet hit enemy
li t9 2 # 2 is explosion sprite
sb t9 enemy_active(s2)
sb zero bullet_active(s3)
lw t0 enemy_kill_count
inc t0
sw t0 enemy_kill_count
_do_not_kill_enemy_and_bullet:
inc s1
inc s2
b _checkbullet_hit_enemies_col_main_loop
_finish_checkbullet_hit_enemies_col_loop:
inc s0
b _checkbullet_hit_enemies_row_main_loop
_finish_checkbullet_hit_enemies_row:
leave s0, s1, s2, s3
check_if_enemy_bullet_hit_player:
enter s0
# a0 bullet_x
# a1 bullet_y
# a2 bullet_pos
move s0 a2
lw a2 player_x
lw a3 player_y
jal check_if_inside_hitbox
beq v0 0 finish_check_if_enemy_bullet_hit_player
sb zero enemy_bullet_active(s0)
jal player_has_been_hit
finish_check_if_enemy_bullet_hit_player:
leave s0
check_if_inside_hitbox:
enter
# (a0, a1, a2, a3)
# a0 - x of bullet
# a1 - y of bullet
# a2 - x of hitbox (assuming 5 x 5)
# a3 - y of hitbox
# return 1 if true, 0 if not
# (a2 <= a0 <= a2 + 5) &&
# (a3 <= a1 <= a3 + 5)
add t0 a2 5
add t1 a3 5
blt a0 a2 _not_in_hitbox
blt t0 a0 _not_in_hitbox
blt a1 a3 _not_in_hitbox
blt t1 a1 _not_in_hitbox
li v0 1
b _finish_check_if_inside_hitbox
_not_in_hitbox:
li v0 0
_finish_check_if_inside_hitbox:
leave
player_has_been_hit:
enter
# check if is invincble
lb t0 player_invincible
beq t0 1 _finish_player_has_been_hit
# not invincible:
# Player loses life
lw t0 player_lives
dec t0
sw t0 player_lives
## If no lives left, game over
bge t0 0 _turn_player_invincible
jal game_over
_turn_player_invincible:
lw t0 frame_counter
sw t0 player_invincible_last_frame
li t0 1
sb t0 player_invincible
_finish_player_has_been_hit:
leave