diff options
author | Charadon <dev@iotib.net> | 2022-06-08 06:08:34 -0400 |
---|---|---|
committer | Charadon <dev@iotib.net> | 2022-06-08 06:08:34 -0400 |
commit | c1811dc4241c5f89f3f3a743e35ef44c313356b5 (patch) | |
tree | 252fac43e39aa535d49aa2829dec67eee2bc45a5 /src | |
parent | 3e0948e5928e8b418cce21e8b13fd8fd21cad42e (diff) | |
download | Pong-C-c1811dc4241c5f89f3f3a743e35ef44c313356b5.tar.gz |
Settings file added
Diffstat (limited to 'src')
-rw-r--r-- | src/main.c | 37 | ||||
-rw-r--r-- | src/pong.h | 8 | ||||
-rw-r--r-- | src/title.c | 2 |
3 files changed, 47 insertions, 0 deletions
diff --git a/src/main.c b/src/main.c index 5acec18..00e23de 100644 --- a/src/main.c +++ b/src/main.c @@ -5,6 +5,8 @@ SDL_atomic_t Ticks; bool GameGoing = true; char VersionString[256]; +struct Settings GlobalSettings; + SDL_mutex *AudioQueueBeingModified; int AudioQueue[20]; @@ -40,6 +42,7 @@ int audio() { while(GameGoing == true) { for(i = 0; i < 20; i++) { if(AudioQueue[i] != -1){ + Mix_Volume(-1, GlobalSettings.SoundVolume); switch(AudioQueue[i]) { case 0: //Play bounce sound. Mix_PlayChannel(-1, Bounce, 0); @@ -121,7 +124,41 @@ int main(int argc, char *argv[]) { SDL_AtomicSet(&Ticks, 0); SDL_Thread *InternalClock = SDL_CreateThread(internal_clock, "Internal Clock", NULL); SDL_Thread *AudioThread = SDL_CreateThread(audio, "Audio", NULL); + + //Load Settings + char *SettingsDirectory = SDL_GetPrefPath("iotib.net", "Pong"); + char SettingsFilePath[8192]; + snprintf(SettingsFilePath, sizeof(SettingsFilePath), "%s/settings.txt", SettingsDirectory); + FILE *SettingsFile; + reopen: + if ((SettingsFile = fopen(SettingsFilePath, "r")) == NULL) { + if(SettingsFile != NULL) { + fclose(SettingsFile); + } + if ((SettingsFile = fopen(SettingsFilePath, "w")) == NULL) { + fprintf(stderr, "Unable to create settings file.\n"); + exit(1); + } + fprintf(SettingsFile, "sound_volume 100\n"); + fprintf(SettingsFile, "music_volume 100\n"); + fprintf(SettingsFile, "fullscreen 0"); + fclose(SettingsFile); + goto reopen; + } + char Option[2048]; + int Value; + while(!feof(SettingsFile)) { + fscanf(SettingsFile, "%s %i", Option, &Value); + if(strcmp(Option, "sound_volume") == 0) { + GlobalSettings.SoundVolume = Value; + } else if(strcmp(Option, "music_volume") == 0) { + GlobalSettings.MusicVolume = Value; + } else if(strcmp(Option, "fullscreen") == 0) { + GlobalSettings.Fullscreen = Value; + } + } + // Launch Game while (GameGoing == true) { switch(title_screen()) { diff --git a/src/pong.h b/src/pong.h index 0fe384e..74a208a 100644 --- a/src/pong.h +++ b/src/pong.h @@ -39,6 +39,14 @@ struct Balls { Rectangle HitBox; }; +struct Settings { + int SoundVolume; + int MusicVolume; + int Fullscreen; +}; + +extern struct Settings GlobalSettings; + extern int Difficulty; extern bool GameGoing; extern SDL_atomic_t Ticks; diff --git a/src/title.c b/src/title.c index d53db5a..3e85a96 100644 --- a/src/title.c +++ b/src/title.c @@ -1,6 +1,8 @@ #include "pong.h" #include "raylib.h" + + void help_text() { } |