aboutsummaryrefslogtreecommitdiffstats
path: root/src/gameScreen.c
blob: 9b37d9d7ea1877f560b3e7a7a138b13554e11655 (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
#include "gameScreen.h"
#include "game.h"
#include "assets.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
    );

    // Button pannel thingy.
    gameScreen->buttonPanelSharedAnimation = createAnimation(&assets->animations[BUTTON_BOX_ANIMATION], ANIMATION_DEFAULT_DELAY);
    playAnimation(&gameScreen->buttonPanelSharedAnimation);

    Texture* buttonTexture = &gameScreen->buttonPanelSharedAnimation.texture;
    int buttonWidth = width / 4;
    int buttonHeight = buttonWidth / 2;
    int buttonY = height - buttonHeight;

    gameScreen->upgradesButton = createTexturedButton(
        buttonTexture,
        (Rectangle){0.0, buttonY, buttonWidth, buttonHeight},
        "Upgrades",
        WHITE,
        BLACK
    );

    gameScreen->achievementsButton = createTexturedButton(
        buttonTexture,
        (Rectangle){buttonWidth, buttonY, buttonWidth, buttonHeight},
        "Achievements",
        WHITE,
        BLACK
    );

    gameScreen->rebirthButton = createTexturedButton(
        buttonTexture,
        (Rectangle){buttonWidth * 2.0, buttonY, buttonWidth, buttonHeight},
        "Rebirth",
        WHITE,
        BLACK
    );

    gameScreen->statisticsButton = createTexturedButton(
        buttonTexture,
        (Rectangle){buttonWidth * 3.0, buttonY, buttonWidth, buttonHeight},
        "Statistics",
        WHITE,
        BLACK
    );
}

void updateGameScreenShop(GameScreen* gameScreen, Game* game)
{
    Texture shopBoard = game->assets.textures[SHOP_BOARD_TEXTURE];

    DrawTexturePro(
        shopBoard,
        (Rectangle){0.0, 0.0, shopBoard.width, shopBoard.height},
        (Rectangle){0.0, 0.0, GetScreenWidth(), GetScreenHeight()},
        (Vector2){0.0, 0.0},
        0.0,
        WHITE
    );
}

void updateGameScreen(GameScreen* gameScreen, Game* 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, GetScreenWidth(), GetScreenHeight()},
        (Vector2){0.0, 0.0},
        0.0,
        WHITE
    );

    // Navigation buttons.
    if (updateTexturedButton(&gameScreen->toGameButton))
    {
        gameScreen->place = CLICKY_DESKTOP_PLACE;
    }
    if (updateTexturedButton(&gameScreen->toEmperorsEmporiumButton))
    {
        gameScreen->place = SHOP_PLACE;
    }

    // Button panel.
    runAnimation(&gameScreen->buttonPanelSharedAnimation);
    updateTexturedButton(&gameScreen->upgradesButton);
    updateTexturedButton(&gameScreen->achievementsButton);
    updateTexturedButton(&gameScreen->rebirthButton);
    updateTexturedButton(&gameScreen->statisticsButton);

    // assssssss hehehe
    switch (gameScreen->place)
    {
        case CLICKY_DESKTOP_PLACE:
             // Clickies clickies.
            updateClickies(game, &game->clickies);
            break;
        case SHOP_PLACE:
            updateGameScreenShop(gameScreen, game);
            break;
        default:
            break;
    }

    // Stones.
    char stonesBuf[30];
    snprintf(stonesBuf, sizeof(stonesBuf), "Stones: %d", game->stones);
    DrawText(stonesBuf, 10, 10, 20, BLACK);

    //DrawFPS(0, 0);
}

void closeGameScreen(GameScreen* gameScreen)
{
    closeAnimation(&gameScreen->buttonPanelSharedAnimation);
}