diff options
author | Charadon <dev@iotib.net> | 2022-06-09 17:16:43 -0400 |
---|---|---|
committer | Charadon <dev@iotib.net> | 2022-06-09 17:16:43 -0400 |
commit | 2d032601da11595cbb2c1fab34371d10cd184eb6 (patch) | |
tree | 5ebf843ec889f7492fff97048a411eec91bdc37a | |
parent | d8fecbb950f9e0e63fe7151c58700fc8c0e3ec98 (diff) | |
download | Pong-C-2d032601da11595cbb2c1fab34371d10cd184eb6.tar.gz |
Work on leaderboard
-rw-r--r-- | premake5.lua | 6 | ||||
-rw-r--r-- | src/flatpak/flatpak_launch.sh | 5 | ||||
-rw-r--r-- | src/marathon.c | 56 | ||||
-rw-r--r-- | src/pong.h | 1 | ||||
-rw-r--r-- | src/versus.c | 6 |
5 files changed, 62 insertions, 12 deletions
diff --git a/premake5.lua b/premake5.lua index b00e007..8e86b50 100644 --- a/premake5.lua +++ b/premake5.lua @@ -8,8 +8,8 @@ project("Pong") execute = function() os.mkdir(string.format("%s/Pong/resources", prefix)) os.executef("cp -r resources/* %s/Pong/resources/", prefix) - os.executef("install -m755 bin/*/Pong %s/Pong/pong", prefix) - os.exit(0) + os.executef("install -m755 bin/*/Pong %s/Pong/pong", prefix) + os.exit(0) end } @@ -103,6 +103,6 @@ project("Pong") then else buildoptions {"`pkgconf --cflags raylib`", "`pkgconf --cflags glfw3`", "`pkgconf --cflags gl`", "`pkgconf --cflags sdl2`", "`pkgconf --cflags SDL2_mixer`", "`pkgconf --cflags glu`"} - linkoptions {"`pkgconf --libs raylib`", "`pkgconf --libs glfw3`", "`pkgconf --libs gl`", "`pkgconf --libs sdl2`", "`pkgconf --libs SDL2_mixer`", "`pkgconf --libs glu`"} + linkoptions {"`pkgconf --libs raylib`", "`pkgconf --libs glfw3`", "`pkgconf --libs gl`", "`pkgconf --libs sdl2`", "`pkgconf --libs SDL2_mixer`", "`pkgconf --libs glu`"} end diff --git a/src/flatpak/flatpak_launch.sh b/src/flatpak/flatpak_launch.sh index 1312ef3..959858f 100644 --- a/src/flatpak/flatpak_launch.sh +++ b/src/flatpak/flatpak_launch.sh @@ -1,4 +1,5 @@ #!/bin/sh # This file is only for flatpak. -DIRECTORY="$(dirname $0)" -cd $DIRECTORY/../Pong && ./pong $@ \ No newline at end of file +DIRECTORY="$(dirname "$0")" +RUN_COMMAND='./pong $@' +cd "$DIRECTORY"/../Pong && $RUN_COMMAND \ No newline at end of file diff --git a/src/marathon.c b/src/marathon.c index 319b425..904c645 100644 --- a/src/marathon.c +++ b/src/marathon.c @@ -1,7 +1,53 @@ #include "pong.h" +#include <raylib.h> -void leaderboard_record() { - +void leaderboard_record(int Score) { + bool LeaderBoardGoing = true; + struct { + char Name[256]; + int Score; + } LeaderboardEntry; + LeaderboardEntry.Score = Score; + strcpy(LeaderboardEntry.Name, "\0"); + uint16_t CharacterNumber = 0; + int Key = 0; + while(LeaderBoardGoing == true) { + BeginDrawing(); + Key = GetKeyPressed(); + switch(Key) { + case KEY_BACKSPACE: + if(CharacterNumber != 0) { + LeaderboardEntry.Name[CharacterNumber] = '\0'; + CharacterNumber -= 1; + } + break; + case KEY_ENTER: + if(CharacterNumber != 0) { + LeaderBoardGoing = false; + } + break; + default: + if (Key >= 33 && Key <= 126) { + LeaderboardEntry.Name[CharacterNumber] = '\0'+Key; + CharacterNumber += 1; + } + break; + } + printf("%d,%s\n", CharacterNumber, LeaderboardEntry.Name); + EndDrawing(); + } + char *LeaderboardDirectory = SDL_GetPrefPath("iotib", "Pong"); + char LeaderboardFilePath[8192]; + snprintf(LeaderboardFilePath, sizeof(LeaderboardFilePath), "%s/leaderboard.txt", LeaderboardDirectory); + FILE *LeaderboardFile; + // Put save to file here. + if ((LeaderboardFile = fopen(LeaderboardFilePath, "a")) == NULL) { + fprintf(stderr, "Unable to create leaderboard file.\n"); + return; + } + fprintf(LeaderboardFile, "%s %d\n", LeaderboardEntry.Name, Score); + fclose(LeaderboardFile); + return; } void marathon_main() { @@ -86,6 +132,12 @@ void marathon_main() { //Updates hitbox with player's position. Player.HitBox.y = Player.Y; + // End Game + if(Ball.X < 0) { + leaderboard_record(Player.Score); + MarathonGoing = false; + } + BeginDrawing(); ClearBackground(BLACK); BeginMode2D(MainCamera); diff --git a/src/pong.h b/src/pong.h index 25ac56b..eef1150 100644 --- a/src/pong.h +++ b/src/pong.h @@ -14,6 +14,7 @@ #include <time.h> #include <setjmp.h> #include <string.h> +#include <stdint.h> #include "sounds.h" diff --git a/src/versus.c b/src/versus.c index 6523974..45a796d 100644 --- a/src/versus.c +++ b/src/versus.c @@ -1,9 +1,5 @@ #include "pong.h" -static void game_thread() { - -} - void versus_main() { // Init Player Variables struct Players Player; @@ -130,7 +126,7 @@ void versus_main() { //Turn Scores into strings. snprintf(PlayerScore, 50, "Player: %d", Player.Score); snprintf(EnemyScore, 50, "Enemy: %d", Enemy.Score); - + //fprintf(stdout, "%d\n", GetFPS()); BeginDrawing(); ClearBackground(BLACK); BeginMode2D(MainCamera); |