Tuesday, December 22, 2009

User Mania = X + (100-X)/2, where X <100


Last night I figured out what, for me, was a bit of challenging math. Here's the story. In my interactive novel, each reader has stats. Each choice readers make on a page makes the stats go up or down. One of the stats is mania/depression. When the novel starts, you're at 50%/50%. I had to figure out a way to have the stat go up or down without reaching 100. One way to do this would be with two variables, $mania & $depression, where each could be incremented based on the user's choice, then averaged to find the percentage. For example:

$mania = 50
$depression = 50

User's choice:
$depression = $depression + 10

Percentage for new depression = ($depression / ($depression+$mania))*100

That, however, requires two variables, and it will likely never give very extreme percentages, which is always more fun. So I came up with these formulae to use one variable that'll never reach 0 or 100:

to increase: $depression = $depression + (100-$depression)/2
to decrease: $depression = $depression - $depression/2

No comments:

Post a Comment