Users browsing this thread: 2 Guest(s)
PBG's ADVENTURE! (Yeah!)
#6
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);
    }
Animations - MFGG TKO (scrapped) - tFR
[Image: QUmE6.gif]
"It feels that time is better spent on original creations" - Konjak
Focus on the performance, the idea, not the technical bits or details - Milt Kahl
Reply
Thanked by: Joxon


Messages In This Thread
PBG's ADVENTURE! (Yeah!) - by Joxon - 08-17-2015, 12:12 AM
RE: PBG's ADVENTURE! (Yeah!) - by Joxon - 08-18-2015, 07:18 PM
RE: PBG's ADVENTURE! (Yeah!) - by Joxon - 08-29-2015, 08:38 PM
RE: PBG's ADVENTURE! (Yeah!) - by TheShyGuy - 08-29-2015, 09:55 PM
RE: PBG's ADVENTURE! (Yeah!) - by Joxon - 08-29-2015, 10:12 PM
RE: PBG's ADVENTURE! (Yeah!) - by TheShyGuy - 08-29-2015, 10:56 PM
RE: PBG's ADVENTURE! (Yeah!) - by Joxon - 08-30-2015, 12:36 PM
RE: PBG's ADVENTURE! (Yeah!) - by TheShyGuy - 08-30-2015, 02:28 PM
RE: PBG's ADVENTURE! (Yeah!) - by Joxon - 08-30-2015, 02:47 PM
RE: PBG's ADVENTURE! (Yeah!) - by TheShyGuy - 08-30-2015, 03:16 PM
RE: PBG's ADVENTURE! (Yeah!) - by Joxon - 08-30-2015, 03:23 PM
RE: PBG's ADVENTURE! (Yeah!) - by TheShyGuy - 08-30-2015, 03:36 PM
RE: PBG's ADVENTURE! (Yeah!) - by Joxon - 08-30-2015, 03:38 PM
RE: PBG's ADVENTURE! (Yeah!) - by TheShyGuy - 08-30-2015, 04:08 PM
RE: PBG's ADVENTURE! (Yeah!) - by Joxon - 08-30-2015, 04:18 PM
RE: PBG's ADVENTURE! (Yeah!) - by TheShyGuy - 08-30-2015, 04:43 PM
RE: PBG's ADVENTURE! (Yeah!) - by Joxon - 08-30-2015, 04:55 PM
RE: PBG's ADVENTURE! (Yeah!) - by TheShyGuy - 08-30-2015, 04:57 PM
RE: PBG's ADVENTURE! (Yeah!) - by Joxon - 08-30-2015, 05:30 PM
RE: PBG's ADVENTURE! (Yeah!) - by TheShyGuy - 08-30-2015, 07:49 PM
RE: PBG's ADVENTURE! (Yeah!) - by Joxon - 08-30-2015, 07:52 PM
RE: PBG's ADVENTURE! (Yeah!) - by TheShyGuy - 08-30-2015, 07:59 PM
RE: PBG's ADVENTURE! (Yeah!) - by Joxon - 08-30-2015, 08:05 PM
RE: PBG's ADVENTURE! (Yeah!) - by Silversea - 09-04-2015, 12:20 AM
RE: PBG's ADVENTURE! (Yeah!) - by Joxon - 11-04-2015, 09:27 AM
RE: PBG's ADVENTURE! (Yeah!) - by Joxon - 11-07-2015, 11:14 AM

Forum Jump: