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 /src/marathon.c | |
parent | d8fecbb950f9e0e63fe7151c58700fc8c0e3ec98 (diff) | |
download | Pong-C-2d032601da11595cbb2c1fab34371d10cd184eb6.tar.gz |
Work on leaderboard
Diffstat (limited to 'src/marathon.c')
-rw-r--r-- | src/marathon.c | 56 |
1 files changed, 54 insertions, 2 deletions
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); |