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 | |
parent | db67be702a0254df3284832f011217a421428bd1 (diff) | |
download | PenguinYippies-694efe00e1e01af8534672b60970a3e0555e5f34.tar.gz PenguinYippies-694efe00e1e01af8534672b60970a3e0555e5f34.tar.bz2 PenguinYippies-694efe00e1e01af8534672b60970a3e0555e5f34.zip |
Clicky buying working
Diffstat (limited to 'src')
-rw-r--r-- | src/game.c | 4 | ||||
-rw-r--r-- | src/gameCommon.h | 1 | ||||
-rw-r--r-- | src/shop.c | 26 |
3 files changed, 24 insertions, 7 deletions
@@ -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 <stdlib.h> #include <math.h> #include <string.h> +#include <time.h> #include <raylib.h> #include <raymath.h> @@ -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)) { |