aboutsummaryrefslogtreecommitdiffstats
path: root/src/shop.c
blob: f1b6493720476a85c6d635e4b4ec5a06659c9178 (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
#include "shop.h"
#include "game.h"
#include "assets.h"
#include "util.h"
#include <raylib.h>

// Callbacks.
void createPenguinLolCB(ShopEntry* entry, Game* game)
{
    puts("hihihi");
}

void initShop(Shop* shop, Game* game)
{
    Assets* assets = &game->assets;

    // Entries.
    shop->penguinLol = LoadTextureFromImage(assets->animations[PENGUIN_LOL_ANIMATION].image);
    shop->entries[0] = (ShopEntry){&shop->penguinLol, 10, createPenguinLolCB};
}

void updateShop(Shop* shop, Game* game)
{
    Texture shopBoard = game->assets.textures[SHOP_BOARD_TEXTURE];

    // Board thingy.
    DrawTexturePro(
        shopBoard,
        (Rectangle){0.0, 0.0, shopBoard.width, shopBoard.height},
        (Rectangle){0.0, 0.0, WINDOW_WIDTH, WINDOW_HEIGHT},
        (Vector2){0.0, 0.0},
        0.0,
        WHITE
    );

    // Penguin thingy thing thing
    Texture yoyoyo = game->assets.textures[EMPEROR_SHOP_UI_TEXTURE];

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

    // Entry rects.
    double startX = 150.0;
    double startY = 80.0;
    double width = 100.0;
    double height = 100.0;

    Rectangle rects[SHOP_ENTRY_COUNT] = {
        (Rectangle){startX, startY, width, height}
    };

    // Entries.
    for (int i = 0; i < SHOP_ENTRY_COUNT; ++i)
    {
        Texture entryTexture = *shop->entries[i].texture;

        DrawTexturePro(
            entryTexture,
            (Rectangle){0.0, 0.0, entryTexture.width, entryTexture.height},
            rects[i],
            (Vector2){0.0, 0.0},
            0.0,
            WHITE
        );

        Color outlineColor = BLACK;

        // Test collision.
        if (CheckCollisionPointRec(getScaledMousePosition(), rects[i]))
        {
            if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON))
            {
                shop->entries[i].callback(&shop->entries[i], game);
            }
            else if (IsMouseButtonDown(MOUSE_LEFT_BUTTON))
            {
                outlineColor = BLUE;
            }
        }

        DrawRectangleLinesEx(rects[i], 2, outlineColor);
    }
}

void closeShop(Shop* shop)
{
    UnloadTexture(shop->penguinLol);
}