-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathplayermove.asm
265 lines (208 loc) · 4.1 KB
/
playermove.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
move_player
ld a, (keys_pressed)
ld c, a
ld a, (screen_transition_in_progress)
and a
jr z, not_transitioning
dec a
ld (screen_transition_in_progress), a
ld a, (transition_keypress)
ld (keys_pressed), a
ld c, a
not_transitioning
ld a, (player_x)
ld (updated_x), a
bit player_up_bit, c
call nz, move_up
bit player_down_bit, c
call nz, move_down
ld a, (player_y)
ld (updated_y), a
bit player_left_bit, c
call nz, move_left
bit player_right_bit, c
call nz, move_right
bit player_fire1_bit, c
call nz, fire_weapon
; Finally store what we're stood on top of at current position
call check_collision_squares
ld a, (screen_transition_in_progress)
and a
jr nz, inc_frame
ld a, (keys_pressed)
and 0x0f
jr nz, inc_frame ; only animate if something pressed
ld a, default_frame
ld (player_frame), a
ret
inc_frame
ld a, (player_frame)
inc a
and 0x0f
ld (player_frame), a
cp player_step_frame1
jr z, step_sound
cp player_step_frame2
ret nz
step_sound
ld e, sound_steps
jp play_lowpriority_sfx
move_up
ld a, player_is_going_up
ld (player_orientation), a
ld a, (player_y)
add -player_vert_speed
ld (updated_y), a
call check_collision
and a
ret nz
ld a, (updated_y)
ld (player_y), a
ret
move_down
ld a, player_is_going_down
ld (player_orientation), a
ld a, (player_y)
add player_vert_speed
ld (updated_y), a
call check_collision
and a
ret nz
ld a, (updated_y)
ld (player_y), a
ret
move_left
ld a, player_is_going_left
ld (player_orientation), a
ld a, (player_x)
add -player_horiz_speed
ld (updated_x), a
call check_collision
and a
ret nz
ld a, (updated_x)
ld (player_x), a
ret
move_right
ld a, player_is_going_right
ld (player_orientation), a
ld a, (player_x)
add player_horiz_speed
ld (updated_x), a
call check_collision
and a
ret nz
ld a, (updated_x)
ld (player_x), a
ret
check_collision
ld a, (updated_x)
ld b, a
ld a, (updated_y)
call check_corner_collision
ld a, b
and a
ret nz
ld a, (updated_x)
add 3
ld b, a
ld a, (updated_y)
call check_corner_collision
ld a, b
and a
ret nz
ld a, (updated_x)
add player_width + 2
ld b, a
ld a, (updated_y)
call check_corner_collision
ld a, b
and a
ret nz
ld a, (updated_x)
ld b, a
ld a, (actual_player_height)
ld e, a
ld a, (updated_y)
add e
call check_corner_collision
ld a, b
and a
ret nz
ld a, (updated_x)
add 3
ld b, a
ld a, (actual_player_height)
ld e, a
ld a, (updated_y)
add e
call check_corner_collision
ld a, b
and a
ret nz
ld a, (updated_x)
add player_width + 2
ld b, a
ld a, (actual_player_height)
ld e, a
ld a, (updated_y)
add e
call check_corner_collision
ld a, b
ret
check_collision_squares
ld a, (player_x)
ld b, a
ld a, (player_y)
call check_corner_collision
ld (collision_info + 0), a
ld a, (player_x)
add player_width + 2
ld b, a
ld a, (player_y)
call check_corner_collision
ld (collision_info + 1), a
ld a, (player_x)
ld b, a
ld a, (actual_player_height)
ld e, a
ld a, (player_y)
add e
call check_corner_collision
ld (collision_info + 2), a
ld a, (player_x)
add player_width + 2
ld b, a
ld a, (actual_player_height)
ld e, a
ld a, (player_y)
add e
call check_corner_collision
ld (collision_info + 3), a
ret
check_corner_collision ; IN: a = y, b = x
srl a
srl a
srl a
ld l, a
ld h, 0
add hl, hl
ld de, collision_rows
add hl, de
ld a, (hl)
inc hl
ld h, (hl)
ld l, a
ld e, b
srl e
srl e
ld d, 0
add hl, de
ld b, 0
ld a, (hl)
cp 0xff
ret nz
ld b, 1
ret
collision_info
defs 4