Skip to content

Commit

Permalink
Remove projectiles that leave the room bounds
Browse files Browse the repository at this point in the history
  • Loading branch information
mdsteele committed Mar 8, 2024
1 parent 65cb648 commit 9555b79
Show file tree
Hide file tree
Showing 7 changed files with 100 additions and 11 deletions.
3 changes: 3 additions & 0 deletions src/actors/bullet.asm
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

.IMPORT FuncA_Actor_CenterHitsTerrain
.IMPORT FuncA_Actor_HarmAvatarIfCollision
.IMPORT FuncA_Actor_IsInRoomBounds
.IMPORT FuncA_Objects_Draw1x1Actor
.IMPORT FuncA_Room_TurnProjectilesToSmoke
.IMPORT Func_InitActorDefault
Expand Down Expand Up @@ -96,6 +97,8 @@ _VelY_i8_arr:
beq _Expire
jsr FuncA_Actor_HarmAvatarIfCollision ; preserves X, returns C
bcs _Expire
jsr FuncA_Actor_IsInRoomBounds ; preserves X, returns C
bcc _Expire
jsr FuncA_Actor_CenterHitsTerrain ; preserves X, returns C
bcc _Done
_Expire:
Expand Down
18 changes: 12 additions & 6 deletions src/actors/ember.asm
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@
.INCLUDE "ember.inc"

.IMPORT FuncA_Actor_ApplyGravityWithTerminalVelocity
.IMPORT FuncA_Actor_CenterHitsTerrain
.IMPORT FuncA_Actor_CenterHitsTerrainOrSolidPlatform
.IMPORT FuncA_Actor_HarmAvatarIfCollision
.IMPORT FuncA_Actor_IsInRoomBounds
.IMPORT FuncA_Objects_Draw1x1Actor
.IMPORT Func_InitActorDefault
.IMPORT Ram_ActorFlags_bObj_arr
Expand Down Expand Up @@ -64,11 +65,13 @@ kPaletteObjEmber = 1
.EXPORT FuncA_Actor_TickProjEmber
.PROC FuncA_Actor_TickProjEmber
inc Ram_ActorState1_byte_arr, x
beq _Expire
beq _TurnToSmoke
jsr FuncA_Actor_HarmAvatarIfCollision ; preserves X, returns C
bcs _Expire
jsr FuncA_Actor_CenterHitsTerrain ; preserves X, returns C
bcs _Expire
bcs _TurnToSmoke
jsr FuncA_Actor_IsInRoomBounds ; preserves X, returns C
bcc _Remove
jsr FuncA_Actor_CenterHitsTerrainOrSolidPlatform ; preserves X, returns C
bcs _TurnToSmoke
_FlipHorz:
lda Ram_ActorState1_byte_arr, x
mul #16
Expand All @@ -77,7 +80,10 @@ _FlipHorz:
_ApplyGravity:
lda #kEmberTerminalVelocity ; param: terminal velocity
jmp FuncA_Actor_ApplyGravityWithTerminalVelocity ; preserves X
_Expire:
_TurnToSmoke:
ldy #eActor::SmokeParticle ; param: actor type
jmp Func_InitActorDefault ; preserves X
_Remove:
lda #eActor::None
sta Ram_ActorType_eActor_arr, x
rts
Expand Down
26 changes: 21 additions & 5 deletions src/actors/fireball.asm
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,15 @@
.IMPORT FuncA_Actor_CenterHitsTerrain
.IMPORT FuncA_Actor_CenterHitsTerrainOrSolidPlatform
.IMPORT FuncA_Actor_HarmAvatarIfCollision
.IMPORT FuncA_Actor_IsInRoomBounds
.IMPORT FuncA_Objects_Draw1x1Actor
.IMPORT Func_InitActorDefault
.IMPORT Func_InitActorWithState1
.IMPORT Func_SetActorVelocityPolar
.IMPORT Ram_ActorState1_byte_arr
.IMPORT Ram_ActorState2_byte_arr
.IMPORT Ram_ActorState3_byte_arr
.IMPORT Ram_ActorType_eActor_arr
.IMPORTZP Zp_FrameCounter_u8

;;;=========================================================================;;;
Expand Down Expand Up @@ -101,11 +103,13 @@ kPaletteObjFireblast = 1
.PROC FuncA_Actor_TickProjFireball
_IncrementAge:
inc Ram_ActorState2_byte_arr, x ; projectile age in frames
beq FuncA_Actor_ExpireProjFireballOrFireblast
beq FuncA_Actor_ExpireProjFireballOrFireblast ; preserves X
_HandleCollision:
jsr FuncA_Actor_HarmAvatarIfCollision ; preserves X
jsr FuncA_Actor_IsInRoomBounds ; preserves X, returns C
bcc FuncA_Actor_RemoveProjFireballOrFireblast ; preserves X
jsr FuncA_Actor_CenterHitsTerrain ; preserves X, returns C
bcs FuncA_Actor_ExpireProjFireballOrFireblast
bcs FuncA_Actor_ExpireProjFireballOrFireblast ; preserves X
rts
.ENDPROC

Expand All @@ -116,17 +120,19 @@ _HandleCollision:
.PROC FuncA_Actor_TickProjFireblast
_IncrementAge:
inc Ram_ActorState2_byte_arr, x ; projectile age in frames
beq FuncA_Actor_ExpireProjFireballOrFireblast
beq FuncA_Actor_ExpireProjFireballOrFireblast ; preserves X
_DecrementReflectionTimer:
lda Ram_ActorState3_byte_arr, x ; reflection timer
beq @done
dec Ram_ActorState3_byte_arr, x ; reflection timer
@done:
_HandleCollision:
jsr FuncA_Actor_HarmAvatarIfCollision ; preserves X, returns C
bcs FuncA_Actor_ExpireProjFireballOrFireblast
bcs FuncA_Actor_ExpireProjFireballOrFireblast ; preserves X
jsr FuncA_Actor_IsInRoomBounds ; preserves X, returns C
bcc FuncA_Actor_RemoveProjFireballOrFireblast ; preserves X
jsr FuncA_Actor_CenterHitsTerrainOrSolidPlatform ; preserves X, returns C
bcs FuncA_Actor_ExpireProjFireballOrFireblast
bcs FuncA_Actor_ExpireProjFireballOrFireblast ; preserves X
rts
.ENDPROC

Expand All @@ -139,6 +145,16 @@ _HandleCollision:
jmp Func_InitActorDefault ; preserves X
.ENDPROC

;;; Removes a fireball or fireblast projectile without creating a smoke
;;; particle.
;;; @param X The actor index.
;;; @preserve X
.PROC FuncA_Actor_RemoveProjFireballOrFireblast
lda #eActor::None
sta Ram_ActorType_eActor_arr, x
rts
.ENDPROC

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

.SEGMENT "PRGA_Objects"
Expand Down
8 changes: 8 additions & 0 deletions src/actors/grenade.asm
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
.IMPORT FuncA_Actor_ApplyGravity
.IMPORT FuncA_Actor_CenterHitsTerrain
.IMPORT FuncA_Actor_HarmAvatarIfCollision
.IMPORT FuncA_Actor_IsInRoomBounds
.IMPORT FuncA_Objects_Draw1x1Actor
.IMPORT Func_FindActorWithType
.IMPORT Func_InitActorDefault
Expand All @@ -35,6 +36,7 @@
.IMPORT Ram_ActorPosY_i16_0_arr
.IMPORT Ram_ActorPosY_i16_1_arr
.IMPORT Ram_ActorState1_byte_arr
.IMPORT Ram_ActorType_eActor_arr
.IMPORT Ram_ActorVelX_i16_1_arr
.IMPORT Ram_ActorVelY_i16_0_arr
.IMPORT Ram_ActorVelY_i16_1_arr
Expand Down Expand Up @@ -131,6 +133,8 @@ _InitVelY_i16_1_arr:
beq _Explode
jsr FuncA_Actor_HarmAvatarIfCollision ; preserves X, returns C
bcs _Explode
jsr FuncA_Actor_IsInRoomBounds ; preserves X, returns C
bcc _Remove
jsr FuncA_Actor_CenterHitsTerrain ; preserves X, returns C
bcs _ShakeAndExplode
jmp FuncA_Actor_ApplyGravity ; preserves X
Expand All @@ -140,6 +144,10 @@ _ShakeAndExplode:
_Explode:
jsr Func_PlaySfxExplodeSmall ; preserves X
jmp Func_InitActorSmokeExplosion ; preserves X
_Remove:
lda #eActor::None
sta Ram_ActorType_eActor_arr, x
rts
.ENDPROC

;;;=========================================================================;;;
Expand Down
50 changes: 50 additions & 0 deletions src/actors/shared.asm
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
.INCLUDE "../oam.inc"
.INCLUDE "../ppu.inc"
.INCLUDE "../program.inc"
.INCLUDE "../room.inc"

.IMPORT FuncA_Actor_IsCollidingWithAvatar
.IMPORT FuncA_Objects_Draw1x1Shape
Expand Down Expand Up @@ -63,6 +64,7 @@
.IMPORTZP Zp_AvatarFlags_bObj
.IMPORTZP Zp_AvatarPosX_i16
.IMPORTZP Zp_AvatarPosY_i16
.IMPORTZP Zp_Current_sRoom
.IMPORTZP Zp_FrameCounter_u8
.IMPORTZP Zp_PointX_i16
.IMPORTZP Zp_PointY_i16
Expand Down Expand Up @@ -167,6 +169,54 @@ _Atan2:
rts
.ENDPROC

;;; Checks if the center of the actor is within the bounds of the room.
;;; @param X The actor index.
;;; @return C Set if the actor is within the room bounds, cleared otherwise.
;;; @preserve X
.EXPORT FuncA_Actor_IsInRoomBounds
.PROC FuncA_Actor_IsInRoomBounds
_CheckVert:
bit Zp_Current_sRoom + sRoom::Flags_bRoom
.assert bRoom::Tall = bProc::Overflow, error
bvs @tall
@short:
lda #kScreenHeightPx
ldy #0
beq @finishHeight ; unconditional
@tall:
ldya #kTallRoomHeightBlocks * kBlockHeightPx
@finishHeight:
stya T1T0 ; room height in pixels
lda Ram_ActorPosY_i16_0_arr, x
cmp T0 ; room height in pixels (lo)
lda Ram_ActorPosY_i16_1_arr, x
bmi _NotInRoom ; actor is above the top of the room
sbc T1 ; room height in pixels (hi)
bge _NotInRoom ; actor is below the bottom of the room
_CheckHorz:
ldy Zp_Current_sRoom + sRoom::MaxScrollX_u16 + 1
.assert kScreenWidthPx = $100, error
iny
sty T0 ; room right side (hi)
lda Ram_ActorPosX_i16_0_arr, x
ldy Ram_ActorPosX_i16_1_arr, x
bmi _NotInRoom
bne @checkRightSide
cmp Zp_Current_sRoom + sRoom::MinScrollX_u8
blt _NotInRoom
@checkRightSide:
cmp Zp_Current_sRoom + sRoom::MaxScrollX_u16 + 0 ; room right side (lo)
tya ; actor pos X (hi)
sbc T0 ; room right side (hi)
bge _NotInRoom
_IsInRoom:
sec
rts
_NotInRoom:
clc
rts
.ENDPROC

;;; Determines if the actor is facing left/right toward the player avatar.
;;; @param X The actor index.
;;; @return C Set if the actor is facing the player avatar, cleared if not.
Expand Down
3 changes: 3 additions & 0 deletions src/actors/spike.asm
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
.IMPORT FuncA_Actor_ApplyGravityWithTerminalVelocity
.IMPORT FuncA_Actor_CenterHitsTerrain
.IMPORT FuncA_Actor_HarmAvatarIfCollision
.IMPORT FuncA_Actor_IsInRoomBounds
.IMPORT FuncA_Objects_Draw1x1Actor
.IMPORT Func_InitActorDefault
.IMPORT Ram_ActorState1_byte_arr
Expand Down Expand Up @@ -62,6 +63,8 @@ kSpikeTerminalVelocity = 6
beq _Expire
jsr FuncA_Actor_HarmAvatarIfCollision ; preserves X, returns C
bcs _Expire
jsr FuncA_Actor_IsInRoomBounds ; preserves X, returns C
bcc _Expire
jsr FuncA_Actor_CenterHitsTerrain ; preserves X, returns C
bcs _Expire
lda #kSpikeTerminalVelocity ; param: terminal velocity
Expand Down
3 changes: 3 additions & 0 deletions src/actors/spine.asm
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

.IMPORT FuncA_Actor_CenterHitsTerrain
.IMPORT FuncA_Actor_HarmAvatarIfCollision
.IMPORT FuncA_Actor_IsInRoomBounds
.IMPORT FuncA_Objects_Draw1x1Actor
.IMPORT Func_InitActorWithState1
.IMPORT Func_SetActorVelocityPolar
Expand Down Expand Up @@ -84,6 +85,8 @@ _Flags_bObj_arr4:
beq _Expire
jsr FuncA_Actor_HarmAvatarIfCollision ; preserves X, returns C
bcs _Expire
jsr FuncA_Actor_IsInRoomBounds ; preserves X, returns C
bcc _Expire
jsr FuncA_Actor_CenterHitsTerrain ; preserves X, returns C
bcc _Return
_Expire:
Expand Down

0 comments on commit 9555b79

Please sign in to comment.