Skip to content

Commit

Permalink
Add sound effects for picking up and breaking a flower
Browse files Browse the repository at this point in the history
  • Loading branch information
mdsteele committed Sep 28, 2024
1 parent 42e021f commit 11dad67
Show file tree
Hide file tree
Showing 3 changed files with 131 additions and 7 deletions.
3 changes: 2 additions & 1 deletion src/devices/flower.asm
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
.INCLUDE "../oam.inc"
.INCLUDE "flower.inc"

.IMPORT FuncA_Avatar_PlaySfxPickUpFlower
.IMPORT FuncA_Objects_Draw1x1Shape
.IMPORT FuncA_Objects_MoveShapeDownOneTile
.IMPORT FuncA_Objects_MoveShapeRightHalfTile
Expand Down Expand Up @@ -61,7 +62,7 @@ kFlowerAnimCountdown = 48
;; Remove flower device (for now).
lda #eDevice::Placeholder
sta Ram_DeviceType_eDevice_arr, x
rts
jmp FuncA_Avatar_PlaySfxPickUpFlower
.ENDPROC

;;;=========================================================================;;;
Expand Down
21 changes: 15 additions & 6 deletions src/harm.asm
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
.INCLUDE "oam.inc"
.INCLUDE "sample.inc"

.IMPORT Func_PlaySfxBreakFlower
.IMPORT Func_PlaySfxSample
.IMPORT Ppu_ChrObjAnnaNormal
.IMPORT Sram_CarryingFlower_eFlag
Expand Down Expand Up @@ -56,7 +57,7 @@ kAvatarStunVelY = $ffff & -350
blt Func_KillAvatar
rts
_Harm:
jsr Func_DropFlower ; preserves X, Y, and T0+
jsr Func_BreakFlowerIfAny ; preserves X, Y, and T0+
lda #eSample::Harm ; param: eSample to play
jsr Func_PlaySfxSample ; preserves X, Y, and T0+
;; Mark the avatar as damaged.
Expand Down Expand Up @@ -103,16 +104,25 @@ _SetVelX:
sta Zp_AvatarFlags_bObj
lda #kAvatarHarmDeath
sta Zp_AvatarHarmTimer_u8
fall Func_DropFlower ; preserves X, Y, and T0+
fall Func_BreakFlowerIfAny ; preserves X, Y, and T0+
.ENDPROC

;;; If the player avatar is carrying a flower, drops the flower. Otherwise,
;;; If the player avatar is carrying a flower, breaks the flower. Otherwise,
;;; does nothing.
;;; @preserve X, Y, T0+
.PROC Func_BreakFlowerIfAny
lda Sram_CarryingFlower_eFlag
bne @breakFlower
rts
@breakFlower:
jsr Func_PlaySfxBreakFlower ; preserves X, Y, and T0+
fall Func_DropFlower ; preserves X, Y, and T0+
.ENDPROC

;;; Drops the flower that the player avatar is carrying.
;;; @preserve X, Y, T0+
.EXPORT Func_DropFlower
.PROC Func_DropFlower
lda Sram_CarryingFlower_eFlag
beq @done
main_chr10_bank Ppu_ChrObjAnnaNormal
;; Enable writes to SRAM.
lda #bMmc3PrgRam::Enable
Expand All @@ -123,7 +133,6 @@ _SetVelX:
;; Disable writes to SRAM.
lda #bMmc3PrgRam::Enable | bMmc3PrgRam::DenyWrites
sta Hw_Mmc3PrgRamProtect_wo
@done:
rts
.ENDPROC

Expand Down
114 changes: 114 additions & 0 deletions src/sounds/flower.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
;;;=========================================================================;;;
;;; 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 "break flower" sound effect.
.PROC Data_BreakFlower_sSfxSeq_arr
D_STRUCT sSfxSeq
d_byte Duration_u8, 2
d_byte Env_bEnvelope, bEnvelope::NoLength | 2
d_byte Sweep_byte, 0
d_word Timer_u16, $f883
D_END
D_STRUCT sSfxSeq
d_byte Duration_u8, 2
d_byte Env_bEnvelope, bEnvelope::NoLength | 2
d_byte Sweep_byte, 0
d_word Timer_u16, $f885
D_END
D_STRUCT sSfxSeq
d_byte Duration_u8, 7
d_byte Env_bEnvelope, bEnvelope::NoLength | 2
d_byte Sweep_byte, 0
d_word Timer_u16, $f88a
D_END
.byte 0
.ENDPROC

;;; SFX sequence data for the "pick up flower" sound effect.
.PROC Data_PickUpFlower_sSfxSeq_arr
D_STRUCT sSfxSeq
d_byte Duration_u8, 3
d_byte Env_bEnvelope, bEnvelope::Duty14 | bEnvelope::NoLength | 3
d_byte Sweep_byte, 0
d_word Timer_u16, $00d2
D_END
D_STRUCT sSfxSeq
d_byte Duration_u8, 3
d_byte Env_bEnvelope, bEnvelope::Duty14 | bEnvelope::NoLength | 3
d_byte Sweep_byte, 0
d_word Timer_u16, $00a9
D_END
D_STRUCT sSfxSeq
d_byte Duration_u8, 3
d_byte Env_bEnvelope, bEnvelope::Duty14 | bEnvelope::NoLength | 3
d_byte Sweep_byte, 0
d_word Timer_u16, $009f
D_END
D_STRUCT sSfxSeq
d_byte Duration_u8, 9
d_byte Env_bEnvelope, bEnvelope::Duty14 | bEnvelope::NoLength | 3
d_byte Sweep_byte, 0
d_word Timer_u16, $008e
D_END
.byte 0
.ENDPROC

;;; Starts playing the sound for when the player avatar breaks a flower.
;;; @preserve X, Y, T0+
.EXPORT Func_PlaySfxBreakFlower
.PROC Func_PlaySfxBreakFlower
txa
pha
tya
pha
ldx #eChan::Noise
ldya #Data_BreakFlower_sSfxSeq_arr
jsr Func_PlaySfxSequence ; preserves T0+
pla
tay
pla
tax
rts
.ENDPROC

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

.SEGMENT "PRGA_Avatar"

;;; Starts playing the sound for when the player avatar picks up a flower.
;;; @preserve T0+
.EXPORT FuncA_Avatar_PlaySfxPickUpFlower
.PROC FuncA_Avatar_PlaySfxPickUpFlower
ldx #eChan::Pulse1
ldya #Data_PickUpFlower_sSfxSeq_arr
jmp Func_PlaySfxSequence ; preserves T0+
.ENDPROC

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

0 comments on commit 11dad67

Please sign in to comment.