diff options
author | nathansmith117 <thenathansmithsmith@gmail.com> | 2024-03-11 18:24:16 +0000 |
---|---|---|
committer | nathansmith117 <thenathansmithsmith@gmail.com> | 2024-03-11 18:24:16 +0000 |
commit | 694efe00e1e01af8534672b60970a3e0555e5f34 (patch) | |
tree | 4ea7fe8da78627f4f24b4d5447ce92c91b4715ea /src/shop.c | |
parent | db67be702a0254df3284832f011217a421428bd1 (diff) | |
download | PenguinYippies-694efe00e1e01af8534672b60970a3e0555e5f34.tar.gz PenguinYippies-694efe00e1e01af8534672b60970a3e0555e5f34.tar.bz2 PenguinYippies-694efe00e1e01af8534672b60970a3e0555e5f34.zip |
Clicky buying working
Diffstat (limited to 'src/shop.c')
-rw-r--r-- | src/shop.c | 26 |
1 files changed, 23 insertions, 3 deletions
@@ -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)) { |