From 694efe00e1e01af8534672b60970a3e0555e5f34 Mon Sep 17 00:00:00 2001 From: nathansmith117 Date: Mon, 11 Mar 2024 12:24:16 -0600 Subject: Clicky buying working --- src/shop.c | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) (limited to 'src/shop.c') 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 +#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)) { -- cgit v1.2.3