diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/title.c | 71 |
1 files changed, 69 insertions, 2 deletions
diff --git a/src/title.c b/src/title.c index b2ce12b..01cc508 100644 --- a/src/title.c +++ b/src/title.c @@ -68,7 +68,7 @@ static void order_leaderboard() { return; } -static void score_screen() { +static void score_screen(Camera2D *MainCamera) { // Find leaderboard file, and open it. char *LeaderboardDirectory = SDL_GetPrefPath("iotib", "Pong"); char LeaderboardFilePath[8192]; @@ -81,10 +81,13 @@ static void score_screen() { // Init a temporary pointer to store scores and names into. This will be organized into Top10. struct LeaderboardEntries *Scores[UINT16_MAX*2]; for (int size = 0; size < (UINT16_MAX*2); size++) //If there's 131,000 entries, I dunno what to tell you. You really like pong... - Scores[size] = malloc(sizeof(struct LeaderboardEntries)); + Scores[size] = malloc(sizeof(struct LeaderboardEntries)); if(*Scores == NULL) { //Check if memory got assigned correctly. exit(1); } + for (int i = 0; i < (UINT16_MAX*2); i++) { + strcpy(Scores[i]->Name, " "); + } // Load Scores and Names int size = 0; @@ -92,6 +95,67 @@ static void score_screen() { fscanf(LeaderboardFile, "%s %d\n", Scores[a]->Name, &Scores[a]->Score); } qsort(Scores, size, sizeof(struct LeaderboardEntries *), compare_int); + + //Begin drawing scores. + + //Mouse + bool LookingAtScores = true; + bool MouseCursorIn = true; + Vector2 OldPosition = GetMousePosition(); + Vector2 NewPosition = GetMousePosition(); + Rectangle MouseCursor = {0,0,1,1}; + Texture2D MouseCursorSprite = LoadTexture("resources/cursor.png"); + + int Page = 0; + bool EndOfPages = false; + 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}; + + //Mouse + if (MouseCursorIn == true) { + OldPosition = NewPosition; + NewPosition = GetMousePosition(); + MouseCursor.y -= OldPosition.y-NewPosition.y; + MouseCursor.x -= OldPosition.x-NewPosition.x; + if (MouseCursor.y >= 720 || MouseCursor.y <= 0) { + MouseCursor.y += OldPosition.y-NewPosition.y; + } + if (MouseCursor.x >= 1280 || MouseCursor.x <= 0) { + MouseCursor.x += OldPosition.x-NewPosition.x; + } + } + + if (IsKeyPressed(KEY_ESCAPE)) { + EnableCursor(); + MouseCursorIn = false; + } else if (IsCursorOnScreen() && IsMouseButtonPressed(MOUSE_BUTTON_LEFT)) { + DisableCursor(); + MouseCursorIn = true; + } + EndOfPages = false; + BeginDrawing(); + ClearBackground(BLACK); + BeginMode2D(*MainCamera); + DrawRectangle(0, 0, 1280, 720, (Color){20, 20, 20, 255}); + DrawText("<--", 5, 720-50, 48, WHITE); + DrawText("-->", 1280-70, 720-50, 48, WHITE); + for (int i = 1; i <= 10; i++) { + if(Scores[i-1]->Name[0] != ' ') { + DrawText(TextFormat("%d. %s: %d", i, Scores[i-1]->Name, Scores[i-1]->Score), 500, 50*i, 48, WHITE); + } else { + EndOfPages = true; + } + } + DrawTexture(MouseCursorSprite, MouseCursor.x, MouseCursor.y, WHITE); + EndMode2D(); + EndDrawing(); + if(IsKeyPressed(KEY_Q)) { + return; + } + } } @@ -395,6 +459,9 @@ int title_screen() { EndMode2D(); DrawText(VersionString, GetScreenWidth()-400, GetScreenHeight()-32, 32, GREEN); EndDrawing(); + if (IsKeyPressed(KEY_D)) { + score_screen(&MainCamera); + } } Mix_HaltMusic(); Mix_FreeMusic(TitleMusic); |