feat: soundOn flag

This commit is contained in:
huaqo-games
2025-10-15 21:58:42 +02:00
parent e13094e7b7
commit 88afb54082
6 changed files with 34 additions and 16 deletions
+18 -2
View File
@@ -4,20 +4,36 @@
typedef struct {
Music music;
bool playing;
bool paused;
} Soundtrack;
Soundtrack LoadSoundtrack(const char* musicPath){
Soundtrack soundtrack = {
.music = LoadMusicStream(musicPath),
.playing = 0
.playing = false,
.paused = false
};
PlayMusicStream(soundtrack.music);
return soundtrack;
}
void UpdateSoundtrack(Soundtrack *soundtrack){
void UpdateSoundtrack(Soundtrack *soundtrack, bool playing){
if (playing && !soundtrack->playing){
ResumeMusicStream(soundtrack->music);
soundtrack->paused = false;
} else if (!playing && soundtrack->playing){
PauseMusicStream(soundtrack->music);
soundtrack->paused = true;
}
soundtrack->playing = playing;
if (soundtrack->playing) {
UpdateMusicStream(soundtrack->music);
}
}
#endif // SOUNDTRACK_H
+4 -3
View File
@@ -27,6 +27,7 @@ void ConfigApp(App* app){
InitConfig(&app->config, "config/config.ini");
app->state.currentView = GetConfigInt(&app->config, "startView");
app->flags.showFPS = GetConfigInt(&app->config, "showFPS");
app->flags.soundOn = GetConfigInt(&app->config, "soundOn");
app->window.title = GetConfigString(&app->config, "window_title");
app->window.width = GetConfigInt(&app->config, "window_width");
app->window.height = GetConfigInt(&app->config, "window_height");
@@ -51,16 +52,16 @@ void UpdateApp(App *app){
case LOGO:
{
UpdateLogo(&app->logo, &app->state.currentView, &app->state.running);
RenderLogo(&app->logo, &app->flags.showFPS);
RenderLogo(&app->logo, &app->flags);
}break;
case MENU:
{
UpdateMenu(&app->menu, &app->state.currentView, &app->state.running);
UpdateMenu(&app->menu, &app->state, &app->flags);
RenderMenu(&app->menu, &app->font, app->window.title, &app->flags);
}break;
case GAMEPLAY:
{
UpdateGame(&app->game, &app->state.currentView, &app->state.running);
UpdateGame(&app->game, &app->state.currentView, &app->state.running, &app->flags);
RenderGame(&app->game, &app->state, &app->flags);
}break;
default: break;
+1
View File
@@ -3,6 +3,7 @@
typedef struct {
bool showFPS;
bool soundOn;
} Flags;
#endif // FLAGS_H
+2 -2
View File
@@ -75,7 +75,7 @@ void InitGame(GameState *g, Window *window)
g->mouse = CreateMouse(0.10f, 5.0f, 10.0f, &g->textures[CURSOR]);
}
void UpdateGame(GameState *g, View *currentView, bool *running)
void UpdateGame(GameState *g, View *currentView, bool *running, Flags *flags)
{
if (GetFPS() <= 60)
{
@@ -95,7 +95,7 @@ void UpdateGame(GameState *g, View *currentView, bool *running)
}
for (int i = 0; i < SOUNDTRACK_COUNT; i++)
{
UpdateSoundtrack(&g->soundtracks[i]);
UpdateSoundtrack(&g->soundtracks[i], flags->soundOn);
}
UpdateMouse(&g->mouse, &g->camera);
+2 -2
View File
@@ -78,7 +78,7 @@ void UpdateLogo(LogoState *l, View *currentView, bool *running) {
}
}
void RenderLogo(const LogoState *l, bool *showFPS) {
void RenderLogo(const LogoState *l, Flags *flags) {
BeginDrawing();
ClearBackground(RAYWHITE);
@@ -107,7 +107,7 @@ void RenderLogo(const LogoState *l, bool *showFPS) {
DrawText(TextSubtext("raylib", 0, l->lettersCount), GetScreenWidth() / 2 - 44, GetScreenHeight() / 2 + 48, 50, Fade(BLACK, l->alpha));
}
if (*showFPS){
if (flags->showFPS){
DrawFPS(10, 10);
}
+5 -5
View File
@@ -102,12 +102,12 @@ void InitMenu(MenuState *m)
m->quitButton = CreateImageButton(NOT_CLICKED, &m->textures[MENU_BIG_BUTTONS_TEX], &m->assets.textureAssets[MENU_BIG_BUTTONS_TEX], &quitButtonNotPressed, &quitButtonPressed, &quitButtonHover, &quitButtonDestRec);
}
void UpdateMenu(MenuState *m, View *currentView, bool *running)
void UpdateMenu(MenuState *m, State *state, Flags *flags)
{
for (int i = 0; i < MENU_SOUNDTRACK_COUNT; i++)
{
UpdateSoundtrack(&m->soundtracks[i]);
UpdateSoundtrack(&m->soundtracks[i], flags->soundOn);
}
if (GetFPS() >= 60)
@@ -117,13 +117,13 @@ void UpdateMenu(MenuState *m, View *currentView, bool *running)
if (isImageButtonClicked(&m->playButton, m->sounds[HOVER_SOUND], m->sounds[CLICK_SOUND]))
{
*running = true;
*currentView = GAMEPLAY;
state->running = true;
state->currentView = GAMEPLAY;
}
if (isImageButtonClicked(&m->quitButton, m->sounds[HOVER_SOUND], m->sounds[CLICK_SOUND]) || (WindowShouldClose() && !IsKeyPressed(KEY_ESCAPE)))
{
*running = false;
state->running = false;
}
UpdateBackground(&m->background);