about summary refs log tree commit diff stats
path: root/src/title.c
blob: 2f8148df33332172a92384a1bca8c1191284c460 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#include "pong.h"
#include "raylib.h"



void help_text() {

}

int title_screen() {
    // Init Camera
    Camera2D MainCamera;
    MainCamera.offset = (Vector2){0,0};
    MainCamera.target = (Vector2){0,0};
    MainCamera.rotation = 0.0f;

    bool TitleScreenGoing = true;
    int Choice = 0;

    // Selection
    Rectangle Versus = {
        20, 150, 230, 48
    };
    Rectangle Marathon = {
        20, 200, 230, 48
    };
    Rectangle Settings = {
        20, 250, 230, 48
    };
    Rectangle Help = {
        20, 300, 230, 48
    };
    Rectangle Exit = {
        20, 350, 230, 48
    };
    Rectangle Mouse = {
        0, 0, 10, 10
    };
    Rectangle *Selected;
    Selected = &Versus;
    EnableCursor();

    //Music
    Mix_Music *TitleMusic = Mix_LoadMUS("resources/title.wav");
    Mix_PlayMusic(TitleMusic, 1);
    Mix_VolumeMusic(GlobalSettings.MusicVolume);

    while(TitleScreenGoing == true && GameGoing == true) {
        
        if (WindowShouldClose()) { //Quit Game if the window is closed.
            GameGoing = false;
            TitleScreenGoing = false;
        }

        MainCamera.zoom = GetScreenHeight()/720.0f;
        Mouse.x = GetMouseX()/MainCamera.zoom;
        Mouse.y = GetMouseY()/MainCamera.zoom;
        if (CheckCollisionRecs(Mouse, Versus)) {
            Selected = &Versus;
            if (IsMouseButtonPressed(MOUSE_BUTTON_LEFT)) {
                Choice = 0;
                TitleScreenGoing = false;
            }
        } else if (CheckCollisionRecs(Mouse, Marathon)) {
            Selected = &Marathon;
            if (IsMouseButtonPressed(MOUSE_BUTTON_LEFT)) {
                Choice = 1;
                TitleScreenGoing = false;
            }
        } else if (CheckCollisionRecs(Mouse, Settings)) {
            Selected = &Settings;
        } else if (CheckCollisionRecs(Mouse, Help)) {
            Selected = &Help;
        } else if (CheckCollisionRecs(Mouse, Exit)) {
            Selected = &Exit;
            if (IsMouseButtonPressed(MOUSE_BUTTON_LEFT)) {
                GameGoing = false;
                return -1;
            }
        }
        BeginDrawing();
            ClearBackground(BLACK);
            BeginMode2D(MainCamera);
                DrawRectangleRec(*Selected, RED);
                DrawText("PONG", 0, 0, 128, WHITE);
                DrawText("Versus", 20, 150, 48, WHITE);
                DrawText("Marathon", 20, 200, 48, WHITE);
                DrawText("Settings", 20, 250, 48, WHITE);
                DrawText("Help", 20, 300, 48, WHITE);
                DrawText("Exit", 20, 350, 48, WHITE);
            EndMode2D();
            DrawText(VersionString, GetScreenWidth()-400, GetScreenHeight()-32, 32, GREEN);
        EndDrawing();
    }
    Mix_HaltMusic();
    Mix_FreeMusic(TitleMusic);
    return Choice;
}