Implement market

This commit is contained in:
2024-02-11 10:22:09 +01:00
parent 71eddd9ec2
commit f984ca3163
3 changed files with 29 additions and 0 deletions

View File

@@ -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;
}

View File

@@ -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;

View File

@@ -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