Log in

View Full Version : Need some help with some math concepts



thoth
02-17-2012, 04:11 AM
Okay, so I'm going to try to word this the best way I can and have it make sense where I'm stuck.

What I need is to make a configurable const for a location on an hp bar in %.

http://i.imgur.com/cJ1LI.png

that's the hp bar.

The full side of the hp bar is 524,175 the empty side is 408,175

what I need is basically, if there's a const like "percenttochicken = 50;" it well tell a function to calculate the coord at 50% of the distance between hp full and empty and return that x,y


So I guess I'd need to craft a function kind of like

function hppos(hppercent:integer):integer;
begin
(whateve math I can't figure out)
end;

I've been trying to wrap my head around it for a while now, and I really just can't seem to pull anything out my ass, so any help would really be appreciated.


edit:

so I was thinking about it some more, so logically it could go fullhp-emptyhp then with that number apply the percent to it, then add that result to emptyhp to spit out the result percent, but again, not sure at all how I would do this

edit2:

How can I turn an extended variable into an integer, like at the end of a function I have x = 70 but it's still extended, how can I turn x into an integer

I found a ghetto work around to this, I made it a string then I converted the string into an integer, it works but I was wondering if there's a direct way.

Er1k
02-17-2012, 06:09 AM
length is 106, so divide that by 100, supposedly 1% HP corresponds to 1.06pixel.

thoth
02-17-2012, 06:20 AM
Well I managed to get it to work, and if anyone is browsing and some kind of question that relates at all here's the code


function findhpbarx(hppercent,hpfull,hpempty:extended):inte ger;

var
r,k,y,x,z :extended;

begin
x := hppercent / 100;
z := hpfull - hpempty;
y := z * x;
k := round(y);
r := k + hpempty;
Result := StrToInt(ToStr(r));
end;