Struggling with a math formula

0 favourites
  • 5 posts
From the Asset Store
Math questions appear quickly on the page, so you must respond quickly to get points!
  • Okay I have been thinking really hard about this but it's making my brain explode and it is driving me nuts. I want to have a boss with a megaman health bar. the bar is a sprite with 29 frames, frame 0 is an empty bar so a full bar is frame 28 with 28 "mini bars" in it. I want the boss to be allowed to have any amount of maximum health I ever choose at any given time (it will be a set number chosen by me for each boss, but perhaps different for different bosses, however the max health of a boss won't change during the game), hundreds of points even, possibly thousands, and I want each "mini bar" to represent 1/28 of the boss' health, rounded up to the nearest possibility (so if it has only 1 or 2 health out of a gazillion, it will show frame 1). What formula would I need to set the bar's frame number? I have been thinking about this round and round and I just can't come up with it. I am sure it's simple once thought of, so could somebody please help me? Most Megaman games seem to do one hit point per mini bar, or out of always 100 health, so I don't think many of those examples out there would help, even if they are made in MMF or Game Maker (if they did what I was describing then they would indeed give me the answer).

    edit: I figured it out. It's ceil(currenthealth/maxhealth*28).

    I actually had explored this before, but it was with the width of a sprite, rather than the frame number of an animation, so I kinda got confused. sorry if this topic caused any trouble!

  • deleted

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • So the frame and health ratios are the same so:

    Health/maxHealth = frame/28

    Solving for frame:

    Frame = Health*28/maxHealth

    Next we need to round it to a whole number, and since we want frame 0 to be used only if the health is 0 we will use ceil() to round up.

    So the formula is:

    Frame = ceil(Health*28/maxHealth)

  • So the frame and health ratios are the same so:

    Health/maxHealth = frame/28

    Solving for frame:

    Frame = Health*28/maxHealth

    Next we need to round it to a whole number, and since we want frame 0 to be used only if the health is 0 we will use ceil() to round up.

    So the formula is:

    Frame = ceil(Health*28/maxHealth)

    I figured it out on my own, but thanks anyway! It seems like the majority of the people here are nice! That's another newbie problem solved! Wish me luck as I move along with my game, I might post more questions along the way!

  • yes we are here to help if we can

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)