diff options
author | Charadon <dev@iotib.net> | 2022-06-09 20:21:26 -0400 |
---|---|---|
committer | Charadon <dev@iotib.net> | 2022-06-09 20:21:26 -0400 |
commit | ea25821768c7ac5dc7f7c0617689f6a67a88bb2a (patch) | |
tree | afb98f6c7f5585b143c8f9c9853c37518550ff95 /src/marathon.c | |
parent | 2d032601da11595cbb2c1fab34371d10cd184eb6 (diff) | |
download | Pong-C-ea25821768c7ac5dc7f7c0617689f6a67a88bb2a.tar.gz |
Begun work on organizing leaderboard
Diffstat (limited to 'src/marathon.c')
-rw-r--r-- | src/marathon.c | 79 |
1 files changed, 48 insertions, 31 deletions
diff --git a/src/marathon.c b/src/marathon.c index 904c645..064f873 100644 --- a/src/marathon.c +++ b/src/marathon.c @@ -1,39 +1,60 @@ #include "pong.h" -#include <raylib.h> void leaderboard_record(int Score) { bool LeaderBoardGoing = true; + + // Create Leaderboard struct + #define MAX_CHARACTERS 16 struct { - char Name[256]; + char Name[MAX_CHARACTERS]; int Score; } LeaderboardEntry; LeaderboardEntry.Score = Score; - strcpy(LeaderboardEntry.Name, "\0"); - uint16_t CharacterNumber = 0; + + // Init strings + int16_t CharacterNumber = 0; int Key = 0; + for(int i = 0; i < sizeof(LeaderboardEntry.Name); i++) { + LeaderboardEntry.Name[i] = '\0'; + } + char Scored[8192]; + snprintf(Scored, sizeof(Scored), "You Scored: %d", LeaderboardEntry.Score); + + // Init Camera + Camera2D MainCamera; + MainCamera.target = (Vector2){0, 0}; + MainCamera.offset = (Vector2){0, 0}; + MainCamera.rotation = 0; while(LeaderBoardGoing == true) { + MainCamera.zoom = GetScreenHeight()/720.0f; + MainCamera.offset = (Vector2){GetScreenWidth()/2.0f, GetScreenHeight()/2.0f}; + MainCamera.target = (Vector2){1280/2.0f, 720/2.0f}; + 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); + DrawRectangle(0, 0, 1280, 720, (Color){20, 20, 20, 255}); + 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 && CharacterNumber < MAX_CHARACTERS) { + LeaderboardEntry.Name[CharacterNumber] = GetCharPressed(); + CharacterNumber += 1; + } + break; + } + DrawText(Scored, 5, 0, 48, BLUE); + DrawText("Enter Name:", 5, 50, 48, WHITE); + DrawText(LeaderboardEntry.Name, 300, 50, 48, WHITE); EndDrawing(); } char *LeaderboardDirectory = SDL_GetPrefPath("iotib", "Pong"); @@ -64,6 +85,7 @@ void marathon_main() { Ball.Direction = LEFT; Ball.Speed = 3.0f; Ball.Angle = 0.0f; + Ball.NextTick = SDL_AtomicGet(&Ticks)+1; // Init Player struct Players Player; @@ -108,11 +130,6 @@ void marathon_main() { Player.Y = GetMouseY()-PaddleSprite.height/2.0f; DisableCursor(); } - - // Leave game - if(IsKeyPressed(KEY_Q)) { - MarathonGoing = false; - } if(GetMouseY() < 0) { SetMousePosition(0, 0); @@ -133,7 +150,7 @@ void marathon_main() { Player.HitBox.y = Player.Y; // End Game - if(Ball.X < 0) { + if(Ball.X < 0 || IsKeyPressed(KEY_Q)) { leaderboard_record(Player.Score); MarathonGoing = false; } |