commit 455cec4e2da42faa28a12e3037c1ad321660ba89
parent b33fddeee28de88ac7a49e556d72b936a1be83c3
Author: Henry Unite <unitehenry@gmail.com>
Date: Sun, 19 Apr 2026 18:11:14 +0000
feat: init audio
Diffstat:
1 file changed, 21 insertions(+), 0 deletions(-)
diff --git a/src/game.c b/src/game.c
@@ -7,6 +7,7 @@
#define MainLoop emscripten_set_main_loop
#define SeedRandom srand(time(NULL))
+#define InitAudio init_audio()
/* Properties */
static const char *title = "rayflap";
@@ -23,6 +24,9 @@ Texture2D baseTexture;
Texture2D pipeTexture;
Texture2D scoreTexture[10];
+/* Sounds */
+Sound pointSound;
+
/* Game State */
typedef enum { TITLE, PLAY } Screen;
Screen screen = TITLE;
@@ -47,6 +51,19 @@ Rectangle pipeRects[4] = {
{0, 0, 0.0f, 0.0f},
};
+void init_audio() {
+ InitAudioDevice();
+
+ pointSound = LoadSound("assets/audio/point.ogg");
+}
+
+void play_sound(Sound sound) {
+ if (!IsSoundValid(sound))
+ return;
+
+ PlaySound(sound);
+}
+
void draw_message() {
if (screen != TITLE)
return;
@@ -414,6 +431,8 @@ void update() {
if (bottomPipeRect.x < (screenWidth / 2.0f)) {
if (lastCountedPipe != i) {
+ play_sound(pointSound);
+
score++;
lastCountedPipe = i;
}
@@ -447,6 +466,8 @@ int main() {
InitWindow(screenWidth, screenHeight, title);
+ InitAudio;
+
MainLoop(game_loop, 60, 1);
return 0;