-
Notifications
You must be signed in to change notification settings - Fork 0
/
dirt.asm
415 lines (360 loc) · 6.64 KB
/
dirt.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
.export DirtConstructor
.export DirtExecute
.export DirtDraw
.include "include.branch-macros.asm"
.include "include.mov-macros.asm"
.include "include.sprites.asm"
.include "include.tiles.asm"
.include "object_list.h.asm"
.include "sprite_space.h.asm"
.include "shared_object_values.asm"
.include "gunk_drop.h.asm"
.include "trash_gunk.h.asm"
.include "sound.h.asm"
.include "random.h.asm"
.include "move_trig.h.asm"
.include "hurt_player.h.asm"
.importzp camera_h, camera_screen
.importzp player_health_delta
.importzp draw_screen, draw_h, draw_v, draw_frame
.importzp player_iframe
.importzp player_just_landed
.importzp values
num_tiles = values + $00
tile_0 = values + $01
tile_1 = values + $02
tile_2 = values + $03
dirt_draw_attr = values + $04
dirt_draw_counter = values + $05
trash_orig_v = values + $07
trash_orig_h = values + $08
trash_orig_screen = values + $09
.import object_data_extend
dirt_kind = object_data_extend + $00
dirt_step = object_data_extend + $10
dirt_direction = dirt_step
dirt_h_low = object_data_extend + $20 ; only used by spit
dirt_v_low = object_data_extend + $30 ; only used by spit
dirt_shake = object_data_extend + $20 ; only used by trash
DIRT_KIND_SINK = 0
DIRT_KIND_SPLOTCH = 1
DIRT_KIND_PILE = 2
DIRT_KIND_PUDDLE = 3
DIRT_KIND_SPIT = 4
DIRT_KIND_TRASH = 5
DIRT_SPAWN_GUNK_DROP_LOW_BEGIN_PLUS_V = $88
DIRT_SPAWN_GUNK_DROP_HIGH_BEGIN_PLUS_V = $72
DIRT_SPAWN_GUNK_DROP_LIMIT = 75
GUNK_DROP_LIFE = 65
.segment "CODE"
.proc DirtConstructor
tya
sta dirt_kind,x
cmp #DIRT_KIND_SPLOTCH
beq WallSplotch
cmp #DIRT_KIND_SPIT
beq Spit
cmp #DIRT_KIND_TRASH
beq Trash
rts
WallSplotch:
lda object_v,x
cmp #$61
bge LowSplotch
HighSplotch:
lda #DIRT_SPAWN_GUNK_DROP_HIGH_BEGIN_PLUS_V
sec
sbc object_v,x
sta dirt_step,x
rts
LowSplotch:
lda #DIRT_SPAWN_GUNK_DROP_LOW_BEGIN_PLUS_V
sec
sbc object_v,x
sta dirt_step,x
rts
Spit:
jsr RandomGet
and #$07
clc
adc #36
sta dirt_direction,x
mov {object_life,x}, #$f0
rts
Trash:
mov {dirt_shake,x}, #0
rts
.endproc
.proc DirtExecute
.scope MaybeSpit
lda dirt_kind,x
cmp #DIRT_KIND_SPIT
jeq SpitHandler
.endscope
.scope MaybeDespawn
jsr ObjectOffscreenDespawn
bcc Okay
rts
Okay:
.endscope
.scope MaybeTrash
lda dirt_kind,x
cmp #DIRT_KIND_TRASH
beq TrashHandler
.endscope
.scope SpawnGunkDrop
lda dirt_kind,x
cmp #DIRT_KIND_SPLOTCH
bne Next
; Spot on the wall can spawn gunk.
inc dirt_step,x
lda dirt_step,x
cmp #DIRT_SPAWN_GUNK_DROP_LIMIT
blt Next
mov {dirt_step,x}, #0
;
lda object_v,x
clc
adc #9
sta draw_v
lda object_h,x
clc
adc #5
sta draw_h
lda object_screen,x
adc #0
sta draw_screen
; push x
txa
pha
; Allocate gunk.
jsr ObjectAllocate
bcc Return
jsr ObjectConstructor
mov {object_kind,x}, #OBJECT_KIND_GUNK_DROP
mov {object_v,x}, draw_v
mov {object_h,x}, draw_h
mov {object_screen,x}, draw_screen
mov {gunk_drop_form,x}, #0
mov {gunk_drop_inc,x}, _
mov {gunk_drop_speed_low,x}, _
mov {gunk_drop_speed,x}, _
mov {object_life,x}, #GUNK_DROP_LIFE
Return:
; pop X
pla
tax
Next:
.endscope
jmp Later
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
TrashHandler:
.scope ShakeTrashGunk
lda dirt_shake,x
beq Next
dec dirt_shake,x
Next:
.endscope
.scope CollisionWithTrash
mov trash_orig_h, {object_h,x}
mov trash_orig_screen, {object_screen,x}
; player must have just landed
bit player_just_landed
bpl NoHit
; check left half
lda object_h,x
sec
sbc #8
sta object_h,x
lda object_screen,x
sbc #0
sta object_screen,x
jsr ObjectCollisionWithPlayer
bcs Hit
; check right half
lda object_h,x
clc
adc #$10
sta object_h,x
lda object_screen,x
adc #$00
sta object_screen,x
jsr ObjectCollisionWithPlayer
bcc NoHit
Hit:
mov {object_h,x}, trash_orig_h
mov {object_screen,x}, trash_orig_screen
jsr TrashShakesAndSpitsGunk
jmp Next
NoHit:
mov {object_h,x}, trash_orig_h
mov {object_screen,x}, trash_orig_screen
Next:
.endscope
jmp Draw
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
SpitHandler:
.scope SpitHandler
jsr MovementTrig
jsr MovementTrig
lda object_v,x
cmp #$f0
blt Okay
DestroyIt:
jsr ObjectFree
clc
rts
Okay:
.endscope
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Later:
.scope CollisionWithPlayer
lda player_iframe
bne Next
jsr ObjectCollisionWithPlayer
bcc Next
DidCollide:
ldy #2
jsr HurtPlayer
Next:
.endscope
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Draw:
mov dirt_draw_attr, #$03
mov dirt_draw_counter, #$00
; Draw position.
mov draw_v, {object_v,x}
lda object_h,x
sec
sbc camera_h
sta draw_h
lda object_screen,x
sbc camera_screen
sta draw_screen
jne Return
lda dirt_kind,x
cmp #DIRT_KIND_SINK
beq DirtySink
cmp #DIRT_KIND_PILE
beq DirtyPile
cmp #DIRT_KIND_SPIT
beq DirtySpit
cmp #DIRT_KIND_TRASH
beq DirtyTrash
rts
DirtySink:
lda draw_v
clc
adc #4
sta draw_v
mov num_tiles, #2
mov tile_0, #DIRTY_SINK_TILE_0
mov tile_1, #DIRTY_SINK_TILE_1
jmp DrawIt
DirtyPile:
lda draw_h
sec
sbc #3
sta draw_h
mov num_tiles, #3
mov tile_0, #DIRTY_PILE_TILE_0
mov tile_1, #DIRTY_PILE_TILE_1
mov tile_2, #DIRTY_PILE_TILE_0
mov dirt_draw_counter, #$81
jmp DrawIt
DirtySpit:
lda draw_h
sec
sbc #3
sta draw_h
mov num_tiles, #2
lda object_life,x
eor #$ff
lsr a
lsr a
and #$03
tay
mov tile_0, {dirt_spit_animation_left,y}
mov tile_1, {dirt_spit_animation_right,y}
jmp DrawIt
DirtyTrash:
lda dirt_shake,x
beq TrashNoShake
lsr a
lsr a
tay
lda shake_offset_v,y
TrashNoShake:
clc
adc draw_v
clc
adc #16
sta draw_v
lda draw_h
clc
adc #5
sta draw_h
bcs SkipTrash
mov num_tiles, #2
mov tile_0, #DIRTY_TRASH_TILE_0
mov tile_1, #DIRTY_TRASH_TILE_1
jmp DrawIt
SkipTrash:
jmp Return
DrawIt:
ldy #0
DrawLoop:
jsr SpriteSpaceAllocate
lda draw_v
sta sprite_v,x
lda draw_h
sta sprite_h,x
lda tile_0,y
sta sprite_tile,x
lda dirt_draw_attr
sta sprite_attr,x
dec num_tiles
beq Return
iny
bit dirt_draw_counter
bpl :+
dec dirt_draw_counter
bmi :+
;
lda dirt_draw_attr
ora #$40
sta dirt_draw_attr
dec draw_h
:
lda draw_h
clc
adc #8
sta draw_h
bcs Return
jmp DrawLoop
Return:
rts
.endproc
DirtDraw = DirtExecute::Draw
.proc TrashShakesAndSpitsGunk
; Player came down from a jump and landed on trash can.
mov {dirt_shake,x}, #15
ldy #1
jsr TrashGunkSpawnTwoInOppositeDirections
rts
.endproc
shake_offset_v:
.byte 1
.byte 0
.byte 1
.byte 1
dirt_spit_animation_left:
.byte DIRTY_SPIT_TILE_0
.byte DIRTY_SPIT_TILE_2
.byte DIRTY_SPIT_TILE_4
.byte DIRTY_SPIT_TILE_6
dirt_spit_animation_right:
.byte DIRTY_SPIT_TILE_1
.byte DIRTY_SPIT_TILE_3
.byte DIRTY_SPIT_TILE_5
.byte DIRTY_SPIT_TILE_7