So lets say there's a game that has a 'life bar' that consists of theoretical levels. As the user performs specific actions, depending on accuracy of their actions, the life bar grows at a corresponding speed. As it grows and goes into next levels, the criteria for desirable actions change and so the user now has to figure out what those new actions are, to keep the bar growing instead of shrinking. And while the user tries to learn which actions/patterns result in growth, things like 'time' along with undesirable actions slowly bring them back down.

I'm wondering if anyone knows of any open-source games that may have similar logic.

Or perhaps if there's a name for this type of logic so I can try and find some algorithms that may help me set something like this up.

TIA

-added
As it seems there's probably no technical term for something like this, perhaps someone can suggest some pseudo top level logic. I've never built a game before and would like to raise my chances of heading in the optimum direction.

6 Answers
6

For the purpose of this code, let's pretend that the bar holds the score for the player.

Score = Max score that can be received from the action without modifier
Accuracy = [0..1] Where 0 is total miss on the action and 1 is a perfect hit.
Example: The score for a headshot
LevelModifier = [0..1] Where 0 means that in this level, it doesn't give any
scores and 1 means that the player receives the max bonus.
You can also refer to this as a difficulty modifier.
The higher the level, the more bonus you get.
ScoreDelta = (Score * Accuracy) * LevelModifier
ScoreBar += ScoreDelta

For the timer, you can lower their ScoreBar every second.

ScoreBar -= TimePenalty

For gameplay reasons, you can reset the timer whenever the player does an action. This would reward players who kept moving.

That 'Points == 150' condition is just something I made up to demonstrate the power of the state machine. If the player does something especially good to jump from less than 100 to above 150, then he gets to skip a level. You could even have bonus levels that are only accessible in this way.

Edit: Wow, I got so engrossed in my typing, that I kinda forgot what the initial problem was. Hopefully my answer makes more sense now.

(I think most of the other answerers are interpreting your description as logarithmic growth.)

To be honest, the best way to really do this might just be trial and error. Invent a formula, not too complicated. Play with it in game. If it feels a bit chunky or stiff or floppy or whatever, adjust it, add terms, just experiment.

eventually, it will feel aesthetically pleasing. Thats what you want. It should feel like the response of the health bar follows the effort you're putting in.

Also, just by writing the game, you'll know it pretty well. Be sure and give your friends/coworkers/any random victim, a chance to try it too and determine if they feel it is aesthetically right as you do.