Skip to content

Commit

Permalink
Implement fire grub baddies
Browse files Browse the repository at this point in the history
  • Loading branch information
mdsteele committed Jul 2, 2024
1 parent e9577b2 commit 1ff8b66
Show file tree
Hide file tree
Showing 17 changed files with 268 additions and 30 deletions.
8 changes: 8 additions & 0 deletions src/actor.asm
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
.IMPORT FuncA_Actor_TickBadGooRed
.IMPORT FuncA_Actor_TickBadGronta
.IMPORT FuncA_Actor_TickBadGrub
.IMPORT FuncA_Actor_TickBadGrubFire
.IMPORT FuncA_Actor_TickBadHotheadHorz
.IMPORT FuncA_Actor_TickBadHotheadVert
.IMPORT FuncA_Actor_TickBadJelly
Expand Down Expand Up @@ -91,6 +92,7 @@
.IMPORT FuncA_Objects_DrawActorBadGooRed
.IMPORT FuncA_Objects_DrawActorBadGronta
.IMPORT FuncA_Objects_DrawActorBadGrub
.IMPORT FuncA_Objects_DrawActorBadGrubFire
.IMPORT FuncA_Objects_DrawActorBadHotheadHorz
.IMPORT FuncA_Objects_DrawActorBadHotheadVert
.IMPORT FuncA_Objects_DrawActorBadJelly
Expand Down Expand Up @@ -494,6 +496,7 @@ _NoHit:
d_byte BadGooRed, kBadGooRadius
d_byte BadGronta, kOrcBoundingBoxUp
d_byte BadGrub, kBadGrubBoundingBoxUp
d_byte BadGrubFire, kBadGrubBoundingBoxUp
d_byte BadHotheadHorz, 6
d_byte BadHotheadVert, 6
d_byte BadJelly, kBadJellyRadius
Expand Down Expand Up @@ -556,6 +559,7 @@ _NoHit:
d_byte BadGooRed, kBadGooRadius
d_byte BadGronta, kOrcBoundingBoxDown
d_byte BadGrub, kBadGrubBoundingBoxDown
d_byte BadGrubFire, kBadGrubBoundingBoxDown
d_byte BadHotheadHorz, 6
d_byte BadHotheadVert, 6
d_byte BadJelly, kBadJellyRadius
Expand Down Expand Up @@ -618,6 +622,7 @@ _NoHit:
d_byte BadGooRed, kBadGooRadius
d_byte BadGronta, kOrcBoundingBoxSide
d_byte BadGrub, kBadGrubBoundingBoxSide
d_byte BadGrubFire, kBadGrubBoundingBoxSide
d_byte BadHotheadHorz, 6
d_byte BadHotheadVert, 6
d_byte BadJelly, kBadJellyRadius
Expand Down Expand Up @@ -748,6 +753,7 @@ _TypeSpecificTick:
d_entry table, BadGooRed, FuncA_Actor_TickBadGooRed
d_entry table, BadGronta, FuncA_Actor_TickBadGronta
d_entry table, BadGrub, FuncA_Actor_TickBadGrub
d_entry table, BadGrubFire, FuncA_Actor_TickBadGrubFire
d_entry table, BadHotheadHorz, FuncA_Actor_TickBadHotheadHorz
d_entry table, BadHotheadVert, FuncA_Actor_TickBadHotheadVert
d_entry table, BadJelly, FuncA_Actor_TickBadJelly
Expand Down Expand Up @@ -914,6 +920,7 @@ _Finish:
d_entry table, BadGooRed, FuncA_Room_InitActorBadGooRed
d_entry table, BadGronta, Func_InitActorBadGronta
d_entry table, BadGrub, Func_InitActorWithFlags
d_entry table, BadGrubFire, Func_InitActorWithFlags
d_entry table, BadHotheadHorz, Func_InitActorWithFlags
d_entry table, BadHotheadVert, Func_InitActorWithFlags
d_entry table, BadJelly, Func_InitActorWithState1
Expand Down Expand Up @@ -1005,6 +1012,7 @@ _Finish:
d_entry table, BadGooRed, FuncA_Objects_DrawActorBadGooRed
d_entry table, BadGronta, FuncA_Objects_DrawActorBadGronta
d_entry table, BadGrub, FuncA_Objects_DrawActorBadGrub
d_entry table, BadGrubFire, FuncA_Objects_DrawActorBadGrubFire
d_entry table, BadHotheadHorz, FuncA_Objects_DrawActorBadHotheadHorz
d_entry table, BadHotheadVert, FuncA_Objects_DrawActorBadHotheadVert
d_entry table, BadJelly, FuncA_Objects_DrawActorBadJelly
Expand Down
1 change: 1 addition & 0 deletions src/actor.inc
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ kMaxActors = 16
BadGooRed ; squishes back and forth
BadGronta ; the final boss
BadGrub ; crawls left/right on a floor
BadGrubFire ; like grub, but can also shoot at you
BadHotheadHorz ; crawls around a platform, and can drop fire
BadHotheadVert ; crawls around a platform, and can drop fire
BadJelly ; moves in a straight line, turning when it hits a wall
Expand Down
2 changes: 1 addition & 1 deletion src/actors/flydrop.inc
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@
;;; * State4: Unused.

;;; Tile IDs for drawing flydrop baddie actors.
kTileIdObjBadFlydropFirst = $88
kTileIdObjBadFlydropFirst = $b0

;;;=========================================================================;;;
2 changes: 1 addition & 1 deletion src/actors/goo.inc
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@
;;; * State4: Unused.

;;; Tile IDs for drawing goo baddie actors.
kTileIdObjBadGooFirst = $a0
kTileIdObjBadGooFirst = $90

;;;=========================================================================;;;
130 changes: 126 additions & 4 deletions src/actors/grub.asm
Original file line number Diff line number Diff line change
Expand Up @@ -23,36 +23,127 @@
.INCLUDE "../tileset.inc"
.INCLUDE "grub.inc"

.IMPORT FuncA_Actor_FaceTowardsAvatar
.IMPORT FuncA_Actor_HarmAvatarIfCollision
.IMPORT FuncA_Actor_IsAvatarWithinVertDistances
.IMPORT FuncA_Actor_SetPointInFrontOfActor
.IMPORT FuncA_Objects_Draw2x2Actor
.IMPORT Func_FindEmptyActorSlot
.IMPORT Func_GetRandomByte
.IMPORT Func_InitActorProjFireball
.IMPORT Func_IsPointInAnySolidPlatform
.IMPORT Func_PlaySfxShootFire
.IMPORT Func_PointHitsTerrain
.IMPORT Func_SetActorCenterToPoint
.IMPORT Ram_ActorFlags_bObj_arr
.IMPORT Ram_ActorPosX_i16_0_arr
.IMPORT Ram_ActorPosX_i16_1_arr
.IMPORT Ram_ActorState1_byte_arr
.IMPORT Ram_ActorState2_byte_arr
.IMPORTZP Zp_Current_sTileset
.IMPORTZP Zp_TerrainColumn_u8_arr_ptr

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

;;; How long it takes a fire grub to rise up (or lower again), in frames.
.DEFINE kGrubFireRiseFrames 16

;;; How many fireballs a fire grub should shoot per attack cycle.
kGrubFireAttackCount = 4

;;; The cooldown between fireballs from a fire grub, in frames.
.DEFINE kGrubFireCooldownFrames 16

;;; The total duration of a fire grub's attack cycle, in frames.
.LINECONT +
kGrubFireAttackFrames = \
kGrubFireRiseFrames * 2 + kGrubFireCooldownFrames * kGrubFireAttackCount
.LINECONT -

;;; The OBJ palette number to use for drawing grub baddie actors.
kPaletteObjGrub = 0

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

.SEGMENT "PRGA_Actor"

;;; Performs per-frame updates for a fire grub baddie actor.
;;; @param X The actor index.
;;; @preserve X
.EXPORT FuncA_Actor_TickBadGrubFire
.PROC FuncA_Actor_TickBadGrubFire
jsr FuncA_Actor_HarmAvatarIfCollision ; preserves X
lda Ram_ActorState2_byte_arr, x ; attack timer
beq _CrawlOrAttack
_ContinueAttacking:
dec Ram_ActorState2_byte_arr, x ; attack timer
beq FuncA_Actor_TickBadGrub_Crawl ; preserves X
lda Ram_ActorState2_byte_arr, x ; attack timer
sub #kGrubFireRiseFrames
blt @done ; the grub is now lowering
cmp #kGrubFireCooldownFrames * kGrubFireAttackCount
bge @done ; the grub is still raising
mod #kGrubFireCooldownFrames
cmp #kGrubFireCooldownFrames - 1
bne @done ; cooling down between projectiles
;; Set the fireball position just in front of the grub actor.
lda #8 ; param: offset
jsr FuncA_Actor_SetPointInFrontOfActor ; preserves X
;; Set the fireball aim angle based on which way the grub is facing.
jsr Func_GetRandomByte ; preserves X, returns A
mod #$10
rsub #0
sta T0 ; aim angle
lda Ram_ActorFlags_bObj_arr, x
and #bObj::FlipH
beq @shoot
lda #$80
sub T0 ; aim angle
sta T0 ; aim angle
@shoot:
;; Shoot the fireball.
stx T3 ; grub actor index
jsr Func_FindEmptyActorSlot ; preserves T0+, returns C and X
bcs @restoreX
jsr Func_SetActorCenterToPoint ; preserves X and T0+
lda T0 ; param: aim angle ($00 for right, or $80 for left)
jsr Func_InitActorProjFireball ; preserves T3+
jsr Func_PlaySfxShootFire ; preserves T0+
@restoreX:
ldx T3 ; grub actor index
@done:
rts
_CrawlOrAttack:
;; If the grub is still in the middle of a crawl cycle, continue it.
lda Ram_ActorState1_byte_arr, x ; crawl timer
bne FuncA_Actor_TickBadGrub_Crawl ; preserves X
;; If the player avatar isn't nearby vertically, start a new crawl cycle.
lda #8 ; param: distance above avatar
ldy #8 ; param: distance below avatar
jsr FuncA_Actor_IsAvatarWithinVertDistances ; preserves X, returns C
bcc FuncA_Actor_TickBadGrub_Crawl ; preserves X
;; Start an attack cycle.
lda #kGrubFireAttackFrames
sta Ram_ActorState2_byte_arr, x ; attack timer
jmp FuncA_Actor_FaceTowardsAvatar ; preserves X
.ENDPROC

;;; Performs per-frame updates for a grub baddie actor.
;;; @param X The actor index.
;;; @preserve X
.EXPORT FuncA_Actor_TickBadGrub
.PROC FuncA_Actor_TickBadGrub
jsr FuncA_Actor_HarmAvatarIfCollision ; preserves X
lda Ram_ActorState1_byte_arr, x
fall FuncA_Actor_TickBadGrub_Crawl ; preserves X
.ENDPROC

;;; Performs per-frame updates for a grub baddie actor that's crawling.
;;; @param X The actor index.
;;; @preserve X
.PROC FuncA_Actor_TickBadGrub_Crawl
lda Ram_ActorState1_byte_arr, x ; crawl timer
beq _StartMove
dec Ram_ActorState1_byte_arr, x
dec Ram_ActorState1_byte_arr, x ; crawl timer
cmp #$18
blt _Return
lda Ram_ActorFlags_bObj_arr, x
Expand Down Expand Up @@ -95,20 +186,51 @@ _StartMove:
;; Start a new movement cycle for the grub.
@continueForward:
lda #$1f
sta Ram_ActorState1_byte_arr, x
sta Ram_ActorState1_byte_arr, x ; crawl timer
rts
.ENDPROC

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

.SEGMENT "PRGA_Objects"

;;; Draws a fire grub baddie actor.
;;; @param X The actor index.
;;; @preserve X
.EXPORT FuncA_Objects_DrawActorBadGrubFire
.PROC FuncA_Objects_DrawActorBadGrubFire
lda Ram_ActorState2_byte_arr, x ; attack timer
beq FuncA_Objects_DrawActorBadGrub ; preserves X
sub #kGrubFireRiseFrames
blt @lowering
sub #kGrubFireAttackFrames - kGrubFireRiseFrames * 2
bge @raising
@fullyRaised:
ldy #0
beq @draw ; unconditional
@lowering:
eor #$ff
@raising:
div #kGrubFireRiseFrames / 4
tay
@draw:
lda _TileIds_u8_arr4, y ; param: first tile ID
ldy #kPaletteObjGrub ; param: palette
jmp FuncA_Objects_Draw2x2Actor ; preserves X
_TileIds_u8_arr4:
.byte kTileIdObjBadGrubFireFirst + $04
.byte kTileIdObjBadGrubFireFirst + $00
.byte kTileIdObjBadGrubFireFirst + $00
.byte kTileIdObjBadGrubFirst + $04
.byte kTileIdObjBadGrubFirst + $04
.ENDPROC

;;; Draws a grub baddie actor.
;;; @param X The actor index.
;;; @preserve X
.EXPORT FuncA_Objects_DrawActorBadGrub
.PROC FuncA_Objects_DrawActorBadGrub
lda Ram_ActorState1_byte_arr, x
lda Ram_ActorState1_byte_arr, x ; crawl timer
div #8
and #$03
tay
Expand Down
4 changes: 3 additions & 1 deletion src/actors/grub.inc
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
;;; cleared if it is facing right.
;;; * State1: A counter that decrements each frame; when it's zero, the grub
;;; starts another movement cycle and resets the counter.
;;; * State2: Unused.
;;; * State2: (BadGrubFire only) When nonzero, the fire grub is in the middle
;;; of an attack cycle, and this decrements each frame.
;;; * State3: Unused.
;;; * State4: Unused.

Expand All @@ -35,5 +36,6 @@ kBadGrubBoundingBoxSide = 7

;;; Tile IDs for drawing grub baddie actors.
kTileIdObjBadGrubFirst = $9c
kTileIdObjBadGrubFireFirst = $a8

;;;=========================================================================;;;
2 changes: 2 additions & 0 deletions src/actors/townsfolk.inc
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,15 @@
;;; unchanged; if false ($00), the NPC is automatically drawn facing the
;;; player avatar.
;;; * State3: Unused.
;;; * State4: Unused.

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

;;; The first tile IDs for various adults.
kTileIdAdultElderFirst = $c4
kTileIdAdultElder1 = kTileIdAdultElderFirst + 0
kTileIdAdultElder2 = kTileIdAdultElderFirst + 6
kTileIdAdultGhostFirst = $e4
kTileIdAdultManFirst = $d6
kTileIdAdultSmithFirst = $b8
kTileIdAdultSmith1 = kTileIdAdultSmithFirst + 0
Expand Down
29 changes: 15 additions & 14 deletions src/chr.asm
Original file line number Diff line number Diff line change
Expand Up @@ -1118,25 +1118,22 @@ _chr_begin:
.PROC Ppu_ChrObjBoss1
CHR2_BANK $80
chr_inc "spike", kTileIdObjSpike
chr_inc "emitter_light", kTileIdObjEmitterLight
chr_res $01
chr_inc "upgrade_ram", kTileIdObjUpgradeRamFirst
chr_res $02
chr_inc "ember", kTileIdObjEmber
chr_res $01
chr_inc "cannon", kTileIdObjCannonFirst
chr_inc "upgrade_opmul", kTileIdObjUpgradeOpMulFirst
chr_inc "emitter", kTileIdObjEmitterFirst
chr_res $08
chr_inc "upgrade_oprest", kTileIdObjUpgradeOpRestFirst
chr_inc "forcefield", kTileIdObjForcefieldFirst
chr_res $08
chr_inc "boss_garden_eye_white", kTileIdObjBossGardenEyeWhiteFirst
chr_inc "boss_garden_eye_mini", kTileIdObjBossGardenEyeMiniFirst
chr_inc "boss_garden_eye_red", kTileIdObjBossGardenEyeRedFirst
chr_inc "platform_crypt_bricks", kTileIdObjPlatformCryptBricksFirst
chr_inc "boss_crypt_pupil", kTileIdObjBossCryptPupilFirst
chr_inc "fireball", kTileIdObjFireballFirst
chr_inc "mermaid_ghost", kTileIdMermaidGhostFirst
chr_inc "orc_ghost", kTileIdObjOrcGhostFirst
chr_inc "anna_ghost", kTileIdObjAnnaGhostFirst
chr_res $1c
chr_inc "crusher", kTileIdObjCrusherFirst
chr_inc "winch", kTileIdObjWinchFirst
chr_inc "grenade", kTileIdObjGrenadeFirst
Expand Down Expand Up @@ -1419,18 +1416,22 @@ _chr_begin:
CHR2_BANK $80
chr_inc "acid", kTileIdObjAcid
chr_inc "emitter_light", kTileIdObjEmitterLight
chr_res $06
chr_inc "bad_flydrop", kTileIdObjBadFlydropFirst
chr_inc "emitter", kTileIdObjEmitterFirst
chr_res $02
chr_inc "forcefield", kTileIdObjForcefieldFirst
chr_res $04
chr_inc "barrier", kTileIdObjBarrierFirst
chr_inc "upgrade_opmul", kTileIdObjUpgradeOpMulFirst
chr_inc "bad_goo", kTileIdObjBadGooFirst
chr_res $18
chr_inc "bad_grub", kTileIdObjBadGrubFirst
chr_inc "bad_grub_fire", kTileIdObjBadGrubFireFirst
chr_inc "bad_flydrop", kTileIdObjBadFlydropFirst
chr_inc "forcefield", kTileIdObjForcefieldFirst
chr_inc "fireball", kTileIdObjFireballFirst
chr_inc "mermaid_ghost", kTileIdMermaidGhostFirst
chr_inc "orc_ghost", kTileIdObjOrcGhostFirst
chr_inc "laser", kTileIdObjLaserFirst
chr_inc "barrier", kTileIdObjBarrierFirst
chr_res $1e
chr_inc "anna_ghost", kTileIdObjAnnaGhostFirst
chr_inc "adult_ghost", kTileIdAdultGhostFirst
chr_inc "breaker", kTileIdObjBreakerFirst
END_CHR_BANK
.ENDPROC

Expand Down
2 changes: 1 addition & 1 deletion src/machines/emitter.inc
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ kTileIdBgDiagramEmitterXFirst = $e0
kTileIdBgDiagramEmitterYFirst = $f0

;;; OBJ tile IDs used for drawing emitter machines.
kTileIdObjEmitterFirst = $90
kTileIdObjEmitterFirst = $82

;;; The OBJ tile ID for the indicator light on an emitter machine.
kTileIdObjEmitterLight = $81
Expand Down
2 changes: 1 addition & 1 deletion src/platforms/barrier.inc
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ kBarrierPlatformHeightPx = $20
kBarrierPlatformMoveSpeed = 3

;;; OBJ tile IDs for drawing laboratory barrier platforms.
kTileIdObjBarrierFirst = $e0
kTileIdObjBarrierFirst = $8c

;;;=========================================================================;;;
2 changes: 1 addition & 1 deletion src/platforms/force.inc
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ kForcefieldPlatformWidth = $10
kForcefieldPlatformHeight = $10

;;; OBJ tile IDs for drawing forcefield platforms.
kTileIdObjForcefieldFirst = $98
kTileIdObjForcefieldFirst = $b8

;;;=========================================================================;;;
Loading

0 comments on commit 1ff8b66

Please sign in to comment.