I was gonna explain it, but this little section of code should show a solution much quicker:
Code:
//I assume that hp and maxhp are whole integer values and that each of these variables are defined
short hp, maxhp, maxHeartsPerRow;
short cellX, cellY, cellPixelWidth, cellPixelHeight;
short wholeHeartSpriteID, emptyHeartSpriteID;
//originX and originY are the top left position to begin rendering hearts from.
short i;
short originX, originY, posX, posY;
/*
Imagine the hearts being rendered in cells like in a tile grid.
CellX, CellY refer to their cell index. Using i, the number of
hearts rendered, we can determine the position to render each heart.
*/
for (i = 0; i < maxhp; i++)
{
cellX = i % maxHeartsPerRow;
cellY = i / maxHeartsPerRow;
posX = cellX * cellPixelWidth + originX;
posY = cellY * cellPixelHeight + originY;
if (i < hp)
RenderSprite(wholeHeartSpriteID, posX, posY);
else
RenderSprite(emptyHeartSpriteID, posX, posY);
}