about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
authorCharadon <dev@iotib.net>2022-06-25 01:55:56 -0400
committerCharadon <dev@iotib.net>2022-06-25 01:55:56 -0400
commitbc664e9a94271463e35e26a7c988757469986ad7 (patch)
tree36a920e2767b10406ca4faa467bf604f602444b1 /src
parentc020a309846d9d20be1badd28e592da161d1761f (diff)
downloadPong-C-bc664e9a94271463e35e26a7c988757469986ad7.tar.gz
Added a manual
Diffstat (limited to 'src')
-rw-r--r--src/title.c148
1 files changed, 83 insertions, 65 deletions
diff --git a/src/title.c b/src/title.c
index 43b2eed..2183588 100644
--- a/src/title.c
+++ b/src/title.c
@@ -1,4 +1,5 @@
 #include "pong.h"
+#include <raylib.h>
 
 struct LeaderboardEntries {
     int Score;
@@ -117,8 +118,8 @@ static void score_screen(Camera2D *MainCamera) {
     while(LookingAtScores == true && GameGoing == true) {
         /* Update Camera */
         MainCamera->zoom = GetScreenHeight()/720.0f;
-	MainCamera->offset = (Vector2){GetScreenWidth()/2.0f, GetScreenHeight()/2.0f};
-	MainCamera->target = (Vector2){1280/2.0f, 720/2.0f};
+		MainCamera->offset = (Vector2){GetScreenWidth()/2.0f, GetScreenHeight()/2.0f};
+		MainCamera->target = (Vector2){1280/2.0f, 720/2.0f};
 
         /* Mouse */
         if (MouseCursorIn == true) {
@@ -145,17 +146,17 @@ static void score_screen(Camera2D *MainCamera) {
         BeginDrawing();
             ClearBackground(BLACK);
             BeginMode2D(*MainCamera);
-                DrawRectangle(0, 0, 1280, 720, (Color){20, 20, 20, 255});
-		/* Scores */
-		int a = 0;
-		int i = 0;
-                for (i = 1+(10*Page); i <= 10+(10*Page); i++, a++) {
-                    if(Scores[i-1]->Name[0] != ' ') {
-                        DrawText(TextFormat("%d. %s: %d", i, Scores[i-1]->Name, Scores[i-1]->Score), 460, 60+(50*a), 48, WHITE);
-                    } else {
-                        EndOfPages = true;
-                    }
+            DrawRectangle(0, 0, 1280, 720, (Color){20, 20, 20, 255});
+			/* Scores */
+			int a = 0;
+			int i = 0;
+            for (i = 1+(10*Page); i <= 10+(10*Page); i++, a++) {
+	            if(Scores[i-1]->Name[0] != ' ') {
+            	    DrawText(TextFormat("%d. %s: %d", i, Scores[i-1]->Name, Scores[i-1]->Score), 460, 60+(50*a), 48, WHITE);
+                } else {
+                	EndOfPages = true;
                 }
+            }
 		/* Page Buttons */
 		if(CheckCollisionRecs(MouseCursor, PrevPage) && Page > 0) {
 			DrawRectangleRec(PrevPage, RED);
@@ -243,9 +244,10 @@ static void settings(Camera2D *MainCamera, Mix_Music *TitleScreenMusic) {
     Texture2D MouseCursorSprite = LoadTexture("resources/cursor.png");
     bool MouseCursorIn = true;
     while(SettingsGoing == true && GameGoing == true) {
+
         MainCamera->zoom = GetScreenHeight()/720.0f;
         MainCamera->offset = (Vector2){GetScreenWidth()/2.0f, GetScreenHeight()/2.0f};
-	MainCamera->target = (Vector2){1280/2.0f, 720/2.0f};
+		MainCamera->target = (Vector2){1280/2.0f, 720/2.0f};
 	
         /* Mouse */
         if (MouseCursorIn == true) {
@@ -286,7 +288,7 @@ static void settings(Camera2D *MainCamera, Mix_Music *TitleScreenMusic) {
             DrawText("Music Volume:", 50, 10, 42, WHITE);
             DrawText("<", 0,0,128,WHITE);
             DrawRectangle(45, MusicBarY-5, 555, 60, DARKGRAY);
-	    int i = 0;
+	    	int i = 0;
             for(i = 0; i < 10; i++) {
                 if (CheckCollisionRecs(MouseCursor, MusicBar[i]) && IsMouseButtonPressed(MOUSE_BUTTON_LEFT)) {
                     GlobalSettings.MusicVolume = i*10;
@@ -300,7 +302,9 @@ static void settings(Camera2D *MainCamera, Mix_Music *TitleScreenMusic) {
             DrawText("Sound Volume:", 50, 108, 42, WHITE);
             DrawRectangle(45, SoundBarY-5, 555, 60, DARKGRAY);
             DrawText("<", 0,0,128,WHITE);
+			i = 0;
             for(i = 0; i < 10; i++) {
+				printf("%d\n", i);
                 if (CheckCollisionRecs(MouseCursor, SoundBar[i]) && IsMouseButtonPressed(MOUSE_BUTTON_LEFT)) {
                     play_audio(SOUND_BOUNCE);
                     GlobalSettings.SoundVolume = i*10;
@@ -329,7 +333,8 @@ static void settings(Camera2D *MainCamera, Mix_Music *TitleScreenMusic) {
             DrawText("Windowed", 100, 242, 42, WHITE);
             DrawText("Fullscreen", 100, 284, 42, WHITE);
             DrawText("Borderless", 100, 326, 42, WHITE);
-	    DrawTexture(MouseCursorSprite, MouseCursor.x, MouseCursor.y, WHITE);
+	    	DrawTexture(MouseCursorSprite, MouseCursor.x, MouseCursor.y, WHITE);
+			DrawRectangleRec(MouseCursor, WHITE);
         EndMode2D();
         EndDrawing();
     }
@@ -349,10 +354,6 @@ static void settings(Camera2D *MainCamera, Mix_Music *TitleScreenMusic) {
     return;
 }
 
-static void help_text() {
-
-}
-
 int title_screen() {
     /* Init Camera */
     Camera2D MainCamera;
@@ -404,13 +405,12 @@ int title_screen() {
     DisableCursor();
 
     while(TitleScreenGoing == true && GameGoing == true) {
-        
         if (WindowShouldClose()) { /* Quit Game if the window is closed. */
             GameGoing = false;
             TitleScreenGoing = false;
         }
 	
-	/* Update Camera */
+		/* Update Camera */
         MainCamera.zoom = GetScreenHeight()/720.0f;
 	    MainCamera.offset = (Vector2){GetScreenWidth()/2.0f, GetScreenHeight()/2.0f};
 	    MainCamera.target = (Vector2){1280/2.0f, 720/2.0f};
@@ -440,7 +440,6 @@ int title_screen() {
 		} else if(Choice < 0) {
 			Choice = 0;
 		}
-        
         if (IsKeyPressed(KEY_ESCAPE)) {
             EnableCursor();
             MouseCursorIn = false;
@@ -448,39 +447,57 @@ int title_screen() {
             DisableCursor();
             MouseCursorIn = true;
         }
-
-        if (CheckCollisionRecs(Mouse, Versus) || Choice == 0) {
-            Selected = &Versus;
-            Choice = 0;
-            if (IsMouseButtonPressed(MOUSE_BUTTON_LEFT) || IsKeyPressed(KEY_SPACE) || IsGamepadButtonPressed(0, GAMEPAD_BUTTON_RIGHT_FACE_DOWN)) {
-                TitleScreenGoing = false;
-            }
-        } 
-		if (CheckCollisionRecs(Mouse, Marathon) || Choice == 1) {
-            Selected = &Marathon;
-            Choice = 1;
-            if (IsMouseButtonPressed(MOUSE_BUTTON_LEFT) || IsKeyPressed(KEY_SPACE) || IsGamepadButtonPressed(0, GAMEPAD_BUTTON_RIGHT_FACE_DOWN)) {
-                TitleScreenGoing = false;
-            }
-        }
-		if (CheckCollisionRecs(Mouse, Settings) || Choice == 2) {
-            Selected = &Settings;
-        	Choice = 2;
-            if (IsMouseButtonPressed(MOUSE_BUTTON_LEFT) || IsKeyPressed(KEY_SPACE) || IsGamepadButtonPressed(0, GAMEPAD_BUTTON_RIGHT_FACE_DOWN)) {
-                settings(&MainCamera, TitleMusic);
-            }
-        }
-		if (CheckCollisionRecs(Mouse, Help) || Choice == 3) {
-            Selected = &Help;
+		/* Mouse */
+		if(CheckCollisionRecs(Mouse, Versus)) {
+			Choice = 0;
+		} else if(CheckCollisionRecs(Mouse, Marathon)) {
+			Choice = 1;
+		} else if(CheckCollisionRecs(Mouse, Settings)) {
+			Choice = 2;
+		} else if(CheckCollisionRecs(Mouse, Help)) {
 			Choice = 3;
-        }
-		if (CheckCollisionRecs(Mouse, Exit) || Choice == 4) {
-            Selected = &Exit;
+		} else if(CheckCollisionRecs(Mouse, Exit)) {
 			Choice = 4;
-            if (IsMouseButtonPressed(MOUSE_BUTTON_LEFT)) {
-                GameGoing = false;
-            }
-        }
+		}
+
+		/* Select Menu Item */
+		switch(Choice) {
+			case 0:
+            	Selected = &Versus;
+				break;
+			case 1:
+            	Selected = &Marathon;
+				break;
+			case 2:
+            	Selected = &Settings;
+				break;
+			case 3:
+            	Selected = &Help;
+				break;
+			case 4:
+            	Selected = &Exit;
+				break;
+			default:
+				break;
+        } /* Activate menu item */
+		if(((CheckCollisionRecs(Mouse, *Selected) && IsMouseButtonPressed(MOUSE_BUTTON_LEFT)) || IsKeyPressed(KEY_SPACE) || IsGamepadButtonPressed(0, GAMEPAD_BUTTON_RIGHT_FACE_DOWN))) {
+			switch(Choice) {
+				case 2:
+					settings(&MainCamera, TitleMusic);
+					break;
+				case 3:
+					OpenURL("docs/index.html");
+					EnableCursor();
+					break;
+				case 4:
+					TitleScreenGoing = false;
+					GameGoing = false;
+				default:
+					TitleScreenGoing = false;
+					break;
+			}
+		}
+
         BeginDrawing();
             ClearBackground(BLACK);
             BeginMode2D(MainCamera);
@@ -493,13 +510,14 @@ int title_screen() {
                 DrawText("Settings", 20, 250, 48, WHITE);
                 DrawText("Help", 20, 300, 48, WHITE);
                 DrawText("Exit", 20, 350, 48, WHITE);
+				DrawRectangleRec(Mouse, WHITE);
                 if(Choice == 1) {
                     DrawText("Leaderboard:", 600, 0, 48, WHITE);
                     if(NoScores == 1) {
                         goto skip;
                     }
                     char LeaderboardText[1024];
-		    int i = 1;
+		    		int i = 1;
                     for (i = 1; i <= 10; i++) {
                         if(Top10[i-1].Name[0] != '\0') { /* If name is blank, that means we're at the end of the list. */
                             snprintf(LeaderboardText, sizeof(LeaderboardText), "%d: %s : %d", i, Top10[i-1].Name, Top10[i-1].Score);
@@ -507,19 +525,19 @@ int title_screen() {
                         }
                     }
                 }
-		skip:
-		if (Choice == 1) {
-			if(CheckCollisionRecs(Mouse, AllScores)) {
-				DrawRectangleRec(AllScores, RED);
-				if(IsMouseButtonPressed(MOUSE_BUTTON_LEFT)) {
-					score_screen(&MainCamera);
+				skip:
+				if (Choice == 1) {
+					if(CheckCollisionRecs(Mouse, AllScores)) {
+						DrawRectangleRec(AllScores, RED);
+						if(IsMouseButtonPressed(MOUSE_BUTTON_LEFT)) {
+							score_screen(&MainCamera);
+						}
+					}
+					DrawText("See All Scores...", 600, 720-150, 48, WHITE);
 				}
-			}
-			DrawText("See All Scores...", 600, 720-150, 48, WHITE);
-		}
             	DrawTexture(MouseCursor, Mouse.x, Mouse.y, WHITE);
-            EndMode2D();
-            DrawText(VersionString, GetScreenWidth()-400, GetScreenHeight()-32, 32, GREEN);
+        	EndMode2D();
+        	DrawText(VersionString, GetScreenWidth()-400, GetScreenHeight()-32, 32, GREEN);
         EndDrawing();
     }
     Mix_HaltMusic();