Skip to content

Instantly share code, notes, and snippets.

@EpicPuppy613
Created March 29, 2022 22:27
Show Gist options
  • Save EpicPuppy613/93e7d461154e2f99dd548cd046548a36 to your computer and use it in GitHub Desktop.
Save EpicPuppy613/93e7d461154e2f99dd548cd046548a36 to your computer and use it in GitHub Desktop.
document.getElementById('debug').innerHTML = 'preinit';
const G = {};
G.level = Decimal(0);
G.xp = Decimal(0);
G.need = Decimal(1000);
document.getElementById('debug').innerHTML = 'init';
G.percent = 0;
G.gain = Decimal(2);
document.getElementById('debug').innerHTML = 'postinit';
const E = {};
E.level = document.getElementById('curlvl');
E.prog = document.getElementById('lvlprog');
E.bar = document.getElementById('barprog');
E.icon = document.getElementById('icon');
E.bug = document.getElementById('debug');
const icons = [0, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95];
function Main() {
E.bug.innerHTML = 'start';
G.xp = G.xp.add(G.gain);
E.bug.innerHTML = 'xpgain';
if (G.xp.gte(G.need)) {
E.bug.innerHTML = 'levelup';
G.level = G.level.add(1);
G.xp = Decimal(0);
G.need = G.need.mul(2);
}
E.bug.innerHTML = 'percent';
G.percent = G.xp.div(G.need).mul(100).toFixed(1);
E.bug.innerHTML = 'update';
UpdateUI();
}
function UpdateUI() {
E.level.innerHTML = 'Level ' + G.level.toString();
E.prog.innerHTML = G.percent + '%';
E.bar.style.width = G.percent + '%';
document.title = G.percent + '% - Level ' + G.level.toString();
var high = 0;
for (const val of icons) {
if (G.xp.div(G.need).mul(100) >= val) {
high = val;
}
}
E.icon.href = 'icon/' + high + '.png';
}
G.loop = setInterval(Main, 20);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment