Skip to content

Instantly share code, notes, and snippets.

@ninmonkey
Last active March 27, 2025 00:15
Show Gist options
  • Save ninmonkey/c898bdbb8a8bc8ab21074e371011f11f to your computer and use it in GitHub Desktop.
Save ninmonkey/c898bdbb8a8bc8ab21074e371011f11f to your computer and use it in GitHub Desktop.
Microtopia Hunger.md
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