aboutsummaryrefslogtreecommitdiffstats
path: root/src/gameScreen.c
blob: a735b584ce77bcdfb0dff5e21e519fa1d614ee05 (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
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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
#include "gameScreen.h"
#include "game.h"
#include "assets.h"
#include "util.h"
#include "clicky.h"
#include "shooterScreen.h"
#include <raylib.h>

void initGameScreen(GameScreen* gameScreen, Game* game)
{
    gameScreen->place = CLICKY_DESKTOP_PLACE;

    Assets* assets = &game->assets;
    int width = WINDOW_WIDTH;
    int height = WINDOW_HEIGHT;
    int navigationButtonSize = 100;
    int navigationButtonX = width - navigationButtonSize - 5.0;

    // Navigation buttons.
    gameScreen->toGameButton = createTexturedButton(
        &assets->textures[TO_GAME_ICON_TEXTURE],
        (Rectangle){navigationButtonX, 5.0, navigationButtonSize, navigationButtonSize},
        "",
        WHITE,
        BLACK
    );

    gameScreen->toEmperorsEmporiumButton = createTexturedButton(
        &assets->textures[TO_EMPERORS_EMPORIUM_ICON_TEXTURE],
        (Rectangle){navigationButtonX, navigationButtonSize + 15.0, navigationButtonSize, navigationButtonSize},
        "",
        WHITE,
        BLACK
    );

    initShop(&gameScreen->shop, game);

    setGameScreenTool(gameScreen, CLICKER_TOOL);
}

void updateGameScreenClickyDesktop(GameScreen* gameScreen, Game* game)
{
    // Clickies clickies.
    updateClickies(game, &game->clickies);
}

void updateGameScreenNavigation(GameScreen* gameScreen, Game* game)
{
    // Navigation buttons.
    if (updateTexturedButton(&gameScreen->toGameButton))
    {
        gameScreen->place = CLICKY_DESKTOP_PLACE;
    }
    if (updateTexturedButton(&gameScreen->toEmperorsEmporiumButton))
    {
        gameScreen->place = SHOP_PLACE;
    }
}

void setGameScreenTool(GameScreen* gameScreen, ToolId tool)
{
    gameScreen->tool = tool;

    // TODO: Switch cursor for different tools
    switch (tool)
    {
        case CLICKER_TOOL:
            break;
        case BOOPER_TOOL:
            break;
        default:
            break;
    }
}

void updateGameScreenTool(GameScreen* gameScreen, Game* game)
{
    ToolId tool = gameScreen->tool;
    Clickies* clickies = &game->clickies;

    switch (tool)
    {
        case CLICKER_TOOL:
            // Nothing lmao.
            break;
        case BOOPER_TOOL:

            for (int i = 0; i < clickies->clickiesCount; ++i)
            {
                Rectangle rect = clickies->clickies[i].rect;

                if (CheckCollisionPointRec(getScaledMousePosition(), rect))
                {
                    // Draw silly outline.
                    Color colorOptions[] = {YELLOW, PINK, BLACK, BLUE, PURPLE, MAGENTA, RED};
                    SetRandomSeed(time(NULL));
                    int colorIndex = GetRandomValue(0, sizeof(colorOptions) / sizeof(Color) - 1);
                    Color color = colorOptions[colorIndex];

                    DrawRectangleLinesEx(rect, colorIndex + 1, color);

                    if (IsMouseButtonPressed(MOUSE_BUTTON_LEFT))
                    {
                        removeClickyFromClickies(clickies, i);
                    }

                    break; // Only one at a time.
                }
            }

            break;
        default:
            break;
    }
}

void updateGameScreenToolBar(GameScreen* gameScreen, Game* game)
{
    int toolIconWidth = 50;
    int toolIconHeight = 50;

    Assets* assets = &game->assets;

    Texture toolTextures[TOOL_COUNT] = {
        assets->textures[CLICKER_TOOL_TEXTURE],
        assets->textures[BOOPER_TOOL_TEXTURE]
    };

    for (int i = 0; i < TOOL_COUNT; ++i)
    {
        Rectangle rect = (Rectangle){i * toolIconWidth + 200, 0.0, toolIconWidth, toolIconHeight};
        Texture texture = toolTextures[i];

        // Draw tool texture.
        DrawTexturePro(
            texture,
            (Rectangle){0.0, 0.0, texture.width, texture.height},
            rect,
            (Vector2){0.0, 0.0},
            0.0,
            WHITE
        );

        // Outline current tool
        if (i == gameScreen->tool)
        {
            DrawRectangleLinesEx(rect, 3, BLACK);
        }
        else // Switch tools.
        {
            if (IsMouseButtonPressed(MOUSE_BUTTON_LEFT) && CheckCollisionPointRec(getScaledMousePosition(), rect))
            {
                setGameScreenTool(gameScreen, i);
            }
        }
    }
}

void updateGameScreen(GameScreen* gameScreen, Game* game)
{

    // Testy shooter.
    if(IsKeyPressed(KEY_S))
    {
        enterShooterScreen(game);
    }

     // Draw background.
    Texture background = game->assets.textures[MAIN_SCREEN_BACKGROUND_TEXTURE];

    DrawTexturePro(
        background,
        (Rectangle){0.0, 0.0, background.width, background.height},
        (Rectangle){0.0, 0.0, WINDOW_WIDTH, WINDOW_HEIGHT},
        (Vector2){0.0, 0.0},
        0.0,
        WHITE
    );

    // assssssss hehehe
    switch (gameScreen->place)
    {
        case CLICKY_DESKTOP_PLACE:
            updateGameScreenClickyDesktop(gameScreen, game);
            break;
        case SHOP_PLACE:
            updateShop(&gameScreen->shop, game);
            break;
        default:
            break;
    }

    // Stones.
    Texture stoneTexture = game->assets.textures[STONE_TEXTURE];

    DrawTexturePro(
        stoneTexture,
        (Rectangle){5.0, 5.0, stoneTexture.width, stoneTexture.height},
        (Rectangle){0.0, 0.0, 35.0, 35.0},
        (Vector2){0.0, 0.0},
        0.0,
        WHITE
    );

    char stonesBuf[30];
    snprintf(stonesBuf, sizeof(stonesBuf), "%d", game->stones);
    DrawText(stonesBuf, 40.0, 5.0, 30, BLACK);

    updateGameScreenNavigation(gameScreen, game);
    updateGameScreenTool(gameScreen, game); // This should go before tool bar update because of how clicks work.
    updateGameScreenToolBar(gameScreen, game);
}

void closeGameScreen(GameScreen* gameScreen)
{
    closeShop(&gameScreen->shop);
}