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
|
#include "shop.h"
#include "game.h"
#include "assets.h"
#include "util.h"
#include "clicky.h"
// Callbacks.
void createPenguinLolCB(ShopEntry* entry, Game* game)
{
SetRandomSeed(clock());
int randomX = GetRandomValue(200, WINDOW_WIDTH - 200);
int randomY = GetRandomValue(200, WINDOW_HEIGHT - 200);
Clicky lol = createPenguinLolClicky(game);
lol.rect.x = randomX;
lol.rect.y = randomY;
addClickyToClickies(&game->clickies, lol);
}
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 buyThingFromShop(Shop* shop, int id, Game* game)
{
int cost = shop->entries[id].cost;
if (game->stones >= cost)
{
shop->entries[id].callback(&shop->entries[id], game);
game->stones -= cost;
}
}
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))
{
buyThingFromShop(shop, i, game);
}
else if (IsMouseButtonDown(MOUSE_LEFT_BUTTON))
{
outlineColor = BLUE;
}
}
DrawRectangleLinesEx(rects[i], 2, outlineColor);
}
}
void closeShop(Shop* shop)
{
UnloadTexture(shop->penguinLol);
}
|