-
Notifications
You must be signed in to change notification settings - Fork 0
/
endboss.asm
533 lines (464 loc) · 8.14 KB
/
endboss.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
.export EndBossInit
.export EndBossUpdate
.export EndBossFillGraphics
.export EndBossSwatterHandle
.export EndbossAnimation
.include "include.const.asm"
.include "include.controller.asm"
.include "include.branch-macros.asm"
.include "include.mov-macros.asm"
.include "include.sys.asm"
.include "include.tiles.asm"
.include "gfx.h.asm"
.include "hud_display.h.asm"
.include "render_action.h.asm"
.include "object_list.h.asm"
.include "score_combo.h.asm"
.include "famitone.h.asm"
.include "sound.h.asm"
.include "marque.h.asm"
.include "include.sprites.asm"
.include "sprite_space.h.asm"
.include "memory_layout.h.asm"
.include "hurt_player.h.asm"
.importzp endboss_screen, endboss_count, endboss_state
.importzp endboss_h, endboss_health, endboss_aggro, endboss_speed
.importzp endboss_iframe, endboss_show_meter, endboss_is_dead
.importzp endboss_render_animation
.importzp endboss_render_animation, endboss_render_count
.importzp endboss_smell
.importzp player_owns_swatter, player_health, player_h
.importzp blink_bg_color
.importzp bg_x_scroll, bg_nt_select
.importzp draw_h
.importzp which_level
.importzp values
inner = values + $0
outer = values + $1
; Reuse
meter = values + $0
is_near = values + $2
BOSS_LEVEL = MAX_LEVEL
BOSS_HEALTH_PALETTE = 3
BOSS_HEALTH_METER_V = $40
SMELL_ANIMATION_LIMIT = 24
.proc EndBossInit
lda which_level
cmp #BOSS_LEVEL
beq Okay
rts
Okay:
mov bg_x_scroll, #$00
mov bg_nt_select, #$00
;
mov endboss_health, #12
mov endboss_h, #$30
mov endboss_screen, #$01
mov endboss_state, #0
mov endboss_count, #0
mov endboss_aggro, #0
mov endboss_is_dead, #0
mov endboss_render_animation, #0
mov endboss_render_count, #0
mov endboss_smell, _
rts
.endproc
.proc EndBossUpdate
lda which_level
cmp #BOSS_LEVEL
beq Okay
rts
Okay:
.scope BlinkBg
lda blink_bg_color
beq Break
dec blink_bg_color
bne Break
lda #1
jsr AllocateRenderAction
mov {render_action_addr_high,y}, #$3f
mov {render_action_addr_low,y}, #$00
mov {render_action_data,y}, #$0f
Break:
.endscope
lda endboss_state
beq MovementIntoView
cmp #1
beq DriftAndFire
BossDead:
.scope BossDead
inc endboss_is_dead
lda endboss_is_dead
cmp #80
bne WaitMore
jmp ExitBoss
WaitMore:
rts
.endscope
MovementIntoView:
.scope MovementIntoView
lda endboss_h
beq Underflow
dec endboss_h
jmp State
Underflow:
dec endboss_h
dec endboss_screen
State:
lda endboss_h
cmp #$90
bne Next
mov endboss_state, #1
mov endboss_speed, #$ff
Next:
jmp CheckVunerable
.endscope
DriftAndFire:
DriftMovement:
.scope DriftAndFire
inc endboss_count
lda endboss_count
and #$03
bne AfterDrift
lda endboss_h
clc
adc endboss_speed
sta endboss_h
AfterDrift:
lda endboss_count
cmp #$80
blt AfterDir
mov endboss_count, #0
lda endboss_speed
eor #$ff
clc
adc #1
sta endboss_speed
AfterDir:
.endscope
Attack:
.scope Attack
inc endboss_aggro
lda endboss_aggro
cmp #$35
bne Next
mov endboss_aggro, #0
; Fire
jsr ObjectAllocate
mov {object_kind,x}, #OBJECT_KIND_DIRTY_SINK
mov {object_v,x}, #100
mov {object_h,x}, endboss_h
mov {object_screen,x}, #0
ldy #4
jsr ObjectConstructor
mov {object_life,x}, #$f0
Next:
.endscope
CheckVunerable:
.scope Iframe
lda endboss_iframe
beq CanBeHit
dec endboss_iframe
jmp Display
.endscope
CanBeHit:
.scope CanBeHit
; Is swatter being thrown.
ldy player_owns_swatter
bmi Break
; Screen
lda object_screen,y
bne Break
; Vertical
lda object_v,y
cmp #$90
bge Break
; Horizontal
lda object_h,y
sec
sbc endboss_h
bmi Break
cmp #$10
bge Break
; Hit the boss
mov endboss_iframe, #$30
mov endboss_show_meter, #$50
lda #SFX_FLY_KILLED
jsr SoundPlay
lda #5
jsr ScoreAddLow
dec endboss_health
bne Flash
; Boss is dead!
mov endboss_state, #2
mov endboss_screen, #$01
mov endboss_h, #$f0
Flash:
mov blink_bg_color, #2
lda #1
jsr AllocateRenderAction
mov {render_action_addr_high,y}, #$3f
mov {render_action_addr_low,y}, #$00
mov {render_action_data,y}, #$16
Break:
.endscope
Display:
lda #$30
sec
sbc endboss_h
sta bg_x_scroll
lda #$01
sbc endboss_screen
sta bg_nt_select
SmellRender:
.scope SmellRender
; Determine if player is near the boss.
mov is_near, #0
lda endboss_screen
bne Break
lda endboss_h
sec
sbc player_h
cmp #$1c
bge Break
Near:
mov is_near, #$ff
Break:
;
lda endboss_smell
bne Animate
bit is_near
bpl Next
Animate:
inc endboss_smell
lda endboss_smell
lsr a
lsr a
tay
jsr DrawSmell
; Check if end of animation, if so either loop or stop.
lda endboss_smell
cmp #SMELL_ANIMATION_LIMIT
bne Next
mov endboss_smell, #0
bit is_near
bpl Next
inc endboss_smell
Next:
.endscope
PlayerOverlap:
.scope PlayerOverlap
lda player_health
beq Break
; Kill them.
lda endboss_screen
bne Break
lda player_h
cmp endboss_h
blt Break
; Play sound effect
ldy #5
jsr HurtPlayer
Break:
.endscope
.scope AnimateWings
inc endboss_render_count
lda endboss_render_count
cmp #4
blt Next
mov endboss_render_count, #0
inc endboss_render_animation
lda endboss_render_animation
and #1
ora #$80
sta endboss_render_animation
Next:
.endscope
.scope DrawHealthMeter
lda endboss_show_meter
beq Next
dec endboss_show_meter
jsr EndBossFillMeter
mov draw_h, endboss_h
; left edge
jsr SpriteSpaceAllocate
lda draw_h
sta sprite_h,x
lda #BOSS_HEALTH_METER_V
sta sprite_v,x
lda #BOSS_HEALTH_EDGE_TILE
sta sprite_tile,x
lda #BOSS_HEALTH_PALETTE
sta sprite_attr,x
lda draw_h
clc
adc #8
sta draw_h
ldy #0
MeterDrawLoop:
; meter 0 edge
jsr SpriteSpaceAllocate
lda draw_h
sta sprite_h,x
lda #BOSS_HEALTH_METER_V
sta sprite_v,x
lda meter,y
asl a
clc
adc #BOSS_HEALTH_METER_BASE_TILE
sta sprite_tile,x
lda #BOSS_HEALTH_PALETTE
sta sprite_attr,x
lda draw_h
clc
adc #8
sta draw_h
iny
cpy #3
blt MeterDrawLoop
MeterDrawDone:
; right edge
jsr SpriteSpaceAllocate
lda draw_h
sta sprite_h,x
lda #BOSS_HEALTH_METER_V
sta sprite_v,x
lda #BOSS_HEALTH_EDGE_TILE
sta sprite_tile,x
lda #(BOSS_HEALTH_PALETTE | $40)
sta sprite_attr,x
Next:
.endscope
rts
.endproc
.proc EndBossFillGraphics
jsr PrepareRenderHorizontal
ldx #<boss_graphics
ldy #>boss_graphics
jsr MemoryLayoutLoadNametable
lda #$ff
jsr HudApplyAttributes
jsr RemoveLeftBackground
; Collision
lda #$55
ldx #$0
Loop:
sta $5c0,x
inx
cpx #$10
bne Loop
rts
.endproc
.proc EndBossSwatterHandle
; Palette for swatter.
lda #1
jsr AllocateRenderAction
mov {render_action_addr_high,y}, #$3f
mov {render_action_addr_low,y}, #$12
mov {render_action_data,y}, #$10
rts
.endproc
.proc RemoveLeftBackground
mov PPU_ADDR, #$20
mov PPU_ADDR, #$c0
mov outer, #$03
mov inner, #$40
lda #0
Loop:
sta PPU_DATA
dec inner
bne Loop
dec outer
bne Loop
rts
.endproc
ExitBoss:
jsr FamiToneMusicStop
jsr DisableDisplayAndNmi
inc which_level
jmp MarqueScreen
.segment "DAT0"
boss_graphics:
.include ".b/boss.compressed.asm"
.segment "BOOT"
.proc EndbossAnimation
lda endboss_render_animation
bpl Return
and #$01
sta endboss_render_animation
beq Render0
bne Render1
Render0:
jmp BossAnimateWing0
Render1:
jmp BossAnimateWing1
Return:
rts
.endproc
BossAnimateWing0:
.include ".b/boss.animate0.asm"
BossAnimateWing1:
.include ".b/boss.animate1.asm"
.proc EndBossFillMeter
ldx #0
lda endboss_health
Loop:
cmp #0
beq EmptyPiece
cmp #4
bge FullPiece
PartialPiece:
tay
lda #0
bpl Assign
EmptyPiece:
ldy #0
bpl Assign
FullPiece:
ldy #4
sec
sbc #4
Assign:
sty meter,x
inx
cpx #3
blt Loop
rts
.endproc
.proc DrawSmell
lda smell_animation_frame,y
beq Return
tay
lda endboss_h
clc
adc #$0a
sta draw_h
jsr SpriteSpaceAllocate
mov {sprite_v,x}, #$9c
mov {sprite_h,x}, draw_h
tya
sta sprite_tile,x
mov {sprite_attr,x}, #3
lda draw_h
clc
adc #08
sta draw_h
iny
iny
jsr SpriteSpaceAllocate
mov {sprite_v,x}, #$9c
mov {sprite_h,x}, draw_h
tya
sta sprite_tile,x
mov {sprite_attr,x}, #3
Return:
rts
.endproc
smell_animation_frame:
.byte $cb
.byte $cf
.byte $d3
.byte $d7
.byte $00
.byte $00
.byte $00