-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtiles.asm
536 lines (458 loc) · 9.31 KB
/
tiles.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
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
; this file contains all collision sub routines
; for each possible tile
; all tile routines return
; a = 0 -> no collision
; a = 1 -> collision
; this sub routine simply
; returns with a = 0 to flag no collision
; returns:
; a = 0 always
no_collision:
lda #$00
rts
; this sub routine simply
; returns with a = 1 to flag collision
; returns:
; a = 1 always
collision:
lda #$01
rts
; space tile collision
; and then spawn back at previous good location
; reduces hp by 1
space_collision:
lda #$01
jsr take_damage
bne @no_game_over
jsr game_over
rts
@no_game_over:
; init animation
; set up delay timer to play falling animation
lda #<@fall_update
sta delay_update
lda #>@fall_update
sta delay_update+1
lda #<@fall_done
sta delay_done
lda #>@fall_done
sta delay_done+1
lda #$00
sta delay_timer+1
lda #$1F ; 32 frames
sta delay_timer
; disable inputs until fall is done
lda nmi_flags
ora #%00100000
sta nmi_flags
lda #$01
rts
@fall_done:
; enable inputs
lda nmi_flags
and #%11011111
sta nmi_flags
; player normal sprite
lda #$32
sta sprite_data+1
rts
@fall_update:
; player small sprite
lda #$C2
sta sprite_data+1
ldx #$08 ; 8 pixel offset
lda delay_timer
cmp #$17 ; if smaller than 8
bcc @no_smooth
; smooth offset
lda #$1F
sec
sbc delay_timer
tax
@no_smooth:
; check last move and place player above hole
lda last_move
cmp #UP
bne @not_up
stx smooth_down
@not_up:
cmp #DOWN
bne @not_down
stx smooth_up
@not_down:
cmp #LEFT
bne @not_left
stx smooth_right
@not_left:
cmp #RIGHT
bne @not_right
stx smooth_left
@not_right:
rts
; exit tile
; sets victory condition
; returns:
; a = 0 always
exit_collision:
jsr abort_delay ; abort possible weapon
lda #$01
sta tiles_to_clear
lda #$00
sta tiles_to_clear+1
rts
; this routine only returns
; 0 when the direction value is nonzero
; returns:
; a = 0 when direction is nonzero
.macro one_way_n direction
lda direction
beq @.mi.collision
lda #$00
rts
@.mi.collision:
lda #$01
rts
.endm
one_way_left:
one_way_n smooth_left
one_way_right:
one_way_n smooth_right
one_way_up:
one_way_n smooth_up
one_way_down:
one_way_n smooth_down
; this sub routine sets up common
; animation pointers to be used before a jump
; inputs:
; none
; side effects:
; changed delay_update, timer, and done
; disables inputs
init_jump_animation:
lda smooth_down
ora smooth_left
ora smooth_right
ora smooth_up
sta delay_timer
lda #$00
sta delay_timer+1 ; second byte
lda #<jump_update
sta delay_update
lda #>jump_update
sta delay_update+1
; lda #$38
lda #$40
sta sprite_data+1
lda #$42
sta sprite_data_1+1
lda #$41
sta sprite_data_2+1
lda #$43
sta sprite_data_3+1
; set up attributes
lda #$00
sta sprite_data+21
; lda #%10000000
sta sprite_data_1+2
; lda #%01000000
sta sprite_data_2+2
; lda #%11000000
sta sprite_data_3+2
jsr init_jump_noise
rts
; this sub routine inits the pre-jump state
; of the jump animation
; inputs:
; none
; side effects:
; changes delay_update, timer and done
; changes player tile index
; changes sprite_1-4
init_pre_jump:
lda smooth_down
ora smooth_left
ora smooth_right
ora smooth_up
sta delay_timer
lda #$00
sta delay_timer+1 ; second byte
lda #<empty_sub
sta delay_update
lda #>empty_sub
sta delay_update+1
; disable inputs
lda nmi_flags
ora #%00100000
sta nmi_flags
; store initial x and y location
; in temporary collision data
lda player_x
sta collision_data
lda player_y
sta collision_data+1
rts
; this sub routine updates the jump routines
; inputs:
; none
; side effects:
; moves sprites_1-3 relative to player
; x and a registers are used
; uses temp to store original location
jump_update:
lda sprite_data+3
sta temp
lda sprite_data
sta temp+1
; first move x positions
lda temp
clc
adc #$04
sta sprite_data_2+3
sta sprite_data_3+3
lda temp
sec
sbc #$04
sta sprite_data+3
sta sprite_data_1+3
; y position
lda temp+1
clc
adc #$04
sta sprite_data_1
sta sprite_data_3
lda temp+1
sec
sbc #$04
sta sprite_data
sta sprite_data_2
rts
; this sub routine restore
; the original player tile at the end of a jump
; inputs:
; none
; side effects:
; changes player tile index
; changes sprite_1-3
; enables inputs
finish_jump:
lda #$00
sta sprite_data+2
sta sprite_data_1+2
sta sprite_data_2+2
sta sprite_data_3+2
sta sprite_data_1
sta sprite_data_1+3
sta sprite_data_2
sta sprite_data_2+3
sta sprite_data_3
sta sprite_data_3+3
lda #$32
sta sprite_data+1
; enable inputs
lda nmi_flags
and #%11011111
sta nmi_flags
; only trigger collision if player did not land on the same jump tile where
; the jump was initiated
; lda collision_data
; cmp player_x
; bne @collision
; lda collision_data+1
; cmp player_y
; beq @done
; only allow collision if the next tile is not a jump tile again
; check this with some fancy boolean logic
; eor tile with 01011100. resulting values should be between 0-3
; if it is a jump tile
lda player_x
sta get_tile_x
lda player_y
sta get_tile_y
jsr get_tile
eor #%01011100
cmp #$04
bcc @done
@collision:
; trigger collision for the
; current tile
jsr collision_check
@done:
rts
; this routine handles jumping, jumps over 1 tile
; does not go out of bounds
; returns
; a = 0 when jump tile is hit
; side effects:
; removes smooth scrolling
; sets registers
; changes player location
jump_left:
; set up animation pointers
jsr init_pre_jump
lda #<@animation
sta delay_done
lda #>@animation
sta delay_done+1
lda #$00 ; allow animation
rts
@animation:
; set up correct smooth value
lda #$10
sta smooth_left
; set up animation pointers
jsr init_jump_animation
lda #<finish_jump
sta delay_done
lda #>finish_jump
sta delay_done+1
lda player_x
sec
sbc #$02
bcs @no_carry
lda #$00 ; if carry is set we go to 0
@no_carry:
sta player_x
; do not flag the jump tile as passed
lda player_x
sta player_x_bac
lda player_y
sta player_y_bac
lda #$00
@left:
rts
jump_right:
; set up animation pointers
jsr init_pre_jump
lda #<@animation
sta delay_done
lda #>@animation
sta delay_done+1
lda #$00 ; allow animation
rts
@animation:
; set up correct smooth value
lda #$10
sta smooth_right
; set up animation pointers
jsr init_jump_animation
lda #<finish_jump
sta delay_done
lda #>finish_jump
sta delay_done+1
lda player_x
clc
adc #$02
bcc @no_carry
lda #31 ; if carry is set we go to 29
@no_carry:
sta player_x
; do not flag the jump tile as passed
lda player_x
sta player_x_bac
lda player_y
sta player_y_bac
lda #$00
rts
jump_up:
; set up animation pointers
jsr init_pre_jump
lda #<@animation
sta delay_done
lda #>@animation
sta delay_done+1
lda #$00 ; allow animation
rts
@animation:
; set up correct smooth value
lda #$10
sta smooth_up
; set up animation pointers
jsr init_jump_animation
lda #<finish_jump
sta delay_done
lda #>finish_jump
sta delay_done+1
lda player_y
sec
sbc #$02
bcs @no_carry
lda #$00 ; if carry is set we go to 0
@no_carry:
sta player_y
; do not flag the jump tile as passed
lda player_x
sta player_x_bac
lda player_y
sta player_y_bac
lda #$00
rts
jump_down:
; set up animation pointers
jsr init_pre_jump
lda #<@animation
sta delay_done
lda #>@animation
sta delay_done+1
lda #$00 ; allow animation
rts
@animation:
; set up correct smooth value
lda #$10
sta smooth_down
; set up animation pointers
jsr init_jump_animation
lda #<finish_jump
sta delay_done
lda #>finish_jump
sta delay_done+1
lda player_y
clc
adc #$02
bcc @no_carry
lda #29 ; if carry is set we go to 29
@no_carry:
sta player_y
; do not flag the jump tile as passed
lda player_x
sta player_x_bac
lda player_y
sta player_y_bac
lda #$00 ; do not skip update this frame
rts
; inverts the barrier
; flag
; returns:
; a = 00 always
barrier_switch:
lda map_flags
eor #$80
sta map_flags
lda #$00
rts
; this sub routine does collision handling for AI tiles
; with barries
; inputs:
; none
; returns:
; a = 1 if AI is in blocking state
; a = 0 if AI is in non-blocking state
barrier_tile:
lda map_flags ; check flag for tile
and #%10000000
beq @flag_set:
lda #$00
rts
@flag_set:
lda #$01
rts
; this us the same as the normal barrier tile
; but the output is inverted
barrier_tile_invert:
lda map_flags ; check flag for tile
and #%10000000
bne @flag_set:
lda #$00
rts
@flag_set:
lda #$01
rts