so://phie

freezo

A retro platform game
git clone git://soophie.de/freezo

feat: Added sound mute button


commit: 963e99da30498506c2aa767737c83bed0e49c7ef
parent: 0619481f3da52146179ce4c102f7011515b6c52c
author: Sophie <info@soophie.de>
time: 2024-12-17 11:43

diff --git a/include/game.h b/include/game.h

index 12cec31..5db5874 100644

--- a/include/game.h

+++ b/include/game.h

1@@ -12,6 +12,7 @@ typedef struct Game game_t;

2 #include "door.h"

3

4 #define GAME_SCEEN_TIMER 150

5+#define GAME_SOUND_VOLUME 0.5f

6

7 typedef enum {

8 STATE_MENU,

9@@ -48,6 +49,7 @@ struct Game {

10 int sceen_timer;

11 door_t *door;

12 RenderTexture2D overlay;

13+ bool is_muted;

14 };

15

16 game_t *game_create(void);

17

18

diff --git a/src/game.c b/src/game.c

index 2034b44..dc9dd43 100644

--- a/src/game.c

+++ b/src/game.c

1@@ -42,12 +42,29 @@ game_t *game_create(void) {

2 .sceen_timer = 0,

3 .door = NULL,

4 .overlay = LoadRenderTexture(WINDOW_WIDTH, WINDOW_HEIGHT),

5+ .is_muted = false,

6 };

7 level_load(game, LEVEL_1);

8+ SetSoundVolume(game->assets.track, GAME_SOUND_VOLUME);

9+ SetSoundVolume(game->assets.locked, GAME_SOUND_VOLUME);

10 return game;

11 }

12

13 void game_update(game_t *game) {

14+ if (IsKeyPressed(KEY_M)) {

15+ game->is_muted = !game->is_muted;

16+ if (game->is_muted) {

17+ SetSoundVolume(game->assets.track, 0.0f);

18+ SetSoundVolume(game->assets.locked, 0.0f);

19+ }

20+ else {

21+ SetSoundVolume(game->assets.track, GAME_SOUND_VOLUME);

22+ SetSoundVolume(game->assets.locked, GAME_SOUND_VOLUME);

23+ }

24+ }

25+ if (!IsSoundPlaying(game->assets.track)) {

26+ PlaySound(game->assets.track);

27+ }

28 switch (game->state) {

29 case STATE_MENU: {

30 menu_update(game->menu, game);

31@@ -160,7 +177,16 @@ void game_draw(game_t *game) {

32 tile_draw(game->tiles[i], game);

33 }

34 for (int i = 0; i < game->entities_len; i++) {

35- entity_draw(&game->entities[i], game);

36+ entity_t *entity = &game->entities[i];

37+ if (entity->type == ENTITY_GATE || entity->type == ENTITY_DOOR) {

38+ entity_draw(entity, game);

39+ }

40+ }

41+ for (int i = 0; i < game->entities_len; i++) {

42+ entity_t *entity = &game->entities[i];

43+ if (entity->type != ENTITY_GATE && entity->type != ENTITY_DOOR) {

44+ entity_draw(entity, game);

45+ }

46 }

47 if (game->sceen_timer < 100) {

48 player_draw(game->player, game);

49@@ -183,6 +209,12 @@ void game_draw(game_t *game) {

50 for (; i < PLAYER_HEALTH / 2; i++) {

51 DrawTextureRec(game->assets.tiles, texture_rect(2, 1, TILE_WIDTH, TILE_HEIGHT), (pos_t) { TILE_WIDTH / 2.0 + i * (TILE_WIDTH + TILE_WIDTH / 4.0), TILE_WIDTH / 2.0 }, WHITE);

52 }

53+ if (game->is_muted) {

54+ DrawTextureRec(game->assets.tiles, texture_rect(5, 1, TILE_WIDTH, TILE_HEIGHT), (pos_t) { TILE_WIDTH / 2.0, WINDOW_HEIGHT - TILE_HEIGHT - TILE_HEIGHT / 2.0 }, WHITE);

55+ }

56+ else {

57+ DrawTextureRec(game->assets.tiles, texture_rect(4, 1, TILE_WIDTH, TILE_HEIGHT), (pos_t) { TILE_WIDTH / 2.0, WINDOW_HEIGHT - TILE_HEIGHT - TILE_HEIGHT / 2.0 }, WHITE);

58+ }

59 char xp_text[10];

60 snprintf(xp_text, 10, "%dXP", game->xp);

61 pos_t xp_pos = (pos_t) {

62

63

diff --git a/src/main.c b/src/main.c

index acc22a7..e581038 100644

--- a/src/main.c

+++ b/src/main.c

1@@ -25,9 +25,6 @@ void handle_segfault(int signal) {

2 game_t *game = NULL;

3

4 void do_update(void) {

5- if (!IsSoundPlaying(game->assets.track)) {

6- PlaySound(game->assets.track);

7- }

8 game_update(game);

9 game_draw(game);

10 }

11@@ -39,7 +36,6 @@ int main(void) {

12 InitWindow(WINDOW_WIDTH, WINDOW_HEIGHT, "Freezo");

13 InitAudioDevice();

14 game = game_create();

15- SetSoundVolume(game->assets.track, 0.5);

16 SetTargetFPS(60);

17 SetExitKey(0);

18 #if defined(PLATFORM_WEB)

19

20