Skip to content
Snippets Groups Projects
Commit 9c877ed9 authored by Paolo.Brasolin's avatar Paolo.Brasolin
Browse files

feat: #fe better difficulty ramp function

parent 2adae089
No related branches found
No related tags found
No related merge requests found
...@@ -470,22 +470,33 @@ export default class FightScene extends Phaser.Scene { ...@@ -470,22 +470,33 @@ export default class FightScene extends Phaser.Scene {
return scale / Math.pow(Math.random(), 1 / shape); return scale / Math.pow(Math.random(), 1 / shape);
} }
getDifficulty() { sawtoothRamp(t: number, peaksCount = 10, dipsHeight = 0.1, midwayAt = 0.3) {
const t = this.getGameTime(); // https://www.desmos.com/calculator/7zcb6p8qeu
if (t >= 15 * 60000) return 1; // NOTE: c'mon... 15 minutes? // NOTE: this always maps [0;1] ↦ [0;1]
// NOTE: this ranges in [0;20]x[0;10] const ramp = t * (peaksCount * dipsHeight + 1);
const progression = (t) => const dips =
(t + Math.sin((2 * Math.PI * t) / 4) + Math.sin(2 * Math.PI * t)) / 2; (-Math.floor(t * peaksCount) * (peaksCount * dipsHeight)) /
return progression((t * 15) / 20 / 60000) / 10; (peaksCount - 1);
const bend = Math.log(0.5) / Math.log(midwayAt);
return Math.pow(ramp + dips, bend);
}
getDifficulty(t: number, plateausAt = 15 * 60000) {
// NOTE: c'mon... 15 minutes?
// NOTE: this maps [0;∞] ↦ [0;10]
if (t >= plateausAt) return 1;
return this.sawtoothRamp(t / plateausAt) * 10;
} }
async spawnFoes() { async spawnFoes() {
const difficulty = this.getDifficulty(this.getGameTime());
const AVG_WPM = 40; // avg is 41.4, current world record is ~212wpm const AVG_WPM = 40; // avg is 41.4, current world record is ~212wpm
const minDelay = 60 / (5.0 * AVG_WPM); // 0.3s -> world record! const minDelay = 60 / (5.0 * AVG_WPM); // 0.3s -> world record!
const maxDelay = 60 / (0.2 * AVG_WPM); // 7.5s -> utter boredom! const maxDelay = 60 / (0.2 * AVG_WPM); // 7.5s -> utter boredom!
// const expDelay = 60 / (1.0 * AVG_WPM); // 1.5s -> average typer // const expDelay = 60 / (1.0 * AVG_WPM); // 1.5s -> average typer
const expDelay = maxDelay + (minDelay - maxDelay) * this.getDifficulty(); const expDelay = maxDelay + (minDelay - maxDelay) * difficulty;
const rate = 1 / expDelay; const rate = 1 / expDelay;
const delay = const delay =
...@@ -493,13 +504,12 @@ export default class FightScene extends Phaser.Scene { ...@@ -493,13 +504,12 @@ export default class FightScene extends Phaser.Scene {
const AVG_CPM = 200; // corresponds to AVG_WPM and AVG_CPW = 5 const AVG_CPM = 200; // corresponds to AVG_WPM and AVG_CPW = 5
// const minLength = 1; // const minLength = 1;
const minLength = Math.round(1 + (3 - 1) * this.getDifficulty()); const minLength = Math.round(1 + (3 - 1) * difficulty);
// const maxLength = 12; // const maxLength = 12;
const maxLength = Math.round(6 + (18 - 6) * this.getDifficulty()); const maxLength = Math.round(6 + (18 - 6) * difficulty);
// const expLength = AVG_CPM / AVG_WPM; // i.e. 5 char is avg // const expLength = AVG_CPM / AVG_WPM; // i.e. 5 char is avg
const expLength = const expLength = minLength + (maxLength - minLength) * difficulty;
minLength + (maxLength - minLength) * this.getDifficulty();
const scale = minLength; const scale = minLength;
const shape = expLength / (expLength - scale); const shape = expLength / (expLength - scale);
...@@ -520,8 +530,8 @@ export default class FightScene extends Phaser.Scene { ...@@ -520,8 +530,8 @@ export default class FightScene extends Phaser.Scene {
.reduce((a, b) => a + b, 0); .reduce((a, b) => a + b, 0);
const duration = const duration =
(3 + (1 - 3) * this.getDifficulty()) * (3 + (1 - 3) * difficulty) *
(expLength + (length - expLength) * this.getDifficulty()); (expLength + (length - expLength) * difficulty);
if (currentCount < maxCount && currentChars < maxChars) { if (currentCount < maxCount && currentChars < maxChars) {
await this.spawnFoe(length, duration); await this.spawnFoe(length, duration);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment