diff --git a/assets/cannonball_impact.mp3 b/assets/cannonball_impact.mp3 new file mode 100644 index 0000000..3e66e77 Binary files /dev/null and b/assets/cannonball_impact.mp3 differ diff --git a/assets/cannonball_shooting.mp3 b/assets/cannonball_shooting.mp3 new file mode 100644 index 0000000..0aa7cce Binary files /dev/null and b/assets/cannonball_shooting.mp3 differ diff --git a/include/app.h b/include/app.h index 7a882ae..0f7cbb9 100644 --- a/include/app.h +++ b/include/app.h @@ -34,7 +34,7 @@ typedef enum { ISLAND, ISLANDS_TEX_COUNT } islandsTextureID; typedef enum { POST_FX, SHADER_COUNT } ShaderID; -typedef enum { BEE_AMBIENT, SOUNDTRACK_COUNT } SoundtrackID; +typedef enum { BEE_AMBIENT, GAMEPLAY_THEME, SOUNDTRACK_COUNT } SoundtrackID; typedef enum View { LOGO = 0, MENU = 1, GAMEPLAY = 2 } View; @@ -100,6 +100,7 @@ typedef struct { Animation animation; Physics physics; float rotation; + Sound soundFlapping; } Player; typedef enum { BOAT, ENEMIES_TEX_COUNT } enemiesTextureID; @@ -155,6 +156,8 @@ typedef struct { bool active[MAX_PROJECTILES]; float radius[MAX_PROJECTILES]; Color color[MAX_PROJECTILES]; + Sound soundShooting[MAX_PROJECTILES]; + Sound soundImpact[MAX_PROJECTILES]; } Projectiles; typedef struct { diff --git a/src/appGameProjectiles.c b/src/appGameProjectiles.c index 1162011..469dddd 100644 --- a/src/appGameProjectiles.c +++ b/src/appGameProjectiles.c @@ -2,6 +2,17 @@ #include #include +typedef enum { + CANNONBALL_SHOOTING, + CANNONBALL_IMPACT, + SOUND_COUNT +} SoundID; + +const SoundAsset soundAssets[SOUND_COUNT] = { + {"assets/cannonball_shooting.mp3"}, + {"assets/cannonball_impact.mp3"} +}; + Projectiles CreateProjectiles(void) { Projectiles projectiles = {.count = MAX_PROJECTILES}; @@ -12,6 +23,8 @@ Projectiles CreateProjectiles(void) { projectiles.radius[i] = 1.0f; projectiles.active[i] = false; projectiles.color[i] = GRAY; + projectiles.soundShooting[i] = LoadSound(soundAssets[CANNONBALL_SHOOTING].path); + projectiles.soundImpact[i] = LoadSound(soundAssets[CANNONBALL_IMPACT].path); } return projectiles; @@ -25,13 +38,13 @@ void UpdateProjectiles(Projectiles *projectiles, Enemies *enemies) { if (IsKeyDown(KEY_Q) && (currentTime - lastShotTime >= reloadTime)) { for (int i = 0; i < projectiles->count; i++) { - if (!projectiles->active[i]) { projectiles->active[i] = true; Player *player = GetPlayer(); projectiles->physics[i].position = player->physics.position; projectiles->physics[i].direction = Vector2Rotate(player->physics.direction, -90.0f * DEG2RAD); + PlaySound(projectiles->soundShooting[i]); lastShotTime = currentTime; break; } @@ -46,6 +59,7 @@ void UpdateProjectiles(Projectiles *projectiles, Enemies *enemies) { projectiles->physics[i].position = player->physics.position; projectiles->physics[i].direction = Vector2Rotate(player->physics.direction, 90.0f * DEG2RAD); + PlaySound(projectiles->soundShooting[i]); lastShotTime = currentTime; break; } @@ -58,6 +72,7 @@ void UpdateProjectiles(Projectiles *projectiles, Enemies *enemies) { for (int j = 0; j < enemies->count; j++){ if (CheckCollisionCircleRec(projectiles->physics[i].position, projectiles->radius[i], enemies->sprite[j].destRec)){ + PlaySound(projectiles->soundImpact[i]); projectiles->active[i] = false; } }