diff options
-rw-r--r-- | docs/controls/gamepad.html | 9 | ||||
-rw-r--r-- | docs/controls/keyboard.html | 18 | ||||
-rw-r--r-- | docs/controls/mouse.html | 9 | ||||
-rw-r--r-- | docs/gamemodes/marathon.html | 7 | ||||
-rw-r--r-- | docs/gamemodes/versus.html | 7 | ||||
-rw-r--r-- | docs/index.html | 24 | ||||
-rw-r--r-- | premake5.lua | 2 | ||||
-rw-r--r-- | src/title.c | 148 |
8 files changed, 159 insertions, 65 deletions
diff --git a/docs/controls/gamepad.html b/docs/controls/gamepad.html new file mode 100644 index 0000000..983364f --- /dev/null +++ b/docs/controls/gamepad.html @@ -0,0 +1,9 @@ +<html> + <button onclick="history.back()">Back</button> + <br> + <h1>Gamepad</h1> + <hr> + The game assumes your gamepad has an xbox controller layout. Up and Down on the D-Pad controls the movement of the paddle, the entire d-pad controls menus such as the title screen and the pause screen, the start button pauses the game, and the A button selects a menu item. + <br><br> + In multiplayer versus, you can use a 2nd gamepad for the second player. +</html> diff --git a/docs/controls/keyboard.html b/docs/controls/keyboard.html new file mode 100644 index 0000000..0008a9e --- /dev/null +++ b/docs/controls/keyboard.html @@ -0,0 +1,18 @@ +<html> + <button onclick="history.back()">Back</button> + <br> + <h1>Keyboard</h1> + <hr> + <ul> + <li> + Singleplayer + <br> + Up and Down controls the paddle, ESC pauses the game, Arrow Keys controls the menus such as the title screen and pause screen, and SPACE selects a menu item. + </li> + <li> + Multiplayer + <br> + W and S controls the 1st player paddle, Up and Down control the 2nd player paddle, and the rest is the same as singleplayer. + </li> + </ul> +</html> diff --git a/docs/controls/mouse.html b/docs/controls/mouse.html new file mode 100644 index 0000000..ab75977 --- /dev/null +++ b/docs/controls/mouse.html @@ -0,0 +1,9 @@ +<html> + <button onclick="history.back()">Back</button> + <br> + <h1>Mouse</h1> + <hr> + To simplify code and my sanity, the game uses a "Software Cursor". Meaning it locks the cursor to the game. While on the title screen and pause screen, you can press ESC to unlock the cursor. In gameplay, the player's paddle follows the mouse, and menu navigation is self-explainatory. + <br><br> + Mouse will NOT work with multiplayer. +</html> diff --git a/docs/gamemodes/marathon.html b/docs/gamemodes/marathon.html new file mode 100644 index 0000000..4fded3c --- /dev/null +++ b/docs/gamemodes/marathon.html @@ -0,0 +1,7 @@ +<html> + <button onclick="history.back()">Back</button> + <br> + <h1>Marathon Mode</h1> + <hr> + The goal in Marathon Mode is to hit the ball against the right edge as much as possible to get a high score. All games are saved, up to 131,000 games. You can see all scores in the game, or in the file <code>~/.local/share/iotib/Pong/leaderboard.txt</code> +</html> diff --git a/docs/gamemodes/versus.html b/docs/gamemodes/versus.html new file mode 100644 index 0000000..1acc842 --- /dev/null +++ b/docs/gamemodes/versus.html @@ -0,0 +1,7 @@ +<html> + <button onclick="history.back()">Back</button> + <br> + <h1>Versus Mode</h1> + <hr> + Versus mode can be played in two ways, singleplayer and multiplayer. In singleplayer you fight against an AI paddle, while in multiplayer you fight an opponent locally. In order to play multiplayer you need two gamepads. Alternatively, Player 1 can use the W and S keys, and Player 2 can use the arrow keys. +</html> diff --git a/docs/index.html b/docs/index.html new file mode 100644 index 0000000..e98af3c --- /dev/null +++ b/docs/index.html @@ -0,0 +1,24 @@ +<html> + <h1>Pong Manual</h1> + <hr> + <span style="font-weight: bold;"> + Table of Contents: + </span> + <ol> + <li> + Gamemodes: + <ul> + <li><a href="gamemodes/versus.html">Versus</a></li> + <li><a href="gamemodes/marathon.html">Marathon</a></li> + </ul> + </li> + <li> + Controls: + <ul> + <li><a href="controls/mouse.html">Mouse</a></li> + <li><a href="controls/gamepad.html">Gamepad</a></li> + <li><a href="controls/keyboard.html">Keyboard</a></li> + </ul> + </li> + </ol> +</html> diff --git a/premake5.lua b/premake5.lua index 6105513..b7d7f0c 100644 --- a/premake5.lua +++ b/premake5.lua @@ -7,7 +7,9 @@ project("Pong") description = "Install the game to prefix.", execute = function() os.mkdir(string.format("%s/Pong/resources", prefix)) + os.mkdir(string.format("%s/Pong/docs", prefix)) os.executef("cp -r resources/* %s/Pong/resources/", prefix) + os.executef("cp -r docs/* %s/Pong/docs", prefix) os.executef("install -m755 bin/*/Pong %s/Pong/pong", prefix) os.exit(0) end 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(); |