aboutsummaryrefslogtreecommitdiffstats
path: root/src/shop.c
diff options
context:
space:
mode:
authornathansmith117 <thenathansmithsmith@gmail.com>2024-03-11 18:24:16 +0000
committernathansmith117 <thenathansmithsmith@gmail.com>2024-03-11 18:24:16 +0000
commit694efe00e1e01af8534672b60970a3e0555e5f34 (patch)
tree4ea7fe8da78627f4f24b4d5447ce92c91b4715ea /src/shop.c
parentdb67be702a0254df3284832f011217a421428bd1 (diff)
downloadPenguinYippies-694efe00e1e01af8534672b60970a3e0555e5f34.tar.gz
PenguinYippies-694efe00e1e01af8534672b60970a3e0555e5f34.tar.bz2
PenguinYippies-694efe00e1e01af8534672b60970a3e0555e5f34.zip
Clicky buying working
Diffstat (limited to 'src/shop.c')
-rw-r--r--src/shop.c26
1 files changed, 23 insertions, 3 deletions
diff --git a/src/shop.c b/src/shop.c
index f1b6493..465bd7a 100644
--- a/src/shop.c
+++ b/src/shop.c
@@ -2,12 +2,21 @@
#include "game.h"
#include "assets.h"
#include "util.h"
-#include <raylib.h>
+#include "clicky.h"
// Callbacks.
void createPenguinLolCB(ShopEntry* entry, Game* game)
{
- puts("hihihi");
+ 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)
@@ -19,6 +28,17 @@ void initShop(Shop* shop, Game* game)
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];
@@ -76,7 +96,7 @@ void updateShop(Shop* shop, Game* game)
{
if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON))
{
- shop->entries[i].callback(&shop->entries[i], game);
+ buyThingFromShop(shop, i, game);
}
else if (IsMouseButtonDown(MOUSE_LEFT_BUTTON))
{