Last active
March 27, 2025 00:15
-
-
Save ninmonkey/c898bdbb8a8bc8ab21074e371011f11f to your computer and use it in GitHub Desktop.
Microtopia Hunger.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void updateHunger() { | |
// applied about every 1 second? | |
curDrain = GetCurrentDrain(); | |
energy -= curDrain // but clamps to keep it >= 0 | |
newTier = GetTier( energy ) | |
if ( newTier != curTier ) { | |
SetTier( newTier ) | |
} | |
} | |
private float GetCurrentDrain() { | |
cur = tiers[curTier] | |
prev = tiers[curTier - 1] | |
return prev.drain + (cur.drain - prev.drain ) * | |
( (energy - prev.ifBelow) / (cur.ifBelow - prev.ifBelow) ) | |
} | |
private int GetTier(float curEnergy) { | |
int i = 0; | |
foreach( curTier in tiers ) { | |
i++; | |
if( curEnergy < curTier.ifBelow ) { | |
return i; | |
} | |
} | |
curEnergy -= maxTier.ifBelow; | |
float overchargeTierPer = GlobalValues.standard.overchargeTierPer; | |
while (curEnergy >= overchargeTierPer) { | |
i++; | |
curEnergy -= overchargeTierPer; | |
} | |
return i; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment