feat: add projectiles sound effects

This commit is contained in:
2026-03-07 23:02:52 +01:00
parent aa7aeefc93
commit 7ba8890810
4 changed files with 20 additions and 2 deletions
Binary file not shown.
Binary file not shown.
+4 -1
View File
@@ -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 {
+16 -1
View File
@@ -2,6 +2,17 @@
#include <raylib.h>
#include <raymath.h>
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;
}
}