Skip to content

Commit

Permalink
add: sound
Browse files Browse the repository at this point in the history
  • Loading branch information
savalet committed Nov 28, 2024
1 parent 1977697 commit d234985
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 1 deletion.
Binary file added assets/shoot.wav
Binary file not shown.
3 changes: 3 additions & 0 deletions include/hunter.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#ifndef HUNTER_H_
#define HUNTER_H_
#include <SFML/Audio.h>
#include <SFML/Graphics.h>
#define EXIT_FAILURE 84
#define EXIT_SUCCESS 0
Expand Down Expand Up @@ -51,6 +52,7 @@ typedef struct {
sprite_t cursor;
sprite_t ducks[DUCK_NBR];
sprite_t ammos[AMMO_COUNT];
sfMusic *shoot_sound;
sfEvent *event;
int score;
int shoot;
Expand Down Expand Up @@ -88,4 +90,5 @@ int change_ammo_version(hunterinfo_t *, int);
int get_score(hunterinfo_t *);
int post_score(hunterinfo_t *);
int display_game_over(hunterinfo_t *);
int create_sounds(hunterinfo_t *);
#endif
2 changes: 2 additions & 0 deletions src/hunter.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ void destroy_all(hunterinfo_t *hf)
sfFont_destroy(hf->score_text.font);
sfText_destroy(hf->game_over_text.text);
sfFont_destroy(hf->game_over_text.font);
sfMusic_destroy(hf->shoot_sound);
sfSprite_destroy(hf->background.sprite);
sfTexture_destroy(hf->background.texture);
sfSprite_destroy(hf->tree.sprite);
Expand Down Expand Up @@ -115,6 +116,7 @@ void draw_all(hunterinfo_t *hf)
draw_tree(hf);
fill_ducks(hf);
fill_ammos(hf);
create_sounds(hf);
draw_cursor(hf);
draw_score(hf);
create_clock(hf);
Expand Down
16 changes: 16 additions & 0 deletions src/renderer/sound.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
** EPITECH PROJECT, 2024
** __
** File description:
** _
*/

#include "hunter.h"

int create_sounds(hunterinfo_t *hf)
{
hf->shoot_sound = sfMusic_createFromFile("assets/shoot.wav");
if (!hf->shoot_sound)
return EXIT_FAILURE;
return EXIT_SUCCESS;
}
3 changes: 2 additions & 1 deletion src/window/window_manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ void reload(hunterinfo_t *hf)
static
void kill_duck(hunterinfo_t *hf, int i)
{
hf->ammos[hf->ammo].touched = 1;
hf->ducks[i].version = 3;
hf->ducks[i].touched = (move_duck(hf, (sfVector2f){ 0, 0 }, i), 1);
hf->score += 100;
Expand All @@ -67,6 +68,7 @@ void shoot(hunterinfo_t *hf)
hf->shoot++;
hf->ammo--;
hf->ammos[hf->ammo].sprite = NULL;
sfMusic_play(hf->shoot_sound);
for (int i = 0; i < DUCK_NBR; i++) {
if (pos.x < hf->ducks[i].pos.x || pos.x >
(hf->ducks[i].pos.x + hf->ducks[i].size.x) || pos.y <
Expand All @@ -75,7 +77,6 @@ void shoot(hunterinfo_t *hf)
hf->ducks[i].sprite == NULL || hf->ducks[i].touched ||
hf->ammos[hf->ammo].touched)
continue;
hf->ammos[hf->ammo].touched = 1;
kill_duck(hf, i);
}
}
Expand Down

0 comments on commit d234985

Please sign in to comment.