From f984ca316379a3908d15e20871d506a12b3a637e Mon Sep 17 00:00:00 2001 From: Klemen Plestenjak Date: Sun, 11 Feb 2024 10:22:09 +0100 Subject: [PATCH] Implement market --- game/systems/s_ui.c | 23 +++++++++++++++++++++++ game/ui_widgets.c | 5 +++++ game/ui_widgets.h | 1 + 3 files changed, 29 insertions(+) diff --git a/game/systems/s_ui.c b/game/systems/s_ui.c index ff410bb..cb37f83 100644 --- a/game/systems/s_ui.c +++ b/game/systems/s_ui.c @@ -217,6 +217,29 @@ void drawGameUI(Game *game, f32 dt) { } } + break; + } + if (building.type == BUILDING_MARKET) { + // 50:10 + if (uiGameTrade("Buy 50 (-10 gold)##food", foodRec, tex, playerRes->gold >= 10)) { + playerRes->food += 50; + playerRes->gold -= 10; + } + // 100:10 + if (uiGameTrade("Sell 100 (+10 gold)##food", foodRec, tex, playerRes->food >= 100)) { + playerRes->food -= 100; + playerRes->gold += 10; + } + // 50:25 + if (uiGameTrade("Buy 50 (-25 gold)##wood", woodRec, tex, playerRes->gold >= 25)) { + playerRes->wood += 50; + playerRes->gold -= 25; + } + // 100:25 + if (uiGameTrade("Sell 100 (+25 gold)##wood", woodRec, tex, playerRes->wood >= 100)) { + playerRes->wood -= 100; + playerRes->gold += 25; + } } break; } diff --git a/game/ui_widgets.c b/game/ui_widgets.c index c60244f..a99fb8e 100644 --- a/game/ui_widgets.c +++ b/game/ui_widgets.c @@ -422,6 +422,11 @@ void uiGameBuild(const char *label, Rectangle rec, Texture2D tex, bool canAfford bzUIPopParent(UI); } +bool uiGameTrade(const char *label, Rectangle rec, Texture2D tex, bool canAfford) { + bool selected = false; + uiGameBuild(label, rec, tex, canAfford, &selected); + return selected; +} bool uiGameUnit(const char *label, i32 count, Rectangle rec, Texture2D tex) { if (rec.height > 16) rec.y += 16; diff --git a/game/ui_widgets.h b/game/ui_widgets.h index dab644b..80808a2 100644 --- a/game/ui_widgets.h +++ b/game/ui_widgets.h @@ -30,6 +30,7 @@ void uiGameResCount(i32 amount, i32 capacity, Rectangle icon, Texture2D texture) void uiGameRecruit(const char *label, Rectangle rec, Texture2D tex, i32 numRecruiting, f32 progress, bool canAfford, bool *selected); void uiGameBuild(const char *label, Rectangle rec, Texture2D tex, bool canAfford, bool *selected); +bool uiGameTrade(const char *label, Rectangle rec, Texture2D tex, bool canAfford); bool uiGameUnit(const char *label, i32 count, Rectangle rec, Texture2D tex); #endif //PIXELDEFENSE_UI_WIDGETS_H