about summary refs log tree commit diff stats
path: root/src/title.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/title.c')
-rw-r--r--src/title.c82
1 files changed, 79 insertions, 3 deletions
diff --git a/src/title.c b/src/title.c
index 6066797..04cf0ca 100644
--- a/src/title.c
+++ b/src/title.c
@@ -3,6 +3,7 @@
 static void settings(Camera2D *MainCamera, Mix_Music *TitleScreenMusic) {
     bool SettingsGoing = true;
     int MusicBarY = 50;
+    int SoundBarY = 150;
 
     Rectangle MouseCursor = {
         0,0,1,1
@@ -20,13 +21,48 @@ static void settings(Camera2D *MainCamera, Mix_Music *TitleScreenMusic) {
         {490,MusicBarY,50,50},
         {545,MusicBarY,50,50},
     };
+    
+    Rectangle SoundBar[10] = {
+        {50,SoundBarY,50,50},
+        {105,SoundBarY,50,50},
+        {160,SoundBarY,50,50},
+        {215,SoundBarY,50,50},
+        {270,SoundBarY,50,50},
+        {325,SoundBarY,50,50},
+        {380,SoundBarY,50,50},
+        {435,SoundBarY,50,50},
+        {490,SoundBarY,50,50},
+        {545,SoundBarY,50,50},
+    };
+
+    // Back Selection
+    Rectangle BackButton = {
+        0,0,42,120
+    };
+
+    //Screen Buttons
+    int ScreenButtonLength = 250;
+    Rectangle ScreenButtons[3] = {
+        {95, 242, ScreenButtonLength, 42},
+        {95, 284, ScreenButtonLength, 42},
+        {95, 326, ScreenButtonLength, 42}
+    };
+    SetMousePosition(GetScreenWidth()/2, GetScreenHeight()/2);
     while(SettingsGoing == true && GameGoing == true) {
-        MouseCursor.x = GetMouseX();
-        MouseCursor.y = GetMouseY();
+        MainCamera->zoom = GetScreenHeight()/720.0f;
+        MouseCursor.x = GetMouseX()/MainCamera->zoom;
+        MouseCursor.y = GetMouseY()/MainCamera->zoom;
         Mix_VolumeMusic(GlobalSettings.MusicVolume);
         BeginDrawing();
         ClearBackground(BLACK);
         BeginMode2D(*MainCamera);
+            // Back Button
+            if (CheckCollisionRecs(MouseCursor, BackButton)) {
+                DrawRectangleRec(BackButton, RED);
+                if (IsMouseButtonPressed(MOUSE_BUTTON_LEFT)) {
+                    SettingsGoing = false;
+                }
+            }
 
             // Music
             DrawText("Music Volume:", 50, 10, 42, WHITE);
@@ -41,12 +77,52 @@ static void settings(Camera2D *MainCamera, Mix_Music *TitleScreenMusic) {
             }
 
             // Sound
-
+            DrawText("Sound Volume:", 50, 108, 42, WHITE);
+            DrawText("<", 0,0,128,WHITE);
+            for(int i = 0; i < 10; i++) {
+                if (CheckCollisionRecs(MouseCursor, SoundBar[i]) && IsMouseButtonPressed(MOUSE_BUTTON_LEFT)) {
+                    play_audio(SOUND_BOUNCE);
+                    GlobalSettings.SoundVolume = i*10;
+                }
+                if(i <= (GlobalSettings.SoundVolume/10)) {
+                    DrawRectangleRec(SoundBar[i], RED);
+                }
+            }
             // Fullscreen
+            bool MouseHovering = false;
+            for(int i = 0; i < 3; i++) {
+                if(CheckCollisionRecs(MouseCursor, ScreenButtons[i])) {
+                    DrawRectangleRec(ScreenButtons[i], RED);
+                    MouseHovering = true;
+                    if (IsMouseButtonPressed(MOUSE_BUTTON_LEFT)) {
+                        GlobalSettings.Fullscreen = i;
+                        set_screen_mode();
+                    }
+                }
+            }
+            if (MouseHovering == false) {
+                DrawRectangleRec(ScreenButtons[GlobalSettings.Fullscreen], GREEN);
+            }
+            DrawText("Screen Mode:", 50, 205, 42, WHITE);
+            DrawText("Windowed", 100, 242, 42, WHITE);
+            DrawText("Fullscreen", 100, 284, 42, WHITE);
+            DrawText("Borderless", 100, 326, 42, WHITE);
         EndMode2D();
         EndDrawing();
     }
+    char *SettingsDirectory = SDL_GetPrefPath("iotib", "Pong");
+	char SettingsFilePath[8192];
+	snprintf(SettingsFilePath, sizeof(SettingsFilePath), "%s/settings.txt", SettingsDirectory);
+	FILE *SettingsFile;
     // Put save to file here.
+    if ((SettingsFile = fopen(SettingsFilePath, "w")) == NULL) {
+        fprintf(stderr, "Unable to create settings file.\n");
+        exit(1);
+    }
+    fprintf(SettingsFile, "sound_volume %d\n", GlobalSettings.SoundVolume);
+    fprintf(SettingsFile, "music_volume %d\n", GlobalSettings.MusicVolume);
+    fprintf(SettingsFile, "fullscreen %d", GlobalSettings.Fullscreen);
+    fclose(SettingsFile);
     return;
 }