diff --git a/Mine2d/assets/audio/music-loop.wav b/Mine2d/assets/audio/music-loop.wav new file mode 100644 index 0000000..fe6318e Binary files /dev/null and b/Mine2d/assets/audio/music-loop.wav differ diff --git a/Mine2d/assets/audio/step.wav b/Mine2d/assets/audio/step.wav new file mode 100644 index 0000000..6cc6c87 Binary files /dev/null and b/Mine2d/assets/audio/step.wav differ diff --git a/Mine2d/assets/audio/step0.wav b/Mine2d/assets/audio/step0.wav new file mode 100644 index 0000000..c4b72b8 Binary files /dev/null and b/Mine2d/assets/audio/step0.wav differ diff --git a/Mine2d/assets/audio/step1.wav b/Mine2d/assets/audio/step1.wav new file mode 100644 index 0000000..50d1cf1 Binary files /dev/null and b/Mine2d/assets/audio/step1.wav differ diff --git a/Mine2d/assets/audio/step2.wav b/Mine2d/assets/audio/step2.wav new file mode 100644 index 0000000..519d1cd Binary files /dev/null and b/Mine2d/assets/audio/step2.wav differ diff --git a/Mine2d/assets/audio/step3.wav b/Mine2d/assets/audio/step3.wav new file mode 100644 index 0000000..3df04d0 Binary files /dev/null and b/Mine2d/assets/audio/step3.wav differ diff --git a/Mine2d/assets/audio/step4.wav b/Mine2d/assets/audio/step4.wav new file mode 100644 index 0000000..7e76816 Binary files /dev/null and b/Mine2d/assets/audio/step4.wav differ diff --git a/Mine2d/assets/audio/step5.wav b/Mine2d/assets/audio/step5.wav new file mode 100644 index 0000000..cbdb1c1 Binary files /dev/null and b/Mine2d/assets/audio/step5.wav differ diff --git a/Mine2d/engine/AudioPlayer.cs b/Mine2d/engine/AudioPlayer.cs index 1bc4ed7..b29223f 100644 --- a/Mine2d/engine/AudioPlayer.cs +++ b/Mine2d/engine/AudioPlayer.cs @@ -5,6 +5,13 @@ public enum Sound BlockHit, BlockBreak, ItemPickup, + MusicLoop, + Step0, + Step1, + Step2, + Step3, + Step4, + Step5, } public class AudioPlayer diff --git a/Mine2d/game/backend/interactor/Audio.cs b/Mine2d/game/backend/interactor/Audio.cs index 3fff16b..e6ea5ac 100644 --- a/Mine2d/game/backend/interactor/Audio.cs +++ b/Mine2d/game/backend/interactor/Audio.cs @@ -1,6 +1,7 @@ using Mine2d.engine; using Mine2d.engine.system.annotations; using Mine2d.game.backend.network.packets; +using Mine2d.game.core; namespace Mine2d.game.backend.interactor; @@ -13,4 +14,35 @@ public class Audio var ctx = Context.Get(); ctx.GameAudio.Play(Sound.BlockBreak); } + + [Interaction(InteractorKind.Client, PacketType.Tick)] + public static void Tick() + { + var ctx = Context.Get(); + if (ctx.FrontendGameState.NextMusicPlay < DateTime.Now) + { + ctx.GameAudio.Play(Sound.MusicLoop); + ctx.FrontendGameState.NextMusicPlay = DateTime.Now.AddSeconds(130); + } + if (false && ctx.FrontendGameState.NextStepPlay < DateTime.Now && PlayerEntity.GetSelf().PlayerMovementState.CurrentVelocity != Vector2.Zero) + { + ctx.GameAudio.Play(GetRandomStepSound()); + ctx.FrontendGameState.NextStepPlay = DateTime.Now.AddSeconds(0.2); + } + } + + private static Sound GetRandomStepSound() + { + var sound = new Random().NextInt64(0, 6); + return sound switch + { + 0 => Sound.Step0, + 1 => Sound.Step1, + 2 => Sound.Step2, + 3 => Sound.Step3, + 4 => Sound.Step4, + 5 => Sound.Step5, + _ => Sound.Step0 + }; + } } diff --git a/Mine2d/game/frontend/GameAudio.cs b/Mine2d/game/frontend/GameAudio.cs index e8bf752..4b41131 100644 --- a/Mine2d/game/frontend/GameAudio.cs +++ b/Mine2d/game/frontend/GameAudio.cs @@ -12,6 +12,13 @@ public class GameAudio this.audioPlayer.Register(Sound.BlockBreak, "assets.audio.block_break.wav"); this.audioPlayer.Register(Sound.BlockHit, "assets.audio.block_hit_alt.wav"); this.audioPlayer.Register(Sound.ItemPickup, "assets.audio.item_pickup.wav"); + this.audioPlayer.Register(Sound.MusicLoop, "assets.audio.music-loop.wav"); + this.audioPlayer.Register(Sound.Step0, "assets.audio.step0.wav"); + this.audioPlayer.Register(Sound.Step1, "assets.audio.step1.wav"); + this.audioPlayer.Register(Sound.Step2, "assets.audio.step2.wav"); + this.audioPlayer.Register(Sound.Step3, "assets.audio.step3.wav"); + this.audioPlayer.Register(Sound.Step4, "assets.audio.step4.wav"); + this.audioPlayer.Register(Sound.Step5, "assets.audio.step5.wav"); } public void Play(Sound sound) diff --git a/Mine2d/game/state/FrontendGameState.cs b/Mine2d/game/state/FrontendGameState.cs index 9d6a21c..4e7dea4 100644 --- a/Mine2d/game/state/FrontendGameState.cs +++ b/Mine2d/game/state/FrontendGameState.cs @@ -20,6 +20,8 @@ public class FrontendGameState public InventoryKind OpenInventory { get; set; } = InventoryKind.None; public InputState InputState { get; set; } = new(); public DebugState DebugState { get; set; } = new(); + public DateTime NextMusicPlay { get; set; } = DateTime.MinValue; + public DateTime NextStepPlay { get; set; } = DateTime.MinValue; } public class DebugState {