Session 11: Golden Starbloom random event (clickable bonus + production boost)

This commit is contained in:
2026-08-23 00:24:53 +00:00
parent 478b9741a7
commit 26ee47c2db
9 changed files with 465 additions and 3 deletions
+105 -2
View File
@@ -18,14 +18,26 @@ const Game = {
stellarEssence: 0,
prestigeCount: 0,
totalPrestigeEssence: 0,
prestigeUpgrades: []
prestigeUpgrades: [],
// Golden Starbloom random event state
goldenBlooms: {
active: false, // is a bloom currently visible on screen?
timer: 0, // seconds until the bloom vanishes
lastSpawn: Date.now(), // ms when we last (re)spawned one
totalClaimed: 0 // lifetime count of blooms the player has clicked
}
},
// Configuration
config: {
tickRate: 100, // ms per tick (10 ticks/sec)
autoSaveInterval: 30000, // 30 seconds
costScaling: 1.15 // Cost multiplier per building level
costScaling: 1.15, // Cost multiplier per building level
goldenBloomMinMs: 45000, // min ms between bloom spawns (45s)
goldenBloomMaxMs: 90000, // max ms between bloom spawns (90s)
goldenBloomDuration: 12, // seconds a visible bloom stays before vanishing
goldenBloomBonusMult: 15 // production-per-second worth of stardust awarded
},
/**
@@ -188,6 +200,10 @@ const Game = {
const prestigeMultiplier = PRESTIGE.getMultiplier();
production *= prestigeMultiplier;
// Apply Golden Starbloom temporary production boost (+50%)
if (this.state.productionBoostUntil && this.state.productionBoostUntil > Date.now()) {
production *= 1.5;
}
// Apply prestige upgrades
for (const upgradeId of (this.state.prestigeUpgrades || [])) {
const upgrade = PRESTIGE_UPGRADES[upgradeId];
@@ -350,6 +366,90 @@ const Game = {
return false;
},
/**
* Golden Starbloom - random event system.
* A rare, time-limited bloom occasionally appears on screen. Clicking it
* awards a stardust bonus and grants a temporary production boost.
*/
/**
* Seconds remaining until the current bloom vanishes (0 if none active).
*/
getGoldenBloomRemaining() {
return this.state.goldenBlooms.active ? Math.ceil(this.state.goldenBlooms.timer) : 0;
},
/**
* Award a Golden Starbloom bonus and apply the production multiplier.
* Called when the player clicks a visible bloom. Returns the amount earned.
*/
claimGoldenBloom(x, y) {
const state = this.state.goldenBlooms;
// No active bloom - nothing to claim.
if (!state.active) return 0;
state.active = false;
state.timer = 0;
state.totalClaimed++;
// Bonus: goldenBloomBonusMult x current production per second (min 1).
const bonus = Math.max(1, Math.floor(this.getProductionPerSecond() * this.config.goldenBloomBonusMult));
this.addStardust(bonus);
// Temporary production boost: +50% for 30 seconds.
this.state.productionBoostUntil = Date.now() + 30000;
UI.showNotification('⭐ Golden Starbloom! +' + this.formatNumber(bonus) + ' ✨', 'achievement');
Audio.playGoldenBloom();
Particles.createGoldenEffect(x, y);
UI.update();
return bonus;
},
/**
* Update golden bloom scheduling on each tick.
* Spawns a new bloom if none is active and enough time has elapsed;
* decrements the countdown of an active bloom until it vanishes.
*/
updateGoldenBloom(dtSeconds) {
const state = this.state.goldenBlooms;
// If a bloom is still on screen, count down its lifetime.
if (state.active) {
state.timer -= dtSeconds;
if (state.timer <= 0) {
state.active = false;
state.timer = 0;
}
return;
}
// Otherwise, check whether it is time to spawn the next bloom.
const elapsed = Date.now() - state.lastSpawn;
const minMs = this.config.goldenBloomMinMs;
const maxMs = this.config.goldenBloomMaxMs;
if (elapsed >= minMs) {
// Wait until somewhere in [min, max] before spawning.
if (elapsed >= maxMs || Math.random() < 0.05) {
state.active = true;
state.timer = this.config.goldenBloomDuration;
state.lastSpawn = Date.now();
UI.spawnGoldenBloom();
}
}
},
/**
* Whether the temporary production boost is currently active, and how
* many seconds remain.
*/
getProductionBoostInfo() {
const until = this.state.productionBoostUntil || 0;
if (until <= Date.now()) return { active: false, remaining: 0 };
return { active: true, remaining: Math.ceil((until - Date.now()) / 1000) };
},
/**
* Game tick - called every config.tickRate ms
*/
@@ -361,6 +461,9 @@ const Game = {
this.addStardust(production * tickSeconds);
}
// Advance the Golden Starbloom random event clock.
this.updateGoldenBloom(tickSeconds);
UI.update();
Achievements.check();
},