feat: soundOn flag
This commit is contained in:
Vendored
+18
-2
@@ -4,20 +4,36 @@
|
|||||||
typedef struct {
|
typedef struct {
|
||||||
Music music;
|
Music music;
|
||||||
bool playing;
|
bool playing;
|
||||||
|
bool paused;
|
||||||
} Soundtrack;
|
} Soundtrack;
|
||||||
|
|
||||||
Soundtrack LoadSoundtrack(const char* musicPath){
|
Soundtrack LoadSoundtrack(const char* musicPath){
|
||||||
Soundtrack soundtrack = {
|
Soundtrack soundtrack = {
|
||||||
.music = LoadMusicStream(musicPath),
|
.music = LoadMusicStream(musicPath),
|
||||||
.playing = 0
|
.playing = false,
|
||||||
|
.paused = false
|
||||||
};
|
};
|
||||||
PlayMusicStream(soundtrack.music);
|
PlayMusicStream(soundtrack.music);
|
||||||
return soundtrack;
|
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);
|
UpdateMusicStream(soundtrack->music);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
#endif // SOUNDTRACK_H
|
#endif // SOUNDTRACK_H
|
||||||
|
|
||||||
|
|||||||
+4
-3
@@ -27,6 +27,7 @@ void ConfigApp(App* app){
|
|||||||
InitConfig(&app->config, "config/config.ini");
|
InitConfig(&app->config, "config/config.ini");
|
||||||
app->state.currentView = GetConfigInt(&app->config, "startView");
|
app->state.currentView = GetConfigInt(&app->config, "startView");
|
||||||
app->flags.showFPS = GetConfigInt(&app->config, "showFPS");
|
app->flags.showFPS = GetConfigInt(&app->config, "showFPS");
|
||||||
|
app->flags.soundOn = GetConfigInt(&app->config, "soundOn");
|
||||||
app->window.title = GetConfigString(&app->config, "window_title");
|
app->window.title = GetConfigString(&app->config, "window_title");
|
||||||
app->window.width = GetConfigInt(&app->config, "window_width");
|
app->window.width = GetConfigInt(&app->config, "window_width");
|
||||||
app->window.height = GetConfigInt(&app->config, "window_height");
|
app->window.height = GetConfigInt(&app->config, "window_height");
|
||||||
@@ -51,16 +52,16 @@ void UpdateApp(App *app){
|
|||||||
case LOGO:
|
case LOGO:
|
||||||
{
|
{
|
||||||
UpdateLogo(&app->logo, &app->state.currentView, &app->state.running);
|
UpdateLogo(&app->logo, &app->state.currentView, &app->state.running);
|
||||||
RenderLogo(&app->logo, &app->flags.showFPS);
|
RenderLogo(&app->logo, &app->flags);
|
||||||
}break;
|
}break;
|
||||||
case MENU:
|
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);
|
RenderMenu(&app->menu, &app->font, app->window.title, &app->flags);
|
||||||
}break;
|
}break;
|
||||||
case GAMEPLAY:
|
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);
|
RenderGame(&app->game, &app->state, &app->flags);
|
||||||
}break;
|
}break;
|
||||||
default: break;
|
default: break;
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
bool showFPS;
|
bool showFPS;
|
||||||
|
bool soundOn;
|
||||||
} Flags;
|
} Flags;
|
||||||
|
|
||||||
#endif // FLAGS_H
|
#endif // FLAGS_H
|
||||||
|
|||||||
+2
-2
@@ -75,7 +75,7 @@ void InitGame(GameState *g, Window *window)
|
|||||||
g->mouse = CreateMouse(0.10f, 5.0f, 10.0f, &g->textures[CURSOR]);
|
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)
|
if (GetFPS() <= 60)
|
||||||
{
|
{
|
||||||
@@ -95,7 +95,7 @@ void UpdateGame(GameState *g, View *currentView, bool *running)
|
|||||||
}
|
}
|
||||||
for (int i = 0; i < SOUNDTRACK_COUNT; i++)
|
for (int i = 0; i < SOUNDTRACK_COUNT; i++)
|
||||||
{
|
{
|
||||||
UpdateSoundtrack(&g->soundtracks[i]);
|
UpdateSoundtrack(&g->soundtracks[i], flags->soundOn);
|
||||||
}
|
}
|
||||||
|
|
||||||
UpdateMouse(&g->mouse, &g->camera);
|
UpdateMouse(&g->mouse, &g->camera);
|
||||||
|
|||||||
+2
-2
@@ -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();
|
BeginDrawing();
|
||||||
ClearBackground(RAYWHITE);
|
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));
|
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);
|
DrawFPS(10, 10);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+5
-5
@@ -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);
|
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++)
|
for (int i = 0; i < MENU_SOUNDTRACK_COUNT; i++)
|
||||||
{
|
{
|
||||||
UpdateSoundtrack(&m->soundtracks[i]);
|
UpdateSoundtrack(&m->soundtracks[i], flags->soundOn);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (GetFPS() >= 60)
|
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]))
|
if (isImageButtonClicked(&m->playButton, m->sounds[HOVER_SOUND], m->sounds[CLICK_SOUND]))
|
||||||
{
|
{
|
||||||
*running = true;
|
state->running = true;
|
||||||
*currentView = GAMEPLAY;
|
state->currentView = GAMEPLAY;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isImageButtonClicked(&m->quitButton, m->sounds[HOVER_SOUND], m->sounds[CLICK_SOUND]) || (WindowShouldClose() && !IsKeyPressed(KEY_ESCAPE)))
|
if (isImageButtonClicked(&m->quitButton, m->sounds[HOVER_SOUND], m->sounds[CLICK_SOUND]) || (WindowShouldClose() && !IsKeyPressed(KEY_ESCAPE)))
|
||||||
{
|
{
|
||||||
*running = false;
|
state->running = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
UpdateBackground(&m->background);
|
UpdateBackground(&m->background);
|
||||||
|
|||||||
Reference in New Issue
Block a user