feat: add projectiles sound effects
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user