// Begin – Global State Management
const globalState = {
settingsMenuOpen: false,
musicOption: ‘on’,
difficultyOption: Difficulty.PremiumPlus,
playerScore: 0,
playerHealth: null,
enemiesKilled: {
brute: 0,
spam: 0,
malware: 0,
tracker: 0,
marc1n: 0,
},
};
const difficultyMultipliers = (difficultyOption) => {
switch (difficultyOption) {
case ‘free’:
return 2;
case ‘premium’:
return 1.5;
case ‘premium plus’:
return 1;
default:
return 1;
}
}
const getGlobalState = () => ({ …globalState });
const setGlobalState = (newGlobalState) => {
Object.assign(globalState, newGlobalState);
notifySubscribers();
};
const subscribers = [];
const subscribe = (subscriber) => {
subscribers.push(subscriber);
};
const notifySubscribers = () => {
subscribers.forEach((subscriber) => subscriber(getGlobalState()));
};
// End – Global State Management
const k = kaboom({
scale: 1,
background: [0, 0, 0],
})
const pubsub = new PubSub();
const sounds = new Sounds();
const enemyGenerator = new EnemyGenerator();
loadAssets()
getFont(‘pixelFont’)
const scenes = {
[SceneNames.room]: setRoom,
[SceneNames.title]: setTitle,
[SceneNames.credits]: setCredits,
[SceneNames.creditsCC]: setCreditsCC,
[SceneNames.theEnd]: setTheEnd,
[SceneNames.outro]: setOutro,
};
Object.entries(scenes).forEach(sceneData => scene(…sceneData));
pubsub.subscribe(PubSubEvents.BruteDied, () => {
setGlobalState({ playerScore: globalState.playerScore + baseBruteAttributes.scoreValue * difficultyMultipliers(getGlobalState().difficultyOption)})
setGlobalState({ enemiesKilled: { …globalState.enemiesKilled, brute: globalState.enemiesKilled.brute + 1 } });
})
pubsub.subscribe(PubSubEvents.SpamDied, () => {
setGlobalState({ playerScore: globalState.playerScore + baseSpamAttributes.scoreValue * difficultyMultipliers(getGlobalState().difficultyOption)})
setGlobalState({ enemiesKilled: { …globalState.enemiesKilled, spam: globalState.enemiesKilled.spam + 1 } });
})
pubsub.subscribe(PubSubEvents.MalwareDied, () => {
setGlobalState({ playerScore: globalState.playerScore + baseMalwareAttributes.scoreValue * difficultyMultipliers(getGlobalState().difficultyOption)})
setGlobalState({ enemiesKilled: { …globalState.enemiesKilled, malware: globalState.enemiesKilled.malware + 1 } });
})
pubsub.subscribe(PubSubEvents.TrackerDied, () => {
setGlobalState({ playerScore: globalState.playerScore + baseTrackerAttributes.scoreValue * difficultyMultipliers(getGlobalState().difficultyOption)})
setGlobalState({ enemiesKilled: { …globalState.enemiesKilled, tracker: globalState.enemiesKilled.tracker + 1 } });
})
pubsub.subscribe(PubSubEvents.BossDied, () => {
setGlobalState({ playerScore: globalState.playerScore + baseMarc1nAttributes.scoreValue * difficultyMultipliers(getGlobalState().difficultyOption)})
setGlobalState({ enemiesKilled: { …globalState.enemiesKilled, marc1n: globalState.enemiesKilled.marc1n + 1 } });
sounds.stopBossBGM();
setTimeout(() => {
sounds.stopAllSounds();
sounds.reloadBossBGM();
pubsub.unsubscribe(PubSubEvents.LevelCleared, levelClearedSubscriptionToken);
go(SceneNames.outro);
}, 4000)
})
go(SceneNames.title);