Treasure is a fun part of any RPG. In a game as simple as Heroine Dusk the treasure needs to stand out as a main incentive. Early in the game you spend a lot of time collecting a handful of coins from beginner enemies, but later you receive hoards of gold from each creature.
To make this more interesting I wanted to display the exact amount of treasure gained. When the player gets two coins, they should see exactly two coins. I could create a single coin icon and display N random coins, but that won't look interesting. I could also create unique images for every individual value, but that's too much effort.
My solution was to create icons that represent powers-of-two values in coins. The images starting with precise coin counts and end with abstract treasure objects:
Next I chose to position each of the ten icons above into a single massive pile. I chose fixed positions for each icon, but an advanced method might dynamically create these positions. I made sure to not overlap the icons too much while still keeping them close enough to make a cohesive pile.
Ten treasure icons set to fixed positions and sort order
To display the treasure I check the bits of the total gold amount (via Bitwise And). The icons are ordered from back to front so the pile renders correctly.
// arranged in treasure pile draw order if (display_value & 128) treasure_render_gold_icon(7); if (display_value & 512) treasure_render_gold_icon(9); if (display_value & 32) treasure_render_gold_icon(5); if (display_value & 16) treasure_render_gold_icon(4); if (display_value & 8) treasure_render_gold_icon(3); if (display_value & 1) treasure_render_gold_icon(0); if (display_value & 4) treasure_render_gold_icon(2); if (display_value & 64) treasure_render_gold_icon(6); if (display_value & 2) treasure_render_gold_icon(1); if (display_value & 256) treasure_render_gold_icon(8);
And here you can test the results. With ten icons I can display treasures up to 1023 coins in value, which may be enough for Heroine Dusk. Of course, each icon I add will double the total gold value I can display.
Gold amount to display:
I hope you found this interesting! My favorite part of game development is combining art and code to solve technical challenges.