Skip to content

Commit

Permalink
Animate player avatar swimming during dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
mdsteele committed Aug 30, 2024
1 parent 6911d01 commit dd778a7
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 10 deletions.
53 changes: 43 additions & 10 deletions src/dialog.asm
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ Ram_DialogText_u8_arr: .res (kDialogTextMaxCols + 1) * kDialogNumTextRows
.EXPORT Main_Dialog_UseDevice
.PROC Main_Dialog_UseDevice
ldy Ram_DeviceTarget_byte_arr, x ; param: eDialog value
.assert * = Main_Dialog_WhileExploring, error, "fallthrough"
fall Main_Dialog_WhileExploring
.ENDPROC

;;; Mode for beginning dialog within a cutscene.
Expand All @@ -334,7 +334,7 @@ Ram_DialogText_u8_arr: .res (kDialogTextMaxCols + 1) * kDialogNumTextRows
.PROC Main_Dialog_WithinCutscene
lda #bDialog::Cutscene
sta Zp_DialogStatus_bDialog
.assert * = Main_Dialog_OpenWindow, error, "fallthrough"
fall Main_Dialog_OpenWindow
.ENDPROC

;;; Mode for scrolling in the dialog window.
Expand All @@ -354,7 +354,8 @@ _UpdateScrolling:
jmp _GameLoop
.ENDPROC

;;; Mode for ending dialog an
;;; Mode for ending dialog and returning to explore or cutscene mode, as
;;; needed.
;;; @prereq Rendering is enabled.
;;; @prereq Explore mode is initialized.
;;; @prereq The dialog window is fully scrolled out.
Expand Down Expand Up @@ -389,7 +390,7 @@ _GameLoop:
jsr_prga FuncA_Objects_DrawDialogCursorAndObjectsForRoom
jsr Func_ClearRestOfOamAndProcessFrame
_Tick:
jsr_prga FuncA_Dialog_Tick ; returns C, Z, T2, and T1T0
jsr_prga FuncA_Dialog_TickAvatarAndText ; returns C, Z, T2, and T1T0
bcs Main_Dialog_CloseWindow
beq @done
jsr FuncM_CopyDialogText
Expand All @@ -412,7 +413,7 @@ _CopyText:
_GameLoop:
jsr_prga FuncA_Objects_DrawDialogCursor
jsr Func_ClearRestOfOamAndProcessFrame
jsr_prga FuncA_Dialog_Tick ; returns C, Z, T2, and T1T0
jsr_prga FuncA_Dialog_TickText ; returns C, Z, T2, and T1T0
bcs _Finish
beq _GameLoop
bne _CopyText ; unconditional
Expand Down Expand Up @@ -697,6 +698,35 @@ _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 All @@ -705,7 +735,7 @@ _Done:
;;; @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_Tick
.PROC FuncA_Dialog_TickText
_CheckDPad:
;; Ignore the D-pad if yes-or-no question mode isn't currently active.
bit Zp_DialogStatus_bDialog
Expand Down Expand Up @@ -897,6 +927,8 @@ _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
cmp #kScreenHeightPx
Expand All @@ -923,7 +955,8 @@ _FullyClosed:
;;; this each frame when the window is opening.
;;; @return C Set if the window is now fully scrolled in.
.PROC FuncA_Dialog_ScrollWindowUp
_AdjustAvatar:
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.
lda Zp_DialogStatus_bDialog
Expand Down Expand Up @@ -1088,7 +1121,7 @@ _Newline:
inc Zp_DialogTextRow_u8
rts
_YesNoQuestion:
.assert * = FuncA_Dialog_BeginYesNoQuestion, error, "fallthrough"
fall FuncA_Dialog_BeginYesNoQuestion
.ENDPROC

;;; Gets dialog ready for a yes-or-no question.
Expand Down Expand Up @@ -1231,7 +1264,7 @@ _EndOfLine:
;;; Draws the dialog cursor/prompt, as well as any objects in the room.
.PROC FuncA_Objects_DrawDialogCursorAndObjectsForRoom
jsr FuncA_Objects_DrawObjectsForRoom
.assert * = FuncA_Objects_DrawDialogCursor, error, "fallthrough"
fall FuncA_Objects_DrawDialogCursor
.ENDPROC

;;; Draws the dialog cursor/prompt.
Expand All @@ -1243,7 +1276,7 @@ _EndOfLine:
@paused:
.assert bDialog::YesNo = bProc::Overflow, error
bvs FuncA_Objects_DrawDialogYesNoCursor
.assert * = FuncA_Objects_DrawDialogButtonPrompt, error, "fallthrough"
fall FuncA_Objects_DrawDialogButtonPrompt
.ENDPROC

;;; Draws the dialog-paused button prompt.
Expand Down
8 changes: 8 additions & 0 deletions src/explore.asm
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,14 @@ _UpDownPassage:
bit Zp_AvatarState_bAvatar
.assert bAvatar::Airborne = bProc::Negative, error
bmi @noneNearby
;; If the player is swimming below the surface of the water, treat them as
;; not near any device.
.assert bAvatar::Swimming = bProc::Overflow, error
bvc @notSwimming
lda Zp_AvatarState_bAvatar
and #bAvatar::DepthMask
bne @noneNearby
@notSwimming:
;; Check if there's a device nearby.
jsr Func_SetPointToAvatarCenter
jsr Func_FindDeviceNearPoint ; returns N and Y
Expand Down

0 comments on commit dd778a7

Please sign in to comment.