Skip to content

Commit

Permalink
Draw injuries on lava boss when it gets hit
Browse files Browse the repository at this point in the history
  • Loading branch information
mdsteele committed May 9, 2024
1 parent 35ea47e commit e24f285
Show file tree
Hide file tree
Showing 10 changed files with 285 additions and 140 deletions.
4 changes: 2 additions & 2 deletions src/chr.asm
Original file line number Diff line number Diff line change
Expand Up @@ -564,10 +564,10 @@ _chr_begin:
chr_inc "steam_pipes"
chr_inc "volcanic1"
chr_inc "volcanic2"
chr_res $07
chr_inc "terrain_boss_lava", kTileIdBgTerrainBossLavaFirst
chr_inc "arch"
chr_inc "boiler"
chr_inc "terrain_boss_lava"
chr_inc "terrain_boss_lava_hurt", kTileIdBgTerrainBossLavaHurtFirst
END_CHR_BANK
.ENDPROC

Expand Down
107 changes: 91 additions & 16 deletions src/rooms/boss_lava.asm
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,15 @@
.IMPORT Ram_MachineGoalHorz_u8_arr
.IMPORT Ram_Oam_sObj_arr64
.IMPORT Ram_PlatformLeft_i16_0_arr
.IMPORT Ram_PpuTransfer_arr
.IMPORTZP Zp_Active_sIrq
.IMPORTZP Zp_Buffered_sIrq
.IMPORTZP Zp_Chr04Bank_u8
.IMPORTZP Zp_IrqTmp_byte
.IMPORTZP Zp_NextIrq_int_ptr
.IMPORTZP Zp_PointX_i16
.IMPORTZP Zp_PointY_i16
.IMPORTZP Zp_PpuTransferLen_u8
.IMPORTZP Zp_RoomScrollY_u8
.IMPORTZP Zp_RoomState
.IMPORTZP Zp_ShapePosX_i16
Expand Down Expand Up @@ -179,8 +181,8 @@ kBossBodyInitTopY = kBossZoneTopY + kBlockHeightPx * kBossInitGoalY

;;; The tile row/col in the lower nametable for the top-left corner of the
;;; boss's BG tiles.
kBossBgStartRow = 7
kBossBgStartCol = 0
kBossBgStartRow = 8
kBossBgStartCol = 2

;;; The PPU addresses for the start (left) of each row of the boss's BG tiles.
.LINECONT +
Expand All @@ -192,6 +194,10 @@ Ppu_BossRow2Start = Ppu_Nametable3_sName + sName::Tiles_u8_arr + \
kScreenWidthTiles * (kBossBgStartRow + 2) + kBossBgStartCol
Ppu_BossRow3Start = Ppu_Nametable3_sName + sName::Tiles_u8_arr + \
kScreenWidthTiles * (kBossBgStartRow + 3) + kBossBgStartCol
.ASSERT kBossBgStartRow .mod 4 = 0, error
.ASSERT (kBossBgStartCol + 2) .mod 4 = 0, error
Ppu_BossBodyAttrs = Ppu_Nametable3_sName + sName::Attrs_u8_arr64 + \
(kBossBgStartRow / 4) * 8 + ((kBossBgStartCol + 2) / 4)
.LINECONT -

;;; Modes that the boss in this room can be in.
Expand Down Expand Up @@ -279,7 +285,7 @@ _Ext_sRoomExt:
d_addr Devices_sDevice_arr_ptr, _Devices_sDevice_arr
d_addr Passages_sPassage_arr_ptr, 0
d_addr Enter_func_ptr, FuncA_Room_BossLava_EnterRoom
d_addr FadeIn_func_ptr, FuncA_Terrain_BossLava_FadeInRoom
d_addr FadeIn_func_ptr, FuncC_Boss_Lava_FadeInRoom
d_addr Tick_func_ptr, FuncA_Room_BossLava_TickRoom
d_addr Draw_func_ptr, FuncC_Boss_Lava_DrawRoom
D_END
Expand Down Expand Up @@ -506,6 +512,11 @@ _CheckForHitTail:
sta Zp_RoomState + sState::BossCooldown_u8
lda #eSample::BossHurtE ; param: eSample to play
jsr Func_PlaySfxSample
;; Decrement boss health (if nonzero).
lda Zp_RoomState + sState::BossHealth_u8
beq @done
dec Zp_RoomState + sState::BossHealth_u8
jsr FuncC_Boss_Lava_TransferBossBodyTiles
@done:
_CoolDown:
lda Zp_RoomState + sState::BossCooldown_u8
Expand Down Expand Up @@ -648,11 +659,11 @@ _BossHurt:
ldx #kBossTailPlatformIndex ; param: platform index
jmp Func_MovePlatformHorz ; preserves X
@doneVibrate:
;; At the end of the hurt animation, decrement the boss's health. If its
;; health is now zero, kill the boss. Otherwise, start scuttling.
dec Zp_RoomState + sState::BossHealth_u8
;; At the end of the hurt animation, if boss's health is now zero, kill the
;; boss. Otherwise, start scuttling.
lda Zp_RoomState + sState::BossHealth_u8
bne _StartScuttling ; boss is not dead yet
lda #eBossMode::Dead
.assert eBossMode::Dead = 0, error
sta Zp_RoomState + sState::Current_eBossMode
rts
_StartScuttling:
Expand Down Expand Up @@ -1063,37 +1074,101 @@ _ValvePipePlatformIndex_u8_arr4:

.SEGMENT "PRGA_Terrain"

.PROC DataA_Terrain_BossLavaInitTransfer_arr
.PROC DataA_Terrain_BossLavaLegsTransfer_arr
.assert kBossFullWidthTiles = 8, error
.assert kBossHeightTiles = 4, error
.assert kTileIdBgAnimBossLavaFirst = $50, error
;; Nametable attributes to color body injuries red:
.byte kPpuCtrlFlagsHorz
.dbyt Ppu_BossBodyAttrs ; transfer destination
.byte 1
.byte $55
;; Row 0:
.byte kPpuCtrlFlagsHorz
.dbyt Ppu_BossRow0Start ; transfer destination
.byte 8
.byte $50, $54, $58, $b8, $b9, $5c, $60, $64
.byte $50, $54, $58, $00, $00, $5c, $60, $64
;; Row 1:
.byte kPpuCtrlFlagsHorz
.dbyt Ppu_BossRow1Start ; transfer destination
.byte 8
.byte $51, $55, $59, $ba, $bb, $5d, $61, $65
.byte $51, $55, $59, $00, $00, $5d, $61, $65
;; Row 2:
.byte kPpuCtrlFlagsHorz
.dbyt Ppu_BossRow2Start ; transfer destination
.byte 8
.byte $52, $56, $5a, $bc, $bd, $5e, $62, $66
.byte $52, $56, $5a, $00, $00, $5e, $62, $66
;; Row 3:
.byte kPpuCtrlFlagsHorz
.dbyt Ppu_BossRow3Start ; transfer destination
.byte 8
.byte $53, $57, $5b, $be, $bf, $5f, $63, $67
.byte $53, $57, $5b, $00, $00, $5f, $63, $67
.ENDPROC

;;;=========================================================================;;;

.SEGMENT "PRGC_Boss"

.PROC DataC_Boss_BossLavaBodyTransfer_arr
.assert kBossFullWidthTiles = 8, error
.assert kBossHeightTiles = 4, error
.assert kTileIdBgTerrainBossLavaFirst = $a8, error
;; Col 3:
.byte kPpuCtrlFlagsVert
.dbyt Ppu_BossRow0Start + 3 ; transfer destination
.byte 4
.byte $a8, $aa, $ac, $ae
;; Col 4:
.byte kPpuCtrlFlagsVert
.dbyt Ppu_BossRow0Start + 4 ; transfer destination
.byte 4
.byte $a9, $ab, $ad, $af
.ENDPROC

;;; @prereq PRGA_Terrain is loaded.
.PROC FuncC_Boss_Lava_FadeInRoom
jsr FuncA_Terrain_FadeInShortRoomWithLava
;; Transfer BG tiles for the boss's legs.
ldax #DataA_Terrain_BossLavaLegsTransfer_arr ; param: data pointer
ldy #.sizeof(DataA_Terrain_BossLavaLegsTransfer_arr) ; param: data length
jsr Func_BufferPpuTransfer
;; Transfer BG tiles for the boss's body.
fall FuncC_Boss_Lava_TransferBossBodyTiles
.ENDPROC

.PROC FuncA_Terrain_BossLava_FadeInRoom
ldax #DataA_Terrain_BossLavaInitTransfer_arr ; param: data pointer
ldy #.sizeof(DataA_Terrain_BossLavaInitTransfer_arr) ; param: data length
;;; Buffers a PPU transfer to draw the BG tiles for the lava boss's body,
;;; taking its current health into account. Note that this is called from both
;;; room fade-in and boss tick functions, so no particular PRGA bank is
;;; guaranteed to be loaded.
.PROC FuncC_Boss_Lava_TransferBossBodyTiles
;; Buffer a transfer for the boss's body at full health.
ldax #DataC_Boss_BossLavaBodyTransfer_arr ; param: data pointer
ldy #.sizeof(DataC_Boss_BossLavaBodyTransfer_arr) ; param: data length
jsr Func_BufferPpuTransfer
jmp FuncA_Terrain_FadeInShortRoomWithLava
;; For each point of damage on the boss, alter one of the body tiles in the
;; transfer buffer to be injured.
lda #kBossInitHealth
sub Zp_RoomState + sState::BossHealth_u8
tax
bpl @continue ; unconditional
@loop:
lda Zp_PpuTransferLen_u8
sub _OffsetFromEnd_u8_arr, x
tay
lda Ram_PpuTransfer_arr, y
.linecont +
.assert kTileIdBgTerrainBossLavaHurtFirst = \
kTileIdBgTerrainBossLavaFirst | $10, error
ora #$10
.linecont -
sta Ram_PpuTransfer_arr, y
@continue:
dex
bpl @loop
rts
_OffsetFromEnd_u8_arr:
: .byte 4, 10, 1, 12, 2, 11, 3, 9
.assert * - :- = kBossInitHealth, error
.ENDPROC

;;;=========================================================================;;;
Expand Down
4 changes: 4 additions & 0 deletions src/rooms/boss_lava.inc
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
;;; BG tile IDs for animating the lava boss's legs.
kTileIdBgAnimBossLavaFirst = $50

;;; BG tile IDs for the lava boss's body, with and without injuries.
kTileIdBgTerrainBossLavaHurtFirst = $b8
kTileIdBgTerrainBossLavaFirst = $a8

;;; OBJ tile IDs for drawing the lava boss.
kTileIdObjBossLavaJawsFirst = $d0

Expand Down
70 changes: 35 additions & 35 deletions src/tiles/shadow1.ahi
Original file line number Diff line number Diff line change
Expand Up @@ -2,41 +2,41 @@ ahi1 f0 p1 i16 w8 h8

0004;0;54;ECEEEC;FF0;FF0;FF0;FF0;FF0;FF0;FF0;FF0;FF0;FF0;FF0;FF0

03333333
31111111
31333333
31311133
31311333
31313333
31333333
31333333

33333330
11111113
33333313
33111313
33311313
33331313
33333313
33333313

31333333
31333333
31313333
31311333
31311133
31333333
31111111
03333333

33333313
33333313
33331313
33311313
33111313
33333313
11111113
33333330
00000000
00000000
00000000
00000000
00000000
00000000
00000000
00000000

00000000
00000000
00000000
00000000
00000000
00000000
00000000
00000000

00000000
00000000
00000000
00000000
00000000
00000000
00000000
00000000

00000000
00000000
00000000
00000000
00000000
00000000
00000000
00000000

31333333
13333333
Expand Down
75 changes: 75 additions & 0 deletions src/tiles/terrain_boss_lava_hurt.ahi
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
ahi1 f0 p1 i8 w8 h8

;0;982220;ECEEEC;FF0;FF0;FF0;FF0;FF0;FF0;FF0;FF0;FF0;FF0;FF0;FF0

11333313
13333313
13323311
13223331
33233223
31122323
13332333
33333333

31333311
31333221
11332231
13222331
33323333
33223113
33233331
33233333

33333333
33133333
33113223
32223233
33323233
33122333
31332233
11333133

33333333
33333133
33331133
33331333
33331223
33222133
33323313
33132311

13333133
13333333
33222333
32233223
33332233
33113333
33113333
13333113

33133331
33332231
33322333
33222233
33333233
33331133
33331133
31133331

11323113
11223333
13233113
32231113
32321113
33333333
30113303
00000003

31133311
33332311
31132331
31112223
31112322
33333333
30331103
30000000
Loading

0 comments on commit e24f285

Please sign in to comment.