diff --git a/src/actors/bird.asm b/src/actors/bird.asm index ecbca78..fe11e37 100644 --- a/src/actors/bird.asm +++ b/src/actors/bird.asm @@ -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 @@ -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 diff --git a/src/actors/crab.asm b/src/actors/crab.asm index 7471482..ca4d595 100644 --- a/src/actors/crab.asm +++ b/src/actors/crab.asm @@ -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 @@ -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 diff --git a/src/actors/duck.asm b/src/actors/duck.asm index be90555..e0a048f 100644 --- a/src/actors/duck.asm +++ b/src/actors/duck.asm @@ -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 @@ -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 @@ -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 diff --git a/src/actors/fish.asm b/src/actors/fish.asm index ba4b4ba..008ca60 100644 --- a/src/actors/fish.asm +++ b/src/actors/fish.asm @@ -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 ;;;=========================================================================;;; @@ -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 diff --git a/src/actors/flydrop.asm b/src/actors/flydrop.asm index 1b1c5c1..10d6bc5 100644 --- a/src/actors/flydrop.asm +++ b/src/actors/flydrop.asm @@ -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 @@ -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 @@ -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: diff --git a/src/actors/grub.asm b/src/actors/grub.asm index f120261..60d4ef5 100644 --- a/src/actors/grub.asm +++ b/src/actors/grub.asm @@ -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 @@ -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 diff --git a/src/actors/rhino.asm b/src/actors/rhino.asm index cbb1818..faf6d81 100644 --- a/src/actors/rhino.asm +++ b/src/actors/rhino.asm @@ -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 @@ -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 @@ -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 diff --git a/src/actors/shared.asm b/src/actors/shared.asm index 32a12bf..ccd342b 100644 --- a/src/actors/shared.asm +++ b/src/actors/shared.asm @@ -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. diff --git a/src/actors/slime.asm b/src/actors/slime.asm index 4350da6..932c529 100644 --- a/src/actors/slime.asm +++ b/src/actors/slime.asm @@ -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 @@ -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 @@ -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 diff --git a/src/actors/solifuge.asm b/src/actors/solifuge.asm index 28f6735..f2f330e 100644 --- a/src/actors/solifuge.asm +++ b/src/actors/solifuge.asm @@ -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 @@ -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 @@ -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 diff --git a/src/actors/spider.asm b/src/actors/spider.asm index f9e3cad..45757b3 100644 --- a/src/actors/spider.asm +++ b/src/actors/spider.asm @@ -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 @@ -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 diff --git a/src/actors/toddler.asm b/src/actors/toddler.asm index 58948e7..94908ee 100644 --- a/src/actors/toddler.asm +++ b/src/actors/toddler.asm @@ -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 @@ -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: