aboutsummaryrefslogtreecommitdiffstats
path: root/src/main.cpp
blob: 40dae712e2b28c813daa2cccb37f11e0251d6901 (plain)
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
/*********************************/
/*   THRESHOLD        (  //      */
/*   main              ( )/      */
/*   by salade         )(/       */
/*  ________________  ( /)       */
/* ()__)____________)))))   :^}  */
/*********************************/

#include <raylib.h>  // basic libs
#include <fstream>
#include <iostream>
#include "gameplay.hpp"
#include "window.hpp"

#include <filesystem>  // additional libs
#include <map>

gameState gs = TITLE;

std::map<int, std::string> pick;

int main(void) {
    initWindow();
    InitWindow(SCREENWIDTH, SCREENHEIGHT, "WIP -- muchashooter THRESHOLD");
    auto nPick = 0;
    Texture2D background;
    Game* game = nullptr;
    std::ofstream ifs("../meta/maps/savestate");

    std::string path = "../meta/maps";
    int i = 0;
    for (const auto& entry :
         std::filesystem::directory_iterator(path)) {  // NOTE: c++17 lol
        if (entry.path().filename().generic_string().find("start") !=
            std::string::npos) {
            pick[i] = entry.path().filename().generic_string();
            i++;
        }
    }
    // Main game loop
    while (!WindowShouldClose()) /* Detect window close button or ESC key */
    {
        switch (gs) {
            case (TITLE): {
                if (IsKeyPressed(KEY_ENTER)) {
                    gs = PICK;
                }
                break;
            }
            case (PICK): {
                if (IsKeyPressed(KEY_ENTER)) {
                    std::string s(path);
                    s += "/";
                    s += pick[nPick];
                    game = new Game(s);
                    background = LoadTexture(game->getBackground().c_str());
                    gs = GAMEPLAY;
                    game->start();
                }
                if (IsKeyPressed(KEY_DOWN) && nPick < (pick.size() - 1)) {
                    nPick++;
                }
                if (IsKeyPressed(KEY_UP) && nPick > 0) {
                    nPick--;
                }
            }
            case (DEATH): {
                if (IsKeyPressed(KEY_ENTER)) {
                    auto current = game->getCurrent();

                    delete game;
                    CloseAudioDevice();
                    game = new Game(current);
                    gs = GAMEPLAY;
                }
                break;
            }
            case (GAMEPLAY): {
                break;
            }
            case (NEXT): {
                if (IsKeyPressed(KEY_ENTER)) {
                    std::string next("../meta/maps/");
                    next += game->getNext();
                    ifs << game->getCurrent();

                    delete game;
                    CloseAudioDevice();
                    std::cout << "next level " << next << std::endl;
                    if (game->getNext() != "0") {
                        game = new Game(next);
                        gs = GAMEPLAY;
                    }
                }
                break;
            }
            case (ENDING): {
                if (IsKeyPressed(KEY_ENTER)) {
                    gs = TITLE;
                    auto current = game->getCurrent();
                    delete game;
                    CloseAudioDevice();
                    game = new Game(current);
                }
                break;
            }
        }
        BeginDrawing();

        // ClearBackground(COOLPURPLE);

        switch (gs) {
            case (TITLE): {
                ClearBackground(COOLPURPLE);
                DrawRectangle(200, 100, 1200, 700, RAYWHITE);
                DrawRectangle(250, 150, 1100, 600, COOLPURPLE);
                DrawText("THRESHOLD", 260, 160, 30, RAYWHITE);
                DrawRectangle(300, 200, 1000, 500, RAYWHITE);
                DrawText("PRESS ENTER", (SCREENWIDTH / 2) - 140,
                         (SCREENHEIGHT / 2) + 50, 40, MAROON);
                break;
            }
            case (PICK): {
                ClearBackground(COOLPURPLE);
                DrawRectangle(200, 100, 1200, 700, RAYWHITE);
                DrawRectangle(250, 150, 1100, 600, COOLPURPLE);
                DrawRectangle(300, 200, 1000, 500, RAYWHITE);
                DrawText("THRESHOLD", 260, 160, 30, RAYWHITE);

                DrawRectangle(350, 240 + (nPick * 40), 900, 50, PURPLE);
                for (auto n = 0; n < pick.size(); n++) {
                    DrawText(pick[n].c_str(), 400, 240 + (n * 40), 40,
                             COOLPURPLE);
                }
                break;
            }
            case (DEATH): {
                DrawRectangle(250, 150, 1100, 600, COOLPURPLE);
                ClearBackground(COOLPURPLE);
                DrawCircle(SCREENWIDTH / 2, SCREENHEIGHT / 2, 200, BLACK);
                DrawText("YOU DIED", (SCREENWIDTH / 2) - 200,
                         (SCREENHEIGHT / 2) - 50, 40, WHITE);
                DrawText(game->getCurrent().c_str(), (SCREENWIDTH / 2) - 100,
                         (SCREENHEIGHT / 2) + 50, 40, WHITE);
                break;
            }
            case (GAMEPLAY): {
                DrawTexture(background, 0, 0, WHITE);
                if (auto code = game->getKeys()) {
                    if (code == 1)  // death
                    {
                        gs = DEATH;
                    } else if (code == 2)  // level end
                    {
                        gs = NEXT;
                    }
                }
                // BeginMode2D(game->cam); // I think this might be useless
                // NOTE: it was lol
                game->draw();
                break;
            }
            case (NEXT): {
                ClearBackground(COOLPURPLE);
                DrawRectangle(200, 100, 1200, 700, RAYWHITE);
                DrawRectangle(250, 150, 1100, 600, COOLPURPLE);
                DrawRectangle(300, 200, 1000, 500, RAYWHITE);
                DrawText("THRESHOLD", 260, 160, 30, RAYWHITE);
                DrawText("CONGRATULATIONS\n", 350, 240, 30, COOLPURPLE);
                DrawText("KILLS :", 350, 280, 30, COOLPURPLE);
                auto kills = std::to_string(game->getKills());
                DrawText(kills.c_str(), 460, 280, 30, RED);
                DrawText("NEXT LEVEL :\n", 350, 360, 30, COOLPURPLE);
                auto next = game->getNext();
                DrawText(next.c_str(), 460, 400, 30, RED);

                break;
            }
            case (ENDING): {
                DrawCircle(SCREENWIDTH / 2, SCREENHEIGHT / 2, 200, BLACK);
                DrawText("GOOD BYE", (SCREENWIDTH / 2) - 100, SCREENHEIGHT / 2,
                         40, WHITE);
                break;
            }
        }
        EndDrawing();
    }
    ifs.close();
    CloseWindow();
    return 0;
}