Skip to content

Commit

Permalink
Factor out FuncA_Actor_FaceOppositeDir function
Browse files Browse the repository at this point in the history
  • Loading branch information
mdsteele committed Oct 12, 2024
1 parent 6414d56 commit c8fecc9
Show file tree
Hide file tree
Showing 12 changed files with 35 additions and 46 deletions.
6 changes: 2 additions & 4 deletions src/actors/bird.asm
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
.INCLUDE "../ppu.inc"
.INCLUDE "bird.inc"

.IMPORT FuncA_Actor_FaceOppositeDir
.IMPORT FuncA_Actor_HarmAvatarIfCollision
.IMPORT FuncA_Actor_SetPointInFrontOfActor
.IMPORT FuncA_Actor_SetVelXForward
Expand Down Expand Up @@ -109,10 +110,7 @@ _Moving:
bcc _Done
_LandOnWall:
jsr FuncA_Actor_ZeroVelX ; preserves X
;; Make the bird face the opposite direction.
lda Ram_ActorFlags_bObj_arr, x
eor #bObj::FlipH
sta Ram_ActorFlags_bObj_arr, x
jsr FuncA_Actor_FaceOppositeDir ; preserves X
;; Adjust position to be on the wall.
lda #0
sta Ram_ActorSubX_u8_arr, x
Expand Down
5 changes: 2 additions & 3 deletions src/actors/crab.asm
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
.INCLUDE "../tileset.inc"
.INCLUDE "crab.inc"

.IMPORT FuncA_Actor_FaceOppositeDir
.IMPORT FuncA_Actor_HarmAvatarIfCollision
.IMPORT FuncA_Actor_SetPointInFrontOfActor
.IMPORT FuncA_Objects_Draw2x2Actor
Expand Down Expand Up @@ -94,9 +95,7 @@ _StartMove:
bne @continueForward
;; Make the crab face the opposite direction.
@turnAround:
lda Ram_ActorFlags_bObj_arr, x
eor #bObj::FlipH
sta Ram_ActorFlags_bObj_arr, x
jsr FuncA_Actor_FaceOppositeDir ; preserves X
;; Start a new movement cycle for the crab.
@continueForward:
lda #$1f
Expand Down
6 changes: 2 additions & 4 deletions src/actors/duck.asm
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
.INCLUDE "../oam.inc"
.INCLUDE "duck.inc"

.IMPORT FuncA_Actor_FaceOppositeDir
.IMPORT FuncA_Actor_FaceTowardsPoint
.IMPORT FuncA_Actor_SetPointInFrontOfActor
.IMPORT FuncA_Actor_SetPointToOtherActorCenter
Expand All @@ -30,7 +31,6 @@
.IMPORT FuncA_Objects_Draw1x1Actor
.IMPORT Func_GetRandomByte
.IMPORT Func_PointHitsTerrain
.IMPORT Ram_ActorFlags_bObj_arr
.IMPORT Ram_ActorPosX_i16_0_arr
.IMPORT Ram_ActorPosX_i16_1_arr
.IMPORT Ram_ActorState1_byte_arr
Expand Down Expand Up @@ -130,9 +130,7 @@ _MaybeTurnAround:
mod #4
bne _PickNewSpeed ; do not turn around
_DoTurnAround:
lda Ram_ActorFlags_bObj_arr, x
eor #bObj::FlipH
sta Ram_ActorFlags_bObj_arr, x
jsr FuncA_Actor_FaceOppositeDir ; preserves X
_PickNewSpeed:
;; Wander for a random amount of time between about 1-2 seconds.
jsr Func_GetRandomByte ; preserves X, returns A
Expand Down
8 changes: 2 additions & 6 deletions src/actors/fish.asm
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@
.INCLUDE "../oam.inc"
.INCLUDE "fish.inc"

.IMPORT FuncA_Actor_FaceOppositeDir
.IMPORT FuncA_Actor_HarmAvatarIfCollision
.IMPORT FuncA_Actor_SetPointInFrontOfActor
.IMPORT FuncA_Actor_SetVelXForward
.IMPORT FuncA_Objects_Draw2x2Actor
.IMPORT Func_PointHitsTerrain
.IMPORT Ram_ActorFlags_bObj_arr
.IMPORT Ram_ActorState1_byte_arr

;;;=========================================================================;;;
Expand Down Expand Up @@ -55,11 +55,7 @@ kPaletteObjFish = 0
jsr FuncA_Actor_SetPointInFrontOfActor ; preserves X
jsr Func_PointHitsTerrain ; preserves X, returns C
bcc @continueForward
;; Make the fish face the opposite direction.
@turnAround:
lda Ram_ActorFlags_bObj_arr, x
eor #bObj::FlipH
sta Ram_ActorFlags_bObj_arr, x
jsr FuncA_Actor_FaceOppositeDir ; preserves X
@continueForward:
_SetVelocity:
ldya #kFishSpeed ; param: speed
Expand Down
7 changes: 2 additions & 5 deletions src/actors/flydrop.asm
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
.INCLUDE "../oam.inc"
.INCLUDE "flydrop.inc"

.IMPORT FuncA_Actor_FaceOppositeDir
.IMPORT FuncA_Actor_FaceTowardsAvatar
.IMPORT FuncA_Actor_HarmAvatarIfCollision
.IMPORT FuncA_Actor_IsAvatarAboveOrBelow
Expand All @@ -36,7 +37,6 @@
.IMPORT Func_MovePointDownByA
.IMPORT Func_PointHitsTerrain
.IMPORT Func_SetActorCenterToPoint
.IMPORT Ram_ActorFlags_bObj_arr
.IMPORT Ram_ActorState1_byte_arr
.IMPORT Ram_ActorState2_byte_arr
.IMPORT Ram_ActorVelX_i16_0_arr
Expand Down Expand Up @@ -163,10 +163,7 @@ _TurnRandomly:
jsr FuncA_Actor_FaceTowardsAvatar ; preserves X
jmp _SetVelocity
_TurnAround:
;; Make the flydrop face the opposite direction.
lda Ram_ActorFlags_bObj_arr, x
eor #bObj::FlipH
sta Ram_ActorFlags_bObj_arr, x
jsr FuncA_Actor_FaceOppositeDir ; preserves X
lda #kFlydropRandomTurnCooldownFrames
sta Ram_ActorState2_byte_arr, x ; random turn cooldown
_SetVelocity:
Expand Down
5 changes: 2 additions & 3 deletions src/actors/grub.asm
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
.INCLUDE "../tileset.inc"
.INCLUDE "grub.inc"

.IMPORT FuncA_Actor_FaceOppositeDir
.IMPORT FuncA_Actor_FaceTowardsAvatar
.IMPORT FuncA_Actor_HarmAvatarIfCollision
.IMPORT FuncA_Actor_IsAvatarWithinVertDistances
Expand Down Expand Up @@ -180,9 +181,7 @@ _StartMove:
bge @continueForward
;; Make the grub face the opposite direction.
@turnAround:
lda Ram_ActorFlags_bObj_arr, x
eor #bObj::FlipH
sta Ram_ActorFlags_bObj_arr, x
jsr FuncA_Actor_FaceOppositeDir ; preserves X
;; Start a new movement cycle for the grub.
@continueForward:
lda #$1f
Expand Down
9 changes: 3 additions & 6 deletions src/actors/rhino.asm
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
.INCLUDE "../tileset.inc"
.INCLUDE "rhino.inc"

.IMPORT FuncA_Actor_FaceOppositeDir
.IMPORT FuncA_Actor_HarmAvatarIfCollision
.IMPORT FuncA_Actor_IsAvatarWithinHorzDistance
.IMPORT FuncA_Actor_IsAvatarWithinVertDistances
Expand Down Expand Up @@ -130,9 +131,7 @@ kPaletteObjRhino = 0
;; Check if the terrain forces the rhino to turn around.
jsr FuncA_Actor_MustRhinoTurn ; preserves X, returns C
bcc @noTerrainTurn
lda Ram_ActorFlags_bObj_arr, x
eor #bObj::FlipH
sta Ram_ActorFlags_bObj_arr, x
jsr FuncA_Actor_FaceOppositeDir ; preserves X
@noTerrainTurn:
;; Check if the player avatar is nearby.
ldy #kRhinoVertProximity ; param: distance below avatar
Expand All @@ -152,9 +151,7 @@ _NotFacingAvatar:
lda #kRhinoSneakDistance ; param: distance
jsr FuncA_Actor_IsAvatarWithinHorzDistance ; preserves X, returns C
bcc _SetVelocity
lda Ram_ActorFlags_bObj_arr, x
eor #bObj::FlipH
sta Ram_ActorFlags_bObj_arr, x
jsr FuncA_Actor_FaceOppositeDir ; preserves X
lda #kRhinoAngeredBehindFrames
_BecomeAngered:
sta Ram_ActorState2_byte_arr, x ; mode timer
Expand Down
12 changes: 12 additions & 0 deletions src/actors/shared.asm
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,18 @@ _NotInRoom:
rts
.ENDPROC

;;; Toggles the actor's bObj::FlipH bit.
;;; @param X The actor index.
;;; @return A The new bObj value that was set for the actor.
;;; @preserve X, Y, T0+
.EXPORT FuncA_Actor_FaceOppositeDir
.PROC FuncA_Actor_FaceOppositeDir
lda Ram_ActorFlags_bObj_arr, x
eor #bObj::FlipH
sta Ram_ActorFlags_bObj_arr, x
rts
.ENDPROC

;;; Sets or clears bObj::FlipH in the actor's flags so as to face the actor
;;; horizontally towards the direction of the actor's X-velocity.
;;; @param X The actor index.
Expand Down
6 changes: 2 additions & 4 deletions src/actors/slime.asm
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
.INCLUDE "slime.inc"
.INCLUDE "spike.inc"

.IMPORT FuncA_Actor_FaceOppositeDir
.IMPORT FuncA_Actor_HarmAvatarIfCollision
.IMPORT FuncA_Actor_IsAvatarAboveOrBelow
.IMPORT FuncA_Actor_IsAvatarWithinHorzDistance
Expand All @@ -42,7 +43,6 @@
.IMPORT Func_PointHitsTerrain
.IMPORT Func_SetActorCenterToPoint
.IMPORT Func_SetPointToActorCenter
.IMPORT Ram_ActorFlags_bObj_arr
.IMPORT Ram_ActorState1_byte_arr
.IMPORT Ram_ActorState2_byte_arr
.IMPORT Ram_ActorVelY_i16_1_arr
Expand Down Expand Up @@ -95,9 +95,7 @@ _Move:
bge @continueForward
;; Make the slime face the opposite direction.
@turnAround:
lda Ram_ActorFlags_bObj_arr, x
eor #bObj::FlipH
sta Ram_ActorFlags_bObj_arr, x
jsr FuncA_Actor_FaceOppositeDir ; preserves X
;; Set the slime's velocity.
@continueForward:
lda Ram_ActorState2_byte_arr, x ; animation timer
Expand Down
7 changes: 2 additions & 5 deletions src/actors/solifuge.asm
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
.IMPORT FuncA_Actor_ApplyGravity
.IMPORT FuncA_Actor_CenterHitsTerrainOrSolidPlatform
.IMPORT FuncA_Actor_ClampVelX
.IMPORT FuncA_Actor_FaceOppositeDir
.IMPORT FuncA_Actor_FaceTowardsAvatar
.IMPORT FuncA_Actor_GetRoomBlockRow
.IMPORT FuncA_Actor_HarmAvatarIfCollision
Expand All @@ -43,7 +44,6 @@
.IMPORT Func_InitActorDefault
.IMPORT Func_InitActorSmokeExplosion
.IMPORT Func_SetPointToActorCenter
.IMPORT Ram_ActorFlags_bObj_arr
.IMPORT Ram_ActorPosY_i16_0_arr
.IMPORT Ram_ActorPosY_i16_1_arr
.IMPORT Ram_ActorState1_byte_arr
Expand Down Expand Up @@ -192,10 +192,7 @@ _StopIfBlockedHorz:
bge @done ; floor is solid
@blocked:
jsr FuncA_Actor_ZeroVelX ; preserves X
;; TODO: factor this out into a shared actor function
lda Ram_ActorFlags_bObj_arr, x
eor #bObj::FlipH
sta Ram_ActorFlags_bObj_arr, x
jmp FuncA_Actor_FaceOppositeDir ; preserves X
@done:
rts
.ENDPROC
Expand Down
5 changes: 2 additions & 3 deletions src/actors/spider.asm
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
.INCLUDE "../tileset.inc"
.INCLUDE "spider.inc"

.IMPORT FuncA_Actor_FaceOppositeDir
.IMPORT FuncA_Actor_HarmAvatarIfCollision
.IMPORT FuncA_Actor_IsAvatarAboveOrBelow
.IMPORT FuncA_Actor_IsAvatarWithinHorzDistance
Expand Down Expand Up @@ -179,9 +180,7 @@ _StartNewMovementCycle:
bne @continueForward
;; Make the spider face the opposite direction.
@turnAround:
lda Ram_ActorFlags_bObj_arr, x
eor #bObj::FlipH
sta Ram_ActorFlags_bObj_arr, x
jsr FuncA_Actor_FaceOppositeDir ; preserves X
@continueForward:
_SetVelocityForMove:
ldya #kSpiderMoveSpeed * $100 ; param: speed
Expand Down
5 changes: 2 additions & 3 deletions src/actors/toddler.asm
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
.INCLUDE "../oam.inc"
.INCLUDE "toddler.inc"

.IMPORT FuncA_Actor_FaceOppositeDir
.IMPORT FuncA_Objects_Draw1x2Actor
.IMPORT Func_InitActorWithState1
.IMPORT Ram_ActorFlags_bObj_arr
Expand Down Expand Up @@ -73,9 +74,7 @@ kToddlerTime = 64
dec Ram_ActorState1_byte_arr, x
bne @move
@turnAround:
lda Ram_ActorFlags_bObj_arr, x
eor #bObj::FlipH
sta Ram_ActorFlags_bObj_arr, x
jsr FuncA_Actor_FaceOppositeDir ; preserves X
lda #kToddlerTime
sta Ram_ActorState1_byte_arr, x
@move:
Expand Down

0 comments on commit c8fecc9

Please sign in to comment.