-
Notifications
You must be signed in to change notification settings - Fork 0
/
moveRoutines.asm
377 lines (362 loc) · 6.16 KB
/
moveRoutines.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
mapDown:
ld hl,updateMapDown
push hl ;saltar a updateMapDown después de terminar la rutina
ld hl,flechaPulsada ;para avanzar la animacion del jugador
ld (hl),1
ld hl,playerDir
ld (hl),2
ld a,(playerXOff)
add a,PLYR_X_OVRHG ;número de pixeles del sprite del personaje que no forman parte del personaje
ld c,a
ld a,(playerYOff)
ld hl,pulsado ;=número de pixeles a saltar
add a,(hl)
add a,15 ;revisar azulejo debajo del personaje
exx
ld e,a
exx
call checkTile
jr z,tilePassDown
ld de,mapHeight
sbc hl,de
jr nz,downMasked
ld a,(playerXOff)
add a,2
ld c,a
xor a
call checkTile
ld hl,(saveHL)
ld a,(hl)
bit 6,a
jp nz,goToInteraction
downMasked:
;masked tiles
ld hl,(saveHL) ;first brush
ld a,(hl)
ld c,$0F
rra ;animation
rra ;if passable
jr nc,notVarTop ;if passable, skip
ld b,0
rra
jr c,varHeight
ld hl,playerYOff
ld a,(hl)
ld (hl),0
or a
ret z ;si l'on était déjà aligné, il ne faut pas augmenter playerY
ld hl,playerY
inc (hl)
ret ;if no var height, leave
varHeight:
call skipBrushInfo
jr nc,notVarTop
ld b,(hl)
ld c,b
notVarTop:
ld hl,(saveHL+2)
ld a,(hl)
rra
rra
jr nc,endTopCheck ;if not passable, skip
ld b,0
rra
ret nc ;if no var height, leave
call skipBrushInfo
jr nc,endTopCheck
ld a,c
cp (hl)
jr c,$+3
ld b,(hl)
endTopCheck:
ld hl,playerYOff
ld (hl),b
ret
tilePassDown:
ld hl,playerY
ld a,(mapHeight)
dec a
ld b,a ;for updatemapdown
cp (hl)
ret z
ex de,hl
ld hl,playerYOff
ld a,(pulsado)
add a,(hl)
cp 16
jr nc,newTileEnd
ld (hl),a
ret
mapRight:
ld hl,updateMapRight
push hl
ld hl,flechaPulsada
ld (hl),1
ld hl,playerDir
ld (hl),FACE_RIGHT
ld a,(playerXOff)
ld hl,pulsado
add a,(hl) ;current x position on map
add a,15-PLYR_X_OVRHG
ld c,a
ld a,(playerYOff)
add a,PLYR_Y_OVRHG
exx
ld e,a
exx
call checkTile
jr z,tilePassRight
ld hl,playerXOff
ld a,(pulsado)
add a,(hl)
cp 16
ld (hl),PLYR_X_OVRHG
ret c
ld hl,playerX
inc (hl)
ret
tilePassRight:
ld hl,playerX
ld a,(mapWidth)
dec a
ld b,a
cp (hl)
ret z
ex de,hl
ld hl,playerXOff
ld a,(pulsado)
add a,(hl)
ld (hl),a
cp 16
ret c
;hl = o playerXOff o playerYOff
;de = o playerX o playerY
newTileEnd:
sub 16
ld (hl),a ;hl = playerXOff or playerYOff
;de = playerX or playerY, depending on calling routine
ex de,hl
inc (hl) ;playerX += 1
ld a,(hl)
cp b ;b=mapWidth
ret c ;if mapWidth>playerX, quit
ld (hl),a
xor a
ld (de),a ;de = playerXOff/YOff
ret
mapUp:
ld hl,updateMapUp
push hl
ld hl,flechaPulsada
ld (hl),1
ld hl,playerDir
ld (hl),3
ld a,(playerXOff)
add a,PLYR_X_OVRHG
ld c,a
ld a,(playerYOff)
ld hl,pulsado
sub (hl)
add a,PLYR_Y_OVRHG ;para saber donde comienzan las colisiones del personaje (para dejar que
exx ; el personaje se acerque un poco más a las paredes/etc.)
ld e,a
exx
call checkTile
jr z,tilePassUp
;if we can't pass...
ld hl,playerYOff
ld a,(hl)
add a,PLYR_Y_OVRHG
ld (hl),16-PLYR_Y_OVRHG
cp 8
ret nc
ld (hl),0
tilePassUp:
ld hl,playerYOff
ld a,(pulsado)
neg
add a,(hl)
ld (hl),a
cp 16
ret c
add a,16
ld (hl),a
ld de,playerY
ld a,(de)
or a
jr nz,notBeginningTile
ld (hl),a ;set playerXOff to 0
ret
notBeginningTile:
dec a
ld (de),a
ret
;set flechapulsada, which let's the animation routine know that the player is moving (or trying to)
;update playerdir to LEFT
;subtract pulsado (which says how many pixels to move) from the player's xoffset then add plyr_x_ovrhg (how much of the player is empty space)
; for example: our x position is 13. the leftmost 2 bits of the sprite are empty, the sprite doesn't begin until pixel 15. say we are running,
; pulsado = 2. we start with x=13 then subtract (because we need to subtract to go left) 2 pixels. We're at x=11.
; HOWEVER, at x=11 there are two blank columns of pixels in the sprite, therefore we add 2, now x=13.
; so we will check whatever's at x=13 to see if we can pass
mapLeft:
ld hl,updateMapLeft
push hl ;return to updateMapLeft
ld hl,flechaPulsada
ld (hl),1
xor a
ld (playerDir),a
ld a,(playerXOff)
ld hl,pulsado
sub (hl) ;current y position on map
add a,PLYR_X_OVRHG
ld c,a
ld a,(playerYOff)
add a,PLYR_Y_OVRHG
exx
ld e,a
exx
call checkTile
jr z,tilePassLeft
;if we can't pass...
ld hl,playerXOff
ld a,c
ld (hl),16-PLYR_X_OVRHG
cp $F0
ret c
ld hl,playerX
dec (hl)
ret
tilePassLeft:
ld hl,playerXOff
ld a,(pulsado)
neg
add a,(hl)
ld (hl),a
cp 16
ret c
add a,16
ld (hl),a
ld de,playerX
ld a,(de)
or a
jr nz,notBeginningTile
ld (hl),a ;set playerXOff to 0
ret
updateMapX:
ld hl,playerX
ld a,(hl)
ld hl,xCoord
sub (hl) ;playerX - xCoord, shouldn't be any carry
rlca
rlca
rlca
rlca ;x16
ld hl,playerXOff
add a,(hl)
ld hl,xOff
sub (hl) ;player's position in pixels on screen
ret
updateMapRight:
ld hl,xCoord
ld a,(mapWidth)
sub 6 ;hay 6 columnas ya en la pantalla
cp (hl)
jr nz,notRight
xor a ;X align map because we've reached the edge
ld (xOff),a ;hl = yOff
jp updateRotation
notRight:
ex de,hl
call updateMapX
cp SCROLL_RIGHT
ret c
add a,(hl)
sub SCROLL_RIGHT
ld (hl),a
cp 16
jp c,updateRotation
sub 16
ld (hl),a
ex de,hl
inc (hl)
jp updateRotation
updateMapLeft:
call updateMapX
cp SCROLL_LEFT
ret nc
add a,(hl)
sub SCROLL_LEFT
ld (hl),a
cp 16
jp c,updateRotation
add a,16
ld (hl),a
ld de,xCoord
ld a,(de)
or a
jr nz,notLeft
ld (hl),a
jp updateRotation
notLeft:
dec a
ld (de),a
jp updateRotation
updateMapDown:
ld hl,yCoord
ld a,(mapHeight)
sub 4 ;hay 4 filas ya en la pantalla
cp (hl)
jr nz,notBottom
xor a
ld (yOff),a ;hl = yOff
ret
notBottom:
ex de,hl
call updateMapY
cp SCROLL_DOWN
ret c
add a,(hl)
sub SCROLL_DOWN
ld (hl),a
cp 16
ret c
sub 16
ld (hl),a
ex de,hl
inc (hl)
ret
updateMapUp:
call updateMapY
cp SCROLL_UP
ret nc
add a,(hl)
sub SCROLL_UP
ld (hl),a
cp 16
ret c
add a,16
ld (hl),a
ld de,yCoord
ld a,(de)
or a
jr nz,notTop
ld (hl),a
ret
notTop:
dec a
ld (de),a
ret
updateMapY:
ld hl,playerY
ld a,(hl)
ld hl,yCoord
sub (hl)
rlca
rlca
rlca
rlca ;x16
ld hl,playerYOff
add a,(hl)
ld hl,yOff
sub (hl)
ret