Skip to content

Commit

Permalink
Add alarm sound effect to ShadowHall and ShadowTrap rooms
Browse files Browse the repository at this point in the history
  • Loading branch information
mdsteele committed Jun 22, 2024
1 parent 3fe0b7f commit 85f1d17
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 14 deletions.
2 changes: 2 additions & 0 deletions src/rooms/shadow_hall.asm
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
.IMPORT FuncA_Machine_MinigunTryAct
.IMPORT FuncA_Machine_ReachedGoal
.IMPORT FuncA_Objects_DrawMinigunRightMachine
.IMPORT FuncA_Room_PlaySfxAlarm
.IMPORT FuncA_Room_PlaySfxCrack
.IMPORT FuncA_Room_TurnProjectilesToSmokeIfConsoleOpen
.IMPORT FuncC_Shadow_DrawGlassPlatform
Expand Down Expand Up @@ -388,6 +389,7 @@ _InitProgram:
ldx #eFlag::ShadowHallInitialized ; param: flag
jsr Func_SetFlag ; returns C
bcs @done
jsr FuncA_Room_PlaySfxAlarm
ldx #.sizeof(DataA_Room_ShadowHallMinigun_sIns_arr) - 1
;; Enable writes to SRAM.
ldy #bMmc3PrgRam::Enable
Expand Down
39 changes: 25 additions & 14 deletions src/rooms/shadow_trap.asm
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
.IMPORT FuncA_Room_InitActorBadFlydrop
.IMPORT FuncA_Room_IsPointInLaserBeam
.IMPORT FuncA_Room_MachineLaserReset
.IMPORT FuncA_Room_PlaySfxAlarm
.IMPORT FuncC_Shadow_DrawBarrierPlatform
.IMPORT Func_FindEmptyActorSlot
.IMPORT Func_InitActorSmokeExplosion
Expand Down Expand Up @@ -124,8 +125,10 @@ kLaserInitPlatformLeft = \

;;; Defines room-specific state data for this particular room.
.STRUCT sState
;; True ($ff) if the baddies have been spawned, false ($00) otherwise.
SpawnedBaddies_bool .byte
;; If the alarm is waiting to be tripped, this will have the high bit set;
;; otherwise, the bottom seven bits hold the number of frames until the
;; baddies should spawn.
AlarmCountdown_u8 .byte
.ENDSTRUCT
.ASSERT .sizeof(sState) <= kRoomStateSize, error

Expand Down Expand Up @@ -312,9 +315,12 @@ _FixGravity:
sbc Zp_AvatarPosY_i16 + 1
sta Zp_AvatarPosY_i16 + 1
@done:
_MaybeMarkSafe:
_InitAlarm:
flag_bit Sram_ProgressFlags_arr, eFlag::ShadowTrapDisarmed
jne Func_MarkRoomSafe
;; Mark the alarm as not yet tripped.
lda #$ff
sta Zp_RoomState + sState::AlarmCountdown_u8
rts
.ENDPROC

Expand All @@ -325,8 +331,9 @@ _MaybeMarkSafe:
_CheckTrap:
flag_bit Sram_ProgressFlags_arr, eFlag::ShadowTrapDisarmed
bne _OpenBarriers
bit Zp_RoomState + sState::SpawnedBaddies_bool
bpl _MaybeSpawnBaddies
lda Zp_RoomState + sState::AlarmCountdown_u8
bmi _MaybeTripAlarm
bne _MaybeSpawnBaddies
_CheckIfBaddiesZapped:
;; Kill any spawned baddies that get hit by the laser beam.
lda #0
Expand Down Expand Up @@ -355,26 +362,30 @@ _CheckIfBaddiesDefeated:
jsr Func_SetFlag
jsr Func_MarkRoomSafe
jmp _OpenBarriers
_MaybeSpawnBaddies:
;; If the player avatar isn't in the trap zone, don't spawn baddies yet.
_MaybeTripAlarm:
;; If the player avatar isn't in the trap zone, don't trip the alarm.
jsr Func_SetPointToAvatarCenter
ldy #kTrapZonePlatformIndex ; param: platform index
jsr Func_IsPointInPlatform ; returns C
bcc @done
bcc _CheckBarriers
;; Trip the alarm.
jsr FuncA_Room_PlaySfxAlarm
lda #40
sta Zp_RoomState + sState::AlarmCountdown_u8
bne _CheckBarriers ; unconditional
_MaybeSpawnBaddies:
dec Zp_RoomState + sState::AlarmCountdown_u8
bne _CheckBarriers
;; Spawn the baddies.
ldy #kTrapSpawnEastPlatformIndex ; param: platform index
lda #bObj::FlipH ; param: flags
jsr FuncA_Room_ShadowTrap_SpawnBaddie
ldy #kTrapSpawnWestPlatformIndex ; param: platform index
lda #0 ; param: flags
jsr FuncA_Room_ShadowTrap_SpawnBaddie
;; TODO: play an alarm sound
lda #$ff
sta Zp_RoomState + sState::SpawnedBaddies_bool
@done:
_CheckBarriers:
bit Zp_RoomState + sState::SpawnedBaddies_bool
bpl _OpenBarriers
bit Zp_RoomState + sState::AlarmCountdown_u8
bmi _OpenBarriers
_ShutBarriers:
ldax #kBarrierShutTop
stax Zp_PointY_i16
Expand Down
60 changes: 60 additions & 0 deletions src/sounds/alarm.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
;;;=========================================================================;;;
;;; Copyright 2022 Matthew D. Steele <[email protected]> ;;;
;;; ;;;
;;; This file is part of Annalog. ;;;
;;; ;;;
;;; Annalog is free software: you can redistribute it and/or modify it ;;;
;;; under the terms of the GNU General Public License as published by the ;;;
;;; Free Software Foundation, either version 3 of the License, or (at your ;;;
;;; option) any later version. ;;;
;;; ;;;
;;; Annalog is distributed in the hope that it will be useful, but WITHOUT ;;;
;;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or ;;;
;;; FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License ;;;
;;; for more details. ;;;
;;; ;;;
;;; You should have received a copy of the GNU General Public License along ;;;
;;; with Annalog. If not, see <http://www.gnu.org/licenses/>. ;;;
;;;=========================================================================;;;

.INCLUDE "../apu.inc"
.INCLUDE "../audio.inc"
.INCLUDE "../macros.inc"
.INCLUDE "../sound.inc"

.IMPORT Func_PlaySfxSequence

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

.SEGMENT "PRG8"

;;; SFX sequence data for the "alarm" sound effect.
.PROC Data_Alarm_sSfxSeq_arr
.linecont +
.repeat 3
D_STRUCT sSfxSeq
d_byte Duration_u8, 28
d_byte Env_bEnvelope, \
bEnvelope::Duty14 | bEnvelope::NoLength | bEnvelope::ConstVol | 12
d_byte Sweep_byte, pulse_sweep -2, 0
d_word Timer_u16, $0120
D_END
.endrepeat
.byte 0
.linecont -
.ENDPROC

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

.SEGMENT "PRGA_Room"

;;; Starts playing the sound for when an alarm goes off in the Shadow Labs.
;;; @preserve X, T0+
.EXPORT FuncA_Room_PlaySfxAlarm
.PROC FuncA_Room_PlaySfxAlarm
ldx #eChan::Pulse2
ldya #Data_Alarm_sSfxSeq_arr
jmp Func_PlaySfxSequence ; preserves T0+
.ENDPROC

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

0 comments on commit 85f1d17

Please sign in to comment.