diff options
author | Charadon <dev@iotib.net> | 2022-10-11 19:47:26 -0400 |
---|---|---|
committer | Charadon <dev@iotib.net> | 2022-10-11 19:47:26 -0400 |
commit | 67ac76476ccd5c7cfe9e41f023bee96345710a55 (patch) | |
tree | 79bc2a5338ed26f33d98f1505b109ba716a98439 /src | |
parent | 6dca71e96c5f38033d51343ff6c9ddded9f899fe (diff) | |
download | Pong-C-67ac76476ccd5c7cfe9e41f023bee96345710a55.tar.gz |
src/title.c: Began work on making Settings navigable with controllers
Diffstat (limited to 'src')
-rw-r--r-- | src/title.c | 92 |
1 files changed, 76 insertions, 16 deletions
diff --git a/src/title.c b/src/title.c index 9e0d4af..cacd2b0 100644 --- a/src/title.c +++ b/src/title.c @@ -1,4 +1,5 @@ #include "pong.h" +#include "sounds.h" #include <raylib.h> struct LeaderboardEntries { @@ -298,15 +299,11 @@ static void settings(Camera2D *MainCamera, Mix_Music *TitleScreenMusic) { } } - int KeyPressed = player_controls_pressed(); - - switch(KeyPressed) { + switch(player_controls_pressed()) { case CONTROLLER_ACTIVATE: - if ( OnBackButton == true ) { + if(Choice == 0) { SettingsGoing = false; } - OnBackButton = true; - Choice = 0; break; case CONTROLLER_UP: --Choice; @@ -314,8 +311,49 @@ static void settings(Camera2D *MainCamera, Mix_Music *TitleScreenMusic) { case CONTROLLER_DOWN: ++Choice; break; + case CONTROLLER_LEFT: + switch(Choice) { + case 1: + GlobalSettings.MusicVolume -= 10; + break; + case 2: + GlobalSettings.SoundVolume -= 10; + play_audio(SOUND_BOUNCE); + break; + default: + break; + } + break; + case CONTROLLER_RIGHT: + switch(Choice) { + case 1: + GlobalSettings.MusicVolume += 10; + break; + case 2: + GlobalSettings.SoundVolume += 10; + play_audio(SOUND_BOUNCE); + break; + default: + break; + } + break; + } + + + /* Prevent out-of-bounds volume settings. */ + if(GlobalSettings.MusicVolume > 100) { + GlobalSettings.MusicVolume = 100; + } else if(GlobalSettings.MusicVolume < 0) { + GlobalSettings.MusicVolume = 0; + } + if(GlobalSettings.SoundVolume > 100) { + GlobalSettings.SoundVolume = 100; + } else if(GlobalSettings.SoundVolume < 0) { + GlobalSettings.SoundVolume = 0; } + + if (IsKeyPressed(KEY_ESCAPE)) { EnableCursor(); MouseCursorIn = false; @@ -328,6 +366,23 @@ static void settings(Camera2D *MainCamera, Mix_Music *TitleScreenMusic) { BeginDrawing(); ClearBackground(BLACK); BeginMode2D(*MainCamera); + /* Draw Selection */ + OnBackButton = false; + Color MusicVolumeBarColor = DARKGRAY; + Color SoundVolumeBarColor = DARKGRAY; + switch(Choice) { + case 0: + OnBackButton = true; + break; + case 1: + MusicVolumeBarColor = YELLOW; + break; + case 2: + SoundVolumeBarColor = YELLOW; + break; + default: + break; + } DrawRectangle(0, 0, 1280, 720, (Color){20, 20, 20, 255}); /* Back Button */ if (CheckCollisionRecs(MouseCursor, BackButton) || OnBackButton == true) { @@ -340,10 +395,10 @@ static void settings(Camera2D *MainCamera, Mix_Music *TitleScreenMusic) { /* Music */ DrawText("Music Volume:", 50, 10, 42, WHITE); DrawText("<", 0,0,128,WHITE); - DrawRectangle(45, MusicBarY-5, 555, 60, DARKGRAY); + DrawRectangle(45, MusicBarY-5, 555, 60, MusicVolumeBarColor); int i = 0; for(i = 0; i < 10; i++) { - if (CheckCollisionRecs(MouseCursor, MusicBar[i]) && IsMouseButtonPressed(MOUSE_BUTTON_LEFT)) { + if(CheckCollisionRecs(MouseCursor, MusicBar[i]) && IsMouseButtonPressed(MOUSE_BUTTON_LEFT)) { GlobalSettings.MusicVolume = i*10; } if(i <= (GlobalSettings.MusicVolume/10)) { @@ -353,8 +408,7 @@ static void settings(Camera2D *MainCamera, Mix_Music *TitleScreenMusic) { /* Sound */ DrawText("Sound Volume:", 50, 108, 42, WHITE); - DrawRectangle(45, SoundBarY-5, 555, 60, DARKGRAY); - DrawText("<", 0,0,128,WHITE); + DrawRectangle(45, SoundBarY-5, 555, 60, SoundVolumeBarColor); i = 0; for(i = 0; i < 10; i++) { if (CheckCollisionRecs(MouseCursor, SoundBar[i]) && IsMouseButtonPressed(MOUSE_BUTTON_LEFT)) { @@ -456,7 +510,7 @@ int title_screen() { bool MouseCursorIn = true; bool LeaderboardButtonSelected = false; DisableCursor(); - + bool OutOfScoreScreen = false; while(TitleScreenGoing == true && GameGoing == true) { if (WindowShouldClose()) { /* Quit Game if the window is closed. */ GameGoing = false; @@ -561,6 +615,11 @@ int title_screen() { /* Activate menu item */ if( player_controls_pressed() == CONTROLLER_ACTIVATE ){ switch(Choice) { + case 1: + if(OutOfScoreScreen == false && LeaderboardButtonSelected == false) { + return(Choice); + } + break; case 2: clear_input_buffer(); settings(&MainCamera, TitleMusic); @@ -574,9 +633,6 @@ int title_screen() { TitleScreenGoing = false; GameGoing = false; break; - case -1: - TitleScreenGoing = true; - break; default: TitleScreenGoing = false; break; @@ -589,7 +645,8 @@ int title_screen() { } else if(Choice < 0) { Choice = 0; } - + + OutOfScoreScreen = false; BeginDrawing(); ClearBackground(BLACK); BeginMode2D(MainCamera); @@ -623,7 +680,7 @@ int title_screen() { DrawRectangleRec(AllScores, RED); if(player_controls_pressed() == CONTROLLER_ACTIVATE) { score_screen(&MainCamera); - Choice = -1; + OutOfScoreScreen = true; } } DrawText("See All Scores...", 600, 720-150, 48, WHITE); @@ -632,6 +689,9 @@ int title_screen() { EndMode2D(); DrawText(VersionString, GetScreenWidth()-400, GetScreenHeight()-32, 32, GREEN); EndDrawing(); + if (OutOfScoreScreen == true) { + clear_input_buffer(); + } } printf("%d\n", Choice); Mix_HaltMusic(); |