Skip to content

Commit

Permalink
✨ Add footsteps
Browse files Browse the repository at this point in the history
Finally, we have footstep sounds in the game that trigger when the
player moves around in the world.

I've also removed the ambient sounds for the panels in the main
environment, as it did result in significant memory increase. I will
investigate how to go about this better in the next sprint, M6.

Signed-off-by: Marquis Kurt <[email protected]>
  • Loading branch information
alicerunsonfedora committed Nov 18, 2022
1 parent f6f8080 commit 596b65f
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 11 deletions.
Binary file added Shounin/Assets/SFX/sfx_foot_wood.wav
Binary file not shown.
15 changes: 6 additions & 9 deletions Shounin/Environment/GameEnvironment.swift
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,10 @@ class GameEnvironment: SKScene {
setUpAmbientSoundscape()
}

override func willMove(from view: SKView) {
childNode(withName: "baseAmbience")?.run(.changeVolume(to: 0, duration: 0.1))
}

/// Displays the solving mode tutorial if it hasn't been displayed already.
func displaySolvingTutorialIfNeeded() {
guard shouldDisplaySolvingTutorialNode() else { return }
Expand Down Expand Up @@ -276,16 +280,9 @@ class GameEnvironment: SKScene {

private func setUpAmbientSoundscape() {
let audioNode = SKAudioNode(ambientTrackNamed: "amb_room_still", at: 0.1)
audioNode.name = "baseAmbience"
audioNode.run(.changeVolume(to: 0, duration: 0.1))
addChild(audioNode)
let puzzlesCount = Float(environmentDelegate?.allPuzzleTriggers().count ?? 0)
environmentDelegate?.allPuzzleTriggers().forEach { position in
let ambientNode = SKAudioNode(fileNamed: "amb_panel_presence")
ambientNode.isPositional = true
ambientNode.autoplayLooped = true
ambientNode.position = position
ambientNode.run(.changeVolume(to: 0.1 / puzzlesCount, duration: 0))
addChild(ambientNode)
}
}

private func shouldDisplaySolvingTutorialNode() -> Bool {
Expand Down
19 changes: 19 additions & 0 deletions Shounin/Environment/GamePlayer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class GamePlayer: SKSpriteNode {
private var isMoving = false
private var atlas = TextureAtlas()
private var frameRate: TimeInterval = 1 / 6
private var footsteps: SKAudioNode?

/// Creates a player at a specified position.
/// - Parameter position: The position in the SpriteKit scene to set the player at.
Expand Down Expand Up @@ -81,6 +82,7 @@ class GamePlayer: SKSpriteNode {
walkingDirection = direction
facingDirection = direction
updateWalkSpriteAnimation()
createFootsteps()
isMoving = true
}

Expand All @@ -91,6 +93,23 @@ class GamePlayer: SKSpriteNode {
walkingDirection = .stop
updateIdleSpriteAnimation()
isMoving = false
destroyFootsteps()
}

private func createFootsteps() {
guard footsteps == nil else { return }
let fsNode = SKAudioNode(fileNamed: "sfx_foot_wood")
fsNode.autoplayLooped = true
fsNode.isPositional = true
fsNode.run(.changeVolume(to: 0.1, duration: 0))
addChild(fsNode)
footsteps = fsNode
}

private func destroyFootsteps() {
guard let footsteps else { return }
footsteps.removeFromParent()
self.footsteps = nil
}

private func setPhysicsBody() {
Expand Down
4 changes: 4 additions & 0 deletions Shounin/Shounin.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
9553E34B2926850800B6C713 /* sfx_panel_failure.wav in Resources */ = {isa = PBXBuildFile; fileRef = 9553E3482926850800B6C713 /* sfx_panel_failure.wav */; };
9553E34D2926881400B6C713 /* sfx_panel_start.wav in Resources */ = {isa = PBXBuildFile; fileRef = 9553E34C2926881400B6C713 /* sfx_panel_start.wav */; };
9553E34F2926893000B6C713 /* sfx_panel_end.wav in Resources */ = {isa = PBXBuildFile; fileRef = 9553E34E2926893000B6C713 /* sfx_panel_end.wav */; };
9553E3512927C5E500B6C713 /* sfx_foot_wood.wav in Resources */ = {isa = PBXBuildFile; fileRef = 9553E3502927C5E500B6C713 /* sfx_foot_wood.wav */; };
9564878D28EC756A00B4477D /* Paintbrush in Frameworks */ = {isa = PBXBuildFile; productRef = 9564878C28EC756A00B4477D /* Paintbrush */; };
956B604128C7A2200031794C /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 956B604328C7A2200031794C /* InfoPlist.strings */; };
956B604628C7A4730031794C /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 956B604528C7A4730031794C /* AppDelegate.swift */; };
Expand Down Expand Up @@ -159,6 +160,7 @@
9553E3482926850800B6C713 /* sfx_panel_failure.wav */ = {isa = PBXFileReference; lastKnownFileType = audio.wav; path = sfx_panel_failure.wav; sourceTree = "<group>"; };
9553E34C2926881400B6C713 /* sfx_panel_start.wav */ = {isa = PBXFileReference; lastKnownFileType = audio.wav; path = sfx_panel_start.wav; sourceTree = "<group>"; };
9553E34E2926893000B6C713 /* sfx_panel_end.wav */ = {isa = PBXFileReference; lastKnownFileType = audio.wav; path = sfx_panel_end.wav; sourceTree = "<group>"; };
9553E3502927C5E500B6C713 /* sfx_foot_wood.wav */ = {isa = PBXFileReference; lastKnownFileType = audio.wav; path = sfx_foot_wood.wav; sourceTree = "<group>"; };
9564878A28EC755400B4477D /* Paintbrush */ = {isa = PBXFileReference; lastKnownFileType = wrapper; name = Paintbrush; path = ../Paintbrush; sourceTree = "<group>"; };
956B604228C7A2200031794C /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = "<group>"; };
956B604528C7A4730031794C /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -382,6 +384,7 @@
children = (
9553E3462926850800B6C713 /* amb_panel_presence.wav */,
9553E3472926850800B6C713 /* amb_room_still.wav */,
9553E3502927C5E500B6C713 /* sfx_foot_wood.wav */,
9553E34E2926893000B6C713 /* sfx_panel_end.wav */,
9553E3482926850800B6C713 /* sfx_panel_failure.wav */,
9553E34C2926881400B6C713 /* sfx_panel_start.wav */,
Expand Down Expand Up @@ -734,6 +737,7 @@
95AD566A28EE25BD00051144 /* Room_Builder_32x32.png in Resources */,
95DB209228CFA9840079D624 /* ch07.md in Resources */,
95735C1F291C125F003947F5 /* TutorialTouchLayout.sks in Resources */,
9553E3512927C5E500B6C713 /* sfx_foot_wood.wav in Resources */,
95FC94EB2922BD8B00623FA1 /* GameEnvironmentPlayer.1.png in Resources */,
95E4F61F28EC9C61009627F6 /* Caslon Scene.sks in Resources */,
95FC94EA2922BD8B00623FA1 /* GameEnvironmentPlayer.plist in Resources */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,15 +91,16 @@
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<MacroExpansion>
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "950F6CC628C0EADA007ACB53"
BuildableName = "Indexing Your Heart.app"
BlueprintName = "Indexing Your Heart"
ReferencedContainer = "container:Shounin.xcodeproj">
</BuildableReference>
</MacroExpansion>
</BuildableProductRunnable>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
Expand Down

0 comments on commit 596b65f

Please sign in to comment.