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/game.c | 4 ---- src/gameCommon.h | 1 + src/shop.c | 26 +++++++++++++++++++++++--- 3 files changed, 24 insertions(+), 7 deletions(-) diff --git a/src/game.c b/src/game.c index 2fc068e..cfbfbea 100644 --- a/src/game.c +++ b/src/game.c @@ -20,10 +20,6 @@ void initGame(Game* game) Clicky testClicky = createPenguinLolClicky(game); addClickyToClickies(&game->clickies, testClicky); - testClicky = createPenguinLolClicky(game); - testClicky.rect.x += 500; - addClickyToClickies(&game->clickies, testClicky); - game->screenTexture = LoadRenderTexture(WINDOW_WIDTH, WINDOW_HEIGHT); game->stones = 0; diff --git a/src/gameCommon.h b/src/gameCommon.h index ceca8b8..d0e8284 100644 --- a/src/gameCommon.h +++ b/src/gameCommon.h @@ -2,6 +2,7 @@ #include #include #include +#include #include #include 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