diff --git a/assets/sounds/effects/grab.mp3 b/assets/sounds/effects/grab.mp3 new file mode 100644 index 0000000..260841a Binary files /dev/null and b/assets/sounds/effects/grab.mp3 differ diff --git a/assets/sounds/effects/steps/steps_indoor_1.mp3 b/assets/sounds/effects/steps/steps_indoor_1.mp3 new file mode 100644 index 0000000..14a9874 Binary files /dev/null and b/assets/sounds/effects/steps/steps_indoor_1.mp3 differ diff --git a/assets/sounds/effects/steps/steps_indoor_2.mp3 b/assets/sounds/effects/steps/steps_indoor_2.mp3 new file mode 100644 index 0000000..8e64910 Binary files /dev/null and b/assets/sounds/effects/steps/steps_indoor_2.mp3 differ diff --git a/assets/sounds/effects/steps/steps_indoor_3.mp3 b/assets/sounds/effects/steps/steps_indoor_3.mp3 new file mode 100644 index 0000000..02dbf87 Binary files /dev/null and b/assets/sounds/effects/steps/steps_indoor_3.mp3 differ diff --git a/assets/sounds/effects/steps_indoor.mp3 b/assets/sounds/effects/steps_indoor.mp3 deleted file mode 100644 index 4badd24..0000000 Binary files a/assets/sounds/effects/steps_indoor.mp3 and /dev/null differ diff --git a/assets/sounds/effects/time_travel.mp3 b/assets/sounds/effects/time_travel.mp3 new file mode 100644 index 0000000..9543b3e Binary files /dev/null and b/assets/sounds/effects/time_travel.mp3 differ diff --git a/core/src/main/kotlin/com/last/commit/Player.kt b/core/src/main/kotlin/com/last/commit/Player.kt index 32cda19..11d4d9b 100644 --- a/core/src/main/kotlin/com/last/commit/Player.kt +++ b/core/src/main/kotlin/com/last/commit/Player.kt @@ -16,6 +16,7 @@ class Player(private val textureRegion: TextureRegion, private val gameState: Ga private var direction = Vector2.Zero private val movementSpeed = 200f private val interactionRange = 60f + private var lastStep = 0L init { val size = Math.max(textureRegion.regionWidth, textureRegion.regionHeight).toFloat() @@ -36,8 +37,15 @@ class Player(private val textureRegion: TextureRegion, private val gameState: Ga } fun move(v: Vector2, delta: Float) { - updatePosition(v, delta) - updateCollider() + if (v.x != 0f || v.y != 0f) { + updatePosition(v, delta) + updateCollider() + + if (System.currentTimeMillis() - lastStep > 500) { + gameState.soundEngine.play(GameSoundEffect.STEPS_INDOOR, 0.5f) + lastStep = System.currentTimeMillis() + } + } } private fun updatePosition(v: Vector2, delta: Float) { diff --git a/core/src/main/kotlin/com/last/commit/audio/GameSoundEffect.kt b/core/src/main/kotlin/com/last/commit/audio/GameSoundEffect.kt index 424ce22..a4ba3fb 100644 --- a/core/src/main/kotlin/com/last/commit/audio/GameSoundEffect.kt +++ b/core/src/main/kotlin/com/last/commit/audio/GameSoundEffect.kt @@ -4,8 +4,16 @@ import com.last.commit.audio.GameSound public class GameSoundEffect(name: String): GameSound(name) { companion object { - val STEPS_INDOOR = GameSoundEffect("steps_indoor.mp3") + val STEPS_INDOOR: GameSoundEffect + get() = listOf( + GameSoundEffect("steps/steps_indoor_1.mp3"), + GameSoundEffect("steps/steps_indoor_2.mp3"), + GameSoundEffect("steps/steps_indoor_3.mp3"), + ).random() + val DOOR_OPEN = GameSoundEffect("door_open.mp3") val DOOR_CLOSE = GameSoundEffect("door_close.mp3") + val TIME_TRAVEL = GameSoundEffect("time_travel.mp3") + val GRAB = GameSoundEffect("grab.mp3") } } \ No newline at end of file diff --git a/core/src/main/kotlin/com/last/commit/audio/SoundEngine.kt b/core/src/main/kotlin/com/last/commit/audio/SoundEngine.kt index cb674d0..d1dd402 100644 --- a/core/src/main/kotlin/com/last/commit/audio/SoundEngine.kt +++ b/core/src/main/kotlin/com/last/commit/audio/SoundEngine.kt @@ -1,18 +1,17 @@ -package com.last.commit.audio; +package com.last.commit.audio import com.badlogic.gdx.Gdx -import com.badlogic.gdx.audio.Sound import com.badlogic.gdx.audio.Music -import com.last.commit.audio.GameSound -import com.last.commit.audio.GameMusic - +import com.badlogic.gdx.audio.Sound public class SoundEngine { - private val sounds: HashMap = HashMap() - private val musicTracks: HashMap = HashMap() - - public fun play(gameSound: GameSound, volume: Float = 1f) { + private val sounds: ThreadLocal> = + ThreadLocal.withInitial() { HashMap() } + private val musicTracks: ThreadLocal> = + ThreadLocal.withInitial() { HashMap() } + + fun play(gameSound: GameSound, volume: Float = 1f) { if (gameSound is GameSoundEffect) { val sound = loadEffect(gameSound.name) sound.play(volume) @@ -24,28 +23,29 @@ public class SoundEngine { music.play() } } - - private fun loadEffect(name: String): Sound { + + private fun loadEffect(name: String): Sound { return loadSound("effects/$name") } private fun loadMusic(name: String): Music { - var music = musicTracks.get(name) + var music = musicTracks.get().get(name) + if (music == null) { println("Loading sound $name") - music = Gdx.audio.newMusic(Gdx.files.internal("sounds/music/$name")) - musicTracks[name] = music + music = Gdx.audio.newMusic(Gdx.files.internal("sounds/music/$name")) + musicTracks.get()[name] = music } return music!! } private fun loadSound(name: String): Sound { - var sound = sounds.get(name) + var sound = sounds.get().get(name) if (sound == null) { println("Loading sound $name") sound = Gdx.audio.newSound(Gdx.files.internal("sounds/$name")) - sounds[name] = sound + sounds.get()[name] = sound } return sound!! diff --git a/core/src/main/kotlin/com/last/commit/map/Collectible.kt b/core/src/main/kotlin/com/last/commit/map/Collectible.kt index 43cc65d..d81303b 100644 --- a/core/src/main/kotlin/com/last/commit/map/Collectible.kt +++ b/core/src/main/kotlin/com/last/commit/map/Collectible.kt @@ -1,6 +1,7 @@ package com.last.commit.map import com.badlogic.gdx.math.Rectangle +import com.last.commit.audio.GameSoundEffect import Position import GameState @@ -21,6 +22,7 @@ class Collectible( override fun interact(otherCollider: Rectangle, state: GameState) { println("Interacting with item $name") + state.soundEngine.play(GameSoundEffect.GRAB) state.inventory.add(this.name) } diff --git a/core/src/main/kotlin/com/last/commit/map/TimeMap.kt b/core/src/main/kotlin/com/last/commit/map/TimeMap.kt index 1f7627b..1553f3b 100644 --- a/core/src/main/kotlin/com/last/commit/map/TimeMap.kt +++ b/core/src/main/kotlin/com/last/commit/map/TimeMap.kt @@ -14,6 +14,7 @@ import com.badlogic.gdx.utils.Array import com.last.commit.Collidable import com.last.commit.Player import com.last.commit.Wall +import com.last.commit.audio.GameSoundEffect import Position import GameState @@ -50,6 +51,7 @@ class TimeMap(fileName: String, val state: GameState) { for (teleporter in teleporters) { if (teleporter is RectangleMapObject) { if (teleporter.rectangle.contains(player.getX(), player.getY())) { + state.soundEngine.play(GameSoundEffect.TIME_TRAVEL) val targetMap = teleporter.properties.get("target", String::class.java) System.out.println("Teleporting to targetMap $targetMap") map = mapLoader.load("tiled/$targetMap") @@ -67,6 +69,7 @@ class TimeMap(fileName: String, val state: GameState) { fun getPlayerSpawn(): Vector2 { val mapLayers = map.layers val spawnPoints = mapLayers["Spawnpoints"].objects + for (spawnPoint in spawnPoints) { val spawnPointProperties = spawnPoint.properties if (spawnPointProperties != null && spawnPointProperties.containsKey("playerSpawn")) {