Skip to content

Commit

Permalink
Always animate Alex NPC and player avatar when swimming
Browse files Browse the repository at this point in the history
  • Loading branch information
mdsteele committed Aug 31, 2024
1 parent dd778a7 commit 0a716c7
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 66 deletions.
14 changes: 13 additions & 1 deletion src/actors/child.asm
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
.IMPORT Ram_ActorFlags_bObj_arr
.IMPORT Ram_ActorState1_byte_arr
.IMPORT Ram_Oam_sObj_arr64
.IMPORTZP Zp_FrameCounter_u8

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

Expand Down Expand Up @@ -79,9 +80,20 @@ kPaletteObjChild = 1
lda Ram_ActorState1_byte_arr, x
stx T0 ; actor index
tax ; eNpcChild value
;; Special case: for eNpcChild::AlexSwimming1, automatically animate
;; between AlexSwimming1 and AlexSwimming2.
cpx #eNpcChild::AlexSwimming1
bne @setTiles
lda Zp_FrameCounter_u8
adc #6 ; offset so swimming animation isn't synced with player avatar
and #$10
bne @setTiles
ldx #eNpcChild::AlexSwimming2
@setTiles:
;; Set tile IDs for the objects.
lda _Feet_u8_arr, x
sta Ram_Oam_sObj_arr64 + .sizeof(sObj) * 1 + sObj::Tile_u8, y
adc #1
add #1
sta Ram_Oam_sObj_arr64 + .sizeof(sObj) * 3 + sObj::Tile_u8, y
lda _Head_u8_arr, x
sta Ram_Oam_sObj_arr64 + .sizeof(sObj) * 0 + sObj::Tile_u8, y
Expand Down
27 changes: 15 additions & 12 deletions src/avatar.asm
Original file line number Diff line number Diff line change
Expand Up @@ -251,16 +251,7 @@ _SetPoseInAir:
sta Zp_AvatarPose_eAvatar
rts
_SetPoseInWater:
;; The player avatar is in water, so set its pose to Swimming.
lda Zp_FrameCounter_u8
and #$10
bne @swimming2
@swimming1:
lda #eAvatar::Swimming1
bne @setAvatarPose ; unconditional
@swimming2:
lda #eAvatar::Swimming2
@setAvatarPose:
lda #eAvatar::Swimming1 ; animates automatically
sta Zp_AvatarPose_eAvatar
rts
_SetPoseOnGround:
Expand Down Expand Up @@ -847,11 +838,23 @@ _InAirReverseGravity:
@notInvincible:
_DrawObjects:
jsr FuncA_Objects_SetShapePosToAvatarCenter
lda Zp_AvatarPose_eAvatar
;; If the player avatar is hidden, don't draw it.
ldx Zp_AvatarPose_eAvatar
.assert eAvatar::Hidden = 0, error
beq _Done
;; Special case: for eAvatar::Swimming1, automatically animate between
;; Swimming1 and Swimming2.
cpx #eAvatar::Swimming1
bne @drawPose
lda Zp_FrameCounter_u8
and #$10
bne @drawPose
ldx #eAvatar::Swimming2
@drawPose:
;; Draw objects for the player avatar.
txa ; eAvatar value
mul #4
tax
tax ; byte index into _Tiles_u8_arr4_arr
lda Zp_AvatarFlags_bObj ; param: object flags
jsr FuncA_Objects_Alloc2x2Shape ; preserves X, returns C and Y
bcs _Done
Expand Down
23 changes: 2 additions & 21 deletions src/cutscene.asm
Original file line number Diff line number Diff line change
Expand Up @@ -918,17 +918,7 @@ _MoveByYA:
;;; @preserve X, Y, T0+
.PROC FuncA_Cutscene_AnimateAvatarSwimming
jsr FuncA_Cutscene_FaceAvatarTowardsN
_AnimatePose:
lda Zp_FrameCounter_u8
and #$10
beq @swim2
@swim1:
lda #eAvatar::Swimming1
.assert eAvatar::Swimming1 > 0, error
bne @setPose ; unconditional
@swim2:
lda #eAvatar::Swimming2
@setPose:
lda #eAvatar::Swimming1 ; animates automatically
sta Zp_AvatarPose_eAvatar
rts
.ENDPROC
Expand Down Expand Up @@ -964,17 +954,8 @@ _AnimatePose:
jsr FuncA_Cutscene_SetActorFlipHFromN ; preserves X, Y and T0+
lda #$ff
sta Ram_ActorState2_byte_arr, x
_AnimatePose:
lda Zp_FrameCounter_u8
and #$10
beq @swim2
@swim1:
;; Set pose to AlexSwimming1; this will animate automatically.
lda #eNpcChild::AlexSwimming1
.assert eNpcChild::AlexSwimming1 > 0, error
bne @setState ; unconditional
@swim2:
lda #eNpcChild::AlexSwimming2
@setState:
sta Ram_ActorState1_byte_arr, x
rts
.ENDPROC
Expand Down
33 changes: 1 addition & 32 deletions src/dialog.asm
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ _GameLoop:
jsr_prga FuncA_Objects_DrawDialogCursorAndObjectsForRoom
jsr Func_ClearRestOfOamAndProcessFrame
_Tick:
jsr_prga FuncA_Dialog_TickAvatarAndText ; returns C, Z, T2, and T1T0
jsr_prga FuncA_Dialog_TickText ; returns C, Z, T2, and T1T0
bcs Main_Dialog_CloseWindow
beq @done
jsr FuncM_CopyDialogText
Expand Down Expand Up @@ -698,35 +698,6 @@ _Done:
rts
.ENDPROC

;;; Animates the player avatar as needed during dialog. In particular, if the
;;; avatar is swimming, updates the swimming animation.
.PROC FuncA_Dialog_TickAvatar
bit Zp_AvatarState_bAvatar
.assert bAvatar::Swimming = bProc::Overflow, error
bvc _Return ; player avatar is not swimming
_SetSwimmingPose:
ldy #eAvatar::Swimming2
lda Zp_FrameCounter_u8
and #$10
bne @setAvatarPose
@swimming1:
ldy #eAvatar::Swimming1
@setAvatarPose:
sty Zp_AvatarPose_eAvatar
_Return:
rts
.ENDPROC

;;; Calls FuncA_Dialog_TickAvatar and then FuncA_Dialog_TickText.
;;; @return C Set if dialog is finished and the window should be closed.
;;; @return Z Cleared if we should copy the next pane of dialog text.
;;; @return T2 The PRGA bank number that contains the next dialog text.
;;; @return T1T0 A pointer to the start of the next dialog text.
.PROC FuncA_Dialog_TickAvatarAndText
jsr FuncA_Dialog_TickAvatar
fall FuncA_Dialog_TickText ; returns C, Z, T2, and T1T0
.ENDPROC

;;; Updates the dialog text based on joypad input and animates the dialog
;;; portrait appropriately. The return values indicate whether dialog should
;;; end or continue, and whether it's time to copy the next pane of dialog
Expand Down Expand Up @@ -927,7 +898,6 @@ _UpdateDialogPointer:
;;; is closing.
;;; @return C Set if the window is now fully scrolled out.
.PROC FuncA_Dialog_ScrollWindowDown
jsr FuncA_Dialog_TickAvatar
_ScrollWindow:
lda Zp_WindowTop_u8
add #kDialogWindowScrollSpeed
Expand Down Expand Up @@ -955,7 +925,6 @@ _FullyClosed:
;;; this each frame when the window is opening.
;;; @return C Set if the window is now fully scrolled in.
.PROC FuncA_Dialog_ScrollWindowUp
jsr FuncA_Dialog_TickAvatar
_AdjustAvatarHorz:
;; Only adjust the player avatar's position if this dialog was started by
;; using a device, rather than from a cutscene.
Expand Down

0 comments on commit 0a716c7

Please sign in to comment.