diff --git a/res/sounds/Listener/botton-sound-pack/cancel.ogg b/res/sounds/Listener/botton-sound-pack/cancel.ogg new file mode 100644 index 0000000..2f6f09b Binary files /dev/null and b/res/sounds/Listener/botton-sound-pack/cancel.ogg differ diff --git a/res/sounds/Listener/botton-sound-pack/source.md b/res/sounds/Listener/botton-sound-pack/source.md new file mode 100644 index 0000000..7a140de --- /dev/null +++ b/res/sounds/Listener/botton-sound-pack/source.md @@ -0,0 +1 @@ +https://opengameart.org/content/botton-sound-pack \ No newline at end of file diff --git a/res/sounds/leohpaz/retro-rpg-menu-sounds/001_Hover_01.ogg b/res/sounds/leohpaz/retro-rpg-menu-sounds/001_Hover_01.ogg new file mode 100644 index 0000000..5e5f122 Binary files /dev/null and b/res/sounds/leohpaz/retro-rpg-menu-sounds/001_Hover_01.ogg differ diff --git a/res/sounds/leohpaz/retro-rpg-menu-sounds/013_Confirm_03.ogg b/res/sounds/leohpaz/retro-rpg-menu-sounds/013_Confirm_03.ogg new file mode 100644 index 0000000..4271622 Binary files /dev/null and b/res/sounds/leohpaz/retro-rpg-menu-sounds/013_Confirm_03.ogg differ diff --git a/res/sounds/leohpaz/retro-rpg-menu-sounds/029_Decline_09.ogg b/res/sounds/leohpaz/retro-rpg-menu-sounds/029_Decline_09.ogg new file mode 100644 index 0000000..e1da7d7 Binary files /dev/null and b/res/sounds/leohpaz/retro-rpg-menu-sounds/029_Decline_09.ogg differ diff --git a/res/sounds/leohpaz/retro-rpg-menu-sounds/033_Denied_03.ogg b/res/sounds/leohpaz/retro-rpg-menu-sounds/033_Denied_03.ogg new file mode 100644 index 0000000..8791ad9 Binary files /dev/null and b/res/sounds/leohpaz/retro-rpg-menu-sounds/033_Denied_03.ogg differ diff --git a/res/sounds/leohpaz/retro-rpg-menu-sounds/051_use_item_01.ogg b/res/sounds/leohpaz/retro-rpg-menu-sounds/051_use_item_01.ogg new file mode 100644 index 0000000..57e1ed0 Binary files /dev/null and b/res/sounds/leohpaz/retro-rpg-menu-sounds/051_use_item_01.ogg differ diff --git a/res/sounds/leohpaz/retro-rpg-menu-sounds/070_Equip_10.ogg b/res/sounds/leohpaz/retro-rpg-menu-sounds/070_Equip_10.ogg new file mode 100644 index 0000000..e9bebf9 Binary files /dev/null and b/res/sounds/leohpaz/retro-rpg-menu-sounds/070_Equip_10.ogg differ diff --git a/res/sounds/leohpaz/retro-rpg-menu-sounds/071_Unequip_01.ogg b/res/sounds/leohpaz/retro-rpg-menu-sounds/071_Unequip_01.ogg new file mode 100644 index 0000000..9b88fe1 Binary files /dev/null and b/res/sounds/leohpaz/retro-rpg-menu-sounds/071_Unequip_01.ogg differ diff --git a/res/sounds/leohpaz/retro-rpg-menu-sounds/079_Buy_sell_01.ogg b/res/sounds/leohpaz/retro-rpg-menu-sounds/079_Buy_sell_01.ogg new file mode 100644 index 0000000..a2796cb Binary files /dev/null and b/res/sounds/leohpaz/retro-rpg-menu-sounds/079_Buy_sell_01.ogg differ diff --git a/res/sounds/leohpaz/retro-rpg-menu-sounds/092_Pause_04.ogg b/res/sounds/leohpaz/retro-rpg-menu-sounds/092_Pause_04.ogg new file mode 100644 index 0000000..40167e1 Binary files /dev/null and b/res/sounds/leohpaz/retro-rpg-menu-sounds/092_Pause_04.ogg differ diff --git a/res/sounds/leohpaz/retro-rpg-menu-sounds/098_Unpause_04.ogg b/res/sounds/leohpaz/retro-rpg-menu-sounds/098_Unpause_04.ogg new file mode 100644 index 0000000..11f5cc4 Binary files /dev/null and b/res/sounds/leohpaz/retro-rpg-menu-sounds/098_Unpause_04.ogg differ diff --git a/res/sounds/p0ss/interface-sounds/appear-online.ogg b/res/sounds/p0ss/interface-sounds/appear-online.ogg new file mode 100644 index 0000000..c3c6061 Binary files /dev/null and b/res/sounds/p0ss/interface-sounds/appear-online.ogg differ diff --git a/res/sounds/p0ss/interface-sounds/click.ogg b/res/sounds/p0ss/interface-sounds/click.ogg new file mode 100644 index 0000000..7f9d15b Binary files /dev/null and b/res/sounds/p0ss/interface-sounds/click.ogg differ diff --git a/res/sounds/p0ss/interface-sounds/click2.ogg b/res/sounds/p0ss/interface-sounds/click2.ogg new file mode 100644 index 0000000..911248e Binary files /dev/null and b/res/sounds/p0ss/interface-sounds/click2.ogg differ diff --git a/res/sounds/p0ss/interface-sounds/click3.ogg b/res/sounds/p0ss/interface-sounds/click3.ogg new file mode 100644 index 0000000..c650b20 Binary files /dev/null and b/res/sounds/p0ss/interface-sounds/click3.ogg differ diff --git a/res/sounds/p0ss/interface-sounds/click4.ogg b/res/sounds/p0ss/interface-sounds/click4.ogg new file mode 100644 index 0000000..ae37bc0 Binary files /dev/null and b/res/sounds/p0ss/interface-sounds/click4.ogg differ diff --git a/res/sounds/p0ss/interface-sounds/click5.ogg b/res/sounds/p0ss/interface-sounds/click5.ogg new file mode 100644 index 0000000..6331d6d Binary files /dev/null and b/res/sounds/p0ss/interface-sounds/click5.ogg differ diff --git a/res/sounds/p0ss/interface-sounds/click6.ogg b/res/sounds/p0ss/interface-sounds/click6.ogg new file mode 100644 index 0000000..fb2f3c9 Binary files /dev/null and b/res/sounds/p0ss/interface-sounds/click6.ogg differ diff --git a/res/sounds/p0ss/interface-sounds/click7.ogg b/res/sounds/p0ss/interface-sounds/click7.ogg new file mode 100644 index 0000000..bd2d87f Binary files /dev/null and b/res/sounds/p0ss/interface-sounds/click7.ogg differ diff --git a/res/sounds/p0ss/interface-sounds/cut.ogg b/res/sounds/p0ss/interface-sounds/cut.ogg new file mode 100644 index 0000000..6c80db6 Binary files /dev/null and b/res/sounds/p0ss/interface-sounds/cut.ogg differ diff --git a/res/sounds/p0ss/interface-sounds/drop.ogg b/res/sounds/p0ss/interface-sounds/drop.ogg new file mode 100644 index 0000000..3564a23 Binary files /dev/null and b/res/sounds/p0ss/interface-sounds/drop.ogg differ diff --git a/res/sounds/p0ss/interface-sounds/dustbin.ogg b/res/sounds/p0ss/interface-sounds/dustbin.ogg new file mode 100644 index 0000000..f495c78 Binary files /dev/null and b/res/sounds/p0ss/interface-sounds/dustbin.ogg differ diff --git a/res/sounds/p0ss/interface-sounds/message.ogg b/res/sounds/p0ss/interface-sounds/message.ogg new file mode 100644 index 0000000..5e374cf Binary files /dev/null and b/res/sounds/p0ss/interface-sounds/message.ogg differ diff --git a/res/sounds/p0ss/interface-sounds/snap.ogg b/res/sounds/p0ss/interface-sounds/snap.ogg new file mode 100644 index 0000000..fb42d6d Binary files /dev/null and b/res/sounds/p0ss/interface-sounds/snap.ogg differ diff --git a/res/sounds/p0ss/interface-sounds/snap1.ogg b/res/sounds/p0ss/interface-sounds/snap1.ogg new file mode 100644 index 0000000..4b44e94 Binary files /dev/null and b/res/sounds/p0ss/interface-sounds/snap1.ogg differ diff --git a/res/sounds/p0ss/interface-sounds/snap2.ogg b/res/sounds/p0ss/interface-sounds/snap2.ogg new file mode 100644 index 0000000..c59d32e Binary files /dev/null and b/res/sounds/p0ss/interface-sounds/snap2.ogg differ diff --git a/res/sounds/p0ss/interface-sounds/source.md b/res/sounds/p0ss/interface-sounds/source.md new file mode 100644 index 0000000..fc74b49 --- /dev/null +++ b/res/sounds/p0ss/interface-sounds/source.md @@ -0,0 +1 @@ +https://opengameart.org/content/interface-sounds-starter-pack diff --git a/src/main/java/xyz/valnet/engine/App.java b/src/main/java/xyz/valnet/engine/App.java index bd358b3..23f3928 100644 --- a/src/main/java/xyz/valnet/engine/App.java +++ b/src/main/java/xyz/valnet/engine/App.java @@ -1,6 +1,7 @@ package xyz.valnet.engine; import org.lwjgl.glfw.*; +import org.lwjgl.openal.*; import org.lwjgl.opengl.*; import org.lwjgl.system.*; @@ -14,6 +15,8 @@ import static org.lwjgl.opengl.GL11.*; import static org.lwjgl.system.MemoryStack.*; import static org.lwjgl.system.MemoryUtil.*; +import static org.lwjgl.openal.ALC10.*; + public class App { // The window handle @@ -22,6 +25,9 @@ public class App { private Matrix4f matrix = Matrix4f.orthographic(0, width, height, 0, 0, 100); public static int mouseX, mouseY; + public static long audioContext; + public static long audioDevice; + @Deprecated public static boolean mouseLeft, mouseMiddle, mouseRight; @@ -37,6 +43,9 @@ public class App { glfwFreeCallbacks(window); glfwDestroyWindow(window); + alcDestroyContext(audioContext); + alcCloseDevice(audioDevice); + // Terminate GLFW and free the error callback glfwTerminate(); glfwSetErrorCallback(null).free(); @@ -122,6 +131,20 @@ public class App { // Enable v-sync glfwSwapInterval(1); + // Audio device + String defaultDeviceName = alcGetString(0, ALC_DEFAULT_DEVICE_SPECIFIER); + audioDevice = alcOpenDevice(defaultDeviceName); + int[] attributes = {0}; + audioContext = alcCreateContext(audioDevice, attributes); + alcMakeContextCurrent(audioContext); + + ALCCapabilities alcCapabilities = ALC.createCapabilities(audioDevice); + ALCapabilities alCapabilities = AL.createCapabilities(alcCapabilities); + + if(!alCapabilities.OpenAL10) { + System.err.println("Audio not supported?!"); + } + // Make the window visible glfwShowWindow(window); diff --git a/src/main/java/xyz/valnet/engine/sound/Sound.java b/src/main/java/xyz/valnet/engine/sound/Sound.java new file mode 100644 index 0000000..bc0e763 --- /dev/null +++ b/src/main/java/xyz/valnet/engine/sound/Sound.java @@ -0,0 +1,105 @@ +package xyz.valnet.engine.sound; + +import java.io.FileInputStream; +import java.nio.IntBuffer; +import java.nio.ShortBuffer; + +import org.lwjgl.BufferUtils; +import org.lwjgl.PointerBuffer; +import static org.lwjgl.openal.AL10.*; + +import static org.lwjgl.stb.STBVorbis.*; + +import static org.lwjgl.system.MemoryStack.*; +import static org.lwjgl.system.MemoryUtil.memFree; +import org.lwjgl.system.MemoryStack; + +public class Sound { + + private int bufferId; + private int sourceId; + + private boolean loops = false; + + // private float volume = 1.0f; + + public Sound setVolume(float vol) { + alSourcef(sourceId, AL_GAIN, vol); + return this; + } + + public Sound(String path) { + + try (MemoryStack stack = stackPush()) { + IntBuffer channelsBuffer = stack.mallocInt(1); // int* + IntBuffer sampleRateBuffer = stack.mallocInt(1); // int* + + ShortBuffer rawAudioBuffer = stb_vorbis_decode_filename(path, channelsBuffer, sampleRateBuffer); + + if(rawAudioBuffer == null) { + System.err.println("SOUND FAILED BRUV"); + return; + } + + int channels = channelsBuffer.get(); + int samplerate = sampleRateBuffer.get(); + + int format = -1; + if(channels == 1) { + format = AL_FORMAT_MONO16; + } else if (channels == 2) { + format = AL_FORMAT_STEREO16; + } + + bufferId = alGenBuffers(); + alBufferData(bufferId, format, rawAudioBuffer, samplerate); + + sourceId = alGenSources(); + + alSourcei(sourceId, AL_BUFFER, bufferId); + alSourcei(sourceId, AL_LOOPING, loops ? 1 : 0); + alSourcei(sourceId, AL_POSITION, 0); + alSourcef(sourceId, AL_GAIN, 1.0f); + + memFree(rawAudioBuffer); + } + } + + public void play() { + int state = alGetSourcei(sourceId, AL_SOURCE_STATE); + if(state == AL_PLAYING) { + alSourceStop(sourceId); + alSourcei(sourceId, AL_POSITION, 0); + } + alSourcePlay(sourceId); + } + + public void stop() { + int state = alGetSourcei(sourceId, AL_SOURCE_STATE); + if(state == AL_PLAYING) { + alSourceStop(sourceId); + alSourcei(sourceId, AL_POSITION, 0); + } + } + + public boolean isPlaying() { + return alGetSourcei(sourceId, AL_SOURCE_STATE) == AL_PLAYING; + } + + // public static void start() { + // FileInputStream fileStream = new FileInputStream("res/sounds/p0ss/interface-sounds/appear-online.ogg"); + // IntBuffer samples = readOffSamplesToBuffer(fileStream); + // } + + // private static IntBuffer readOffSamplesToBuffer(FileInputStream fileStream) { + // // This theoretical class is what I need – something that + // // can read the data from the OGG file. + // STBVorbis.info + // OggReader reader = new OggReader(fileStream); + + // // Very simplified example + // ShortBuffer buffer = BufferUtils.createIntBuffer(reader.getSampleCount()); + // buffer.put(reader.samplesAsShortArray()); + // return buffer; + // } +} diff --git a/src/main/java/xyz/valnet/hadean/gameobjects/inputlayer/BuildLayer.java b/src/main/java/xyz/valnet/hadean/gameobjects/inputlayer/BuildLayer.java index 12e3f35..6629f7c 100644 --- a/src/main/java/xyz/valnet/hadean/gameobjects/inputlayer/BuildLayer.java +++ b/src/main/java/xyz/valnet/hadean/gameobjects/inputlayer/BuildLayer.java @@ -9,6 +9,7 @@ import xyz.valnet.engine.scenegraph.ITransient; import xyz.valnet.hadean.gameobjects.Camera; import xyz.valnet.hadean.interfaces.BuildableMetadata; import xyz.valnet.hadean.interfaces.IBuildLayerListener; +import xyz.valnet.hadean.util.Assets; import xyz.valnet.hadean.util.Layers; public class BuildLayer extends GameObject implements IMouseCaptureArea, ITransient { @@ -84,6 +85,7 @@ public class BuildLayer extends GameObject implements IMouseCaptureArea, ITransi @Override public void mouseDown(int button) { if(button == 1 && active && hovered) { + Assets.sndCancel.play(); listener.cancel(); } else if(button == 0 && active && hovered) { // TODO this conversion in negative numbers definitely works wrong. diff --git a/src/main/java/xyz/valnet/hadean/gameobjects/inputlayer/SelectionLayer.java b/src/main/java/xyz/valnet/hadean/gameobjects/inputlayer/SelectionLayer.java index cb38a67..e30a5bc 100644 --- a/src/main/java/xyz/valnet/hadean/gameobjects/inputlayer/SelectionLayer.java +++ b/src/main/java/xyz/valnet/hadean/gameobjects/inputlayer/SelectionLayer.java @@ -132,6 +132,10 @@ public class SelectionLayer extends GameObject implements IMouseCaptureArea, ITr } private void broadcastSelectionChanged() { + Assets.sndSelectionChanged.play(); + // if(selected.size() > 0) Assets.sndBubble.play(); + // if(selected.size() == 0) Assets.sndCancel.play(); + for(ISelectionChangeListener listener : listeners) { listener.selectionChanged(selected); } diff --git a/src/main/java/xyz/valnet/hadean/input/Button.java b/src/main/java/xyz/valnet/hadean/input/Button.java index 40cfec8..905bcc2 100644 --- a/src/main/java/xyz/valnet/hadean/input/Button.java +++ b/src/main/java/xyz/valnet/hadean/input/Button.java @@ -121,6 +121,7 @@ public class Button extends GameObject implements IMouseCaptureArea, ITransient if(state == IDLE) { if(hovered) { + Assets.sndGlassTap.play(); state = HOVER; } else if (mouseDown) { state = INACTIVE; @@ -139,8 +140,13 @@ public class Button extends GameObject implements IMouseCaptureArea, ITransient if(!hovered) { state = ACTIVE_NO_HOVER; } else if(!mouseDown) { - state = IDLE; + if(!hovered) { + state = IDLE; + } else { + state = HOVER; + } listener.click(this); + Assets.sndBubble.play(); } } else if (state == ACTIVE_NO_HOVER) { if(hovered) { diff --git a/src/main/java/xyz/valnet/hadean/util/Assets.java b/src/main/java/xyz/valnet/hadean/util/Assets.java index 9693eba..1af7071 100644 --- a/src/main/java/xyz/valnet/hadean/util/Assets.java +++ b/src/main/java/xyz/valnet/hadean/util/Assets.java @@ -10,9 +10,15 @@ import xyz.valnet.engine.graphics.Tile16; import xyz.valnet.engine.graphics.Tile9; import xyz.valnet.engine.math.Vector4i; import xyz.valnet.engine.shaders.SimpleShader; +import xyz.valnet.engine.sound.Sound; public class Assets { - + + public static final Sound sndBubble; + public static final Sound sndCancel; + public static final Sound sndGlassTap; + public static final Sound sndSelectionChanged; + public static final Texture atlas; public static final Font font; public static final Font miniFont; @@ -308,6 +314,12 @@ public class Assets { wall = new Tile16(atlas, new Vector4i(0, 17 * 8, 32, 32)); + sndSelectionChanged = new Sound("res/sounds/leohpaz/retro-rpg-menu-sounds/079_Buy_sell_01.ogg"); + sndBubble = new Sound("res/sounds/p0ss/interface-sounds/appear-online.ogg"); + // sndCancel = new Sound("res/sounds/Listener/botton-sound-pack/cancel.ogg").setVolume(2f); + sndCancel = new Sound("res/sounds/leohpaz/retro-rpg-menu-sounds/098_Unpause_04.ogg").setVolume(0.8f); + sndGlassTap = new Sound("res/sounds/p0ss/interface-sounds/click5.ogg").setVolume(0.2f); + System.out.println("END ASSETS"); } }