diff --git a/src/world/items.c b/src/world/items.c index 2cfadcb..3e1e937 100644 --- a/src/world/items.c +++ b/src/world/items.c @@ -154,12 +154,20 @@ static void dropBattery(int x, int y) void addRandomItems(int x, int y) { - if (rand() % 100 < 25) + int cherryChance, batteryChance; + + cherryChance = 100 - getPercent(world.bob->health, world.bob->healthMax); + batteryChance = 100 - getPercent(world.bob->power, world.bob->powerMax); + + cherryChance = MIN(cherryChance, 50); + batteryChance = MIN(batteryChance, 50); + + if (rand() % 100 < cherryChance) { dropRandomCherry(x, y); } - if (rand() % 100 < 50) + if (rand() % 100 < batteryChance) { dropBattery(x, y); } diff --git a/src/world/items.h b/src/world/items.h index e0a59c6..5feec8c 100644 --- a/src/world/items.h +++ b/src/world/items.h @@ -26,6 +26,7 @@ extern Sprite *getSprite(char *name); extern Item *initBattery(void); extern Item *initCherry(void); extern int rrnd(int low, int high); +extern int getPercent(float current, float total); extern World world;