mirror of
https://gitlab.com/lecarore/breakout71.git
synced 2025-04-21 04:26:14 -04:00
wip
This commit is contained in:
parent
47ad04c49b
commit
354a6490e9
4 changed files with 80 additions and 26 deletions
36
dist/index.html
vendored
36
dist/index.html
vendored
|
@ -964,24 +964,31 @@ function hitsSomething(x, y, radius) {
|
||||||
return hasBrick(brickIndex(x - radius, y - radius)) ?? hasBrick(brickIndex(x + radius, y - radius)) ?? hasBrick(brickIndex(x + radius, y + radius)) ?? hasBrick(brickIndex(x - radius, y + radius));
|
return hasBrick(brickIndex(x - radius, y - radius)) ?? hasBrick(brickIndex(x + radius, y - radius)) ?? hasBrick(brickIndex(x + radius, y + radius)) ?? hasBrick(brickIndex(x - radius, y + radius));
|
||||||
}
|
}
|
||||||
function tick() {
|
function tick() {
|
||||||
|
startWork('tick init');
|
||||||
const currentTick = performance.now();
|
const currentTick = performance.now();
|
||||||
const timeDeltaMs = currentTick - gameState.lastTick;
|
const timeDeltaMs = currentTick - gameState.lastTick;
|
||||||
gameState.lastTick = currentTick;
|
gameState.lastTick = currentTick;
|
||||||
let frames = Math.min(4, timeDeltaMs / (1000 / 60));
|
let frames = Math.min(4, timeDeltaMs / (1000 / 60));
|
||||||
if (gameState.keyboardPuckSpeed) (0, _gameStateMutators.setMousePos)(gameState, gameState.puckPosition + gameState.keyboardPuckSpeed);
|
if (gameState.keyboardPuckSpeed) (0, _gameStateMutators.setMousePos)(gameState, gameState.puckPosition + gameState.keyboardPuckSpeed);
|
||||||
if (gameState.perks.superhot) frames *= (0, _pureFunctions.clamp)(Math.abs(gameState.puckPosition - gameState.lastPuckPosition) / 5, 0.2 / gameState.perks.superhot, 1);
|
if (gameState.perks.superhot) frames *= (0, _pureFunctions.clamp)(Math.abs(gameState.puckPosition - gameState.lastPuckPosition) / 5, 0.2 / gameState.perks.superhot, 1);
|
||||||
|
startWork('normalizeGameState');
|
||||||
(0, _gameStateMutators.normalizeGameState)(gameState);
|
(0, _gameStateMutators.normalizeGameState)(gameState);
|
||||||
|
startWork('gameStateTick');
|
||||||
if (gameState.running) {
|
if (gameState.running) {
|
||||||
gameState.levelTime += timeDeltaMs * frames;
|
gameState.levelTime += timeDeltaMs * frames;
|
||||||
gameState.runStatistics.runTime += timeDeltaMs * frames;
|
gameState.runStatistics.runTime += timeDeltaMs * frames;
|
||||||
(0, _gameStateMutators.gameStateTick)(gameState, frames);
|
(0, _gameStateMutators.gameStateTick)(gameState, frames);
|
||||||
}
|
}
|
||||||
|
startWork('render');
|
||||||
if (gameState.running || gameState.needsRender) {
|
if (gameState.running || gameState.needsRender) {
|
||||||
gameState.needsRender = false;
|
gameState.needsRender = false;
|
||||||
(0, _render.render)(gameState);
|
(0, _render.render)(gameState);
|
||||||
}
|
}
|
||||||
|
startWork('recordOneFrame');
|
||||||
if (gameState.running) (0, _recording.recordOneFrame)(gameState);
|
if (gameState.running) (0, _recording.recordOneFrame)(gameState);
|
||||||
|
startWork('playPendingSounds');
|
||||||
if ((0, _options.isOptionOn)("sound")) (0, _sounds.playPendingSounds)(gameState);
|
if ((0, _options.isOptionOn)("sound")) (0, _sounds.playPendingSounds)(gameState);
|
||||||
|
startWork('idle');
|
||||||
requestAnimationFrame(tick);
|
requestAnimationFrame(tick);
|
||||||
FPSCounter++;
|
FPSCounter++;
|
||||||
}
|
}
|
||||||
|
@ -991,6 +998,20 @@ setInterval(()=>{
|
||||||
lastMeasuredFPS = FPSCounter;
|
lastMeasuredFPS = FPSCounter;
|
||||||
FPSCounter = 0;
|
FPSCounter = 0;
|
||||||
}, 1000);
|
}, 1000);
|
||||||
|
let total = {};
|
||||||
|
let lastTick = performance.now();
|
||||||
|
let doing = '';
|
||||||
|
function startWork(what) {
|
||||||
|
const newNow = performance.now();
|
||||||
|
if (doing) total[doing] = (total[doing] || 0) + (newNow - lastTick);
|
||||||
|
lastTick = newNow;
|
||||||
|
doing = what;
|
||||||
|
}
|
||||||
|
setInterval(()=>{
|
||||||
|
const totalTime = (0, _gameUtils.sumOfValues)(total);
|
||||||
|
console.log((0, _gameStateMutators.liveCount)(gameState.coins) + ' coins\n' + Object.entries(total).sort((a, b)=>b[1] - a[1]).filter((a)=>a[1] > 1).map((t)=>t[0] + ':' + (t[1] / totalTime * 100).toFixed(2) + '% (' + t[1] + 'ms)').join('\n'));
|
||||||
|
total = {};
|
||||||
|
}, 2000);
|
||||||
setInterval(()=>{
|
setInterval(()=>{
|
||||||
(0, _monitorLevelsUnlocks.monitorLevelsUnlocks)(gameState);
|
(0, _monitorLevelsUnlocks.monitorLevelsUnlocks)(gameState);
|
||||||
}, 500);
|
}, 500);
|
||||||
|
@ -2388,13 +2409,16 @@ parcelHelpers.export(exports, "getCurrentMaxCoins", ()=>getCurrentMaxCoins);
|
||||||
parcelHelpers.export(exports, "getCurrentMaxParticles", ()=>getCurrentMaxParticles);
|
parcelHelpers.export(exports, "getCurrentMaxParticles", ()=>getCurrentMaxParticles);
|
||||||
parcelHelpers.export(exports, "cycleMaxCoins", ()=>cycleMaxCoins);
|
parcelHelpers.export(exports, "cycleMaxCoins", ()=>cycleMaxCoins);
|
||||||
let cachedSettings = {};
|
let cachedSettings = {};
|
||||||
function getSettingValue(key, defaultValue) {
|
try {
|
||||||
if (typeof cachedSettings[key] == "undefined") try {
|
for(let key in localStorage)try {
|
||||||
const ls = localStorage.getItem(key);
|
cachedSettings[key] = JSON.parse(localStorage.getItem(key) || 'null');
|
||||||
if (ls) cachedSettings[key] = JSON.parse(ls);
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.warn(e);
|
console.warn(e);
|
||||||
}
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.warn(e);
|
||||||
|
}
|
||||||
|
function getSettingValue(key, defaultValue) {
|
||||||
return cachedSettings[key] ?? defaultValue;
|
return cachedSettings[key] ?? defaultValue;
|
||||||
}
|
}
|
||||||
function setSettingValue(key, value) {
|
function setSettingValue(key, value) {
|
||||||
|
@ -2409,13 +2433,13 @@ function getTotalScore() {
|
||||||
return getSettingValue("breakout_71_total_score", 0);
|
return getSettingValue("breakout_71_total_score", 0);
|
||||||
}
|
}
|
||||||
function getCurrentMaxCoins() {
|
function getCurrentMaxCoins() {
|
||||||
return Math.pow(2, getSettingValue("max_coins", 6)) * 200;
|
return Math.pow(2, getSettingValue("max_coins", 2)) * 200;
|
||||||
}
|
}
|
||||||
function getCurrentMaxParticles() {
|
function getCurrentMaxParticles() {
|
||||||
return getCurrentMaxCoins();
|
return getCurrentMaxCoins();
|
||||||
}
|
}
|
||||||
function cycleMaxCoins() {
|
function cycleMaxCoins() {
|
||||||
setSettingValue("max_coins", (getSettingValue("max_coins", 6) + 1) % 6);
|
setSettingValue("max_coins", (getSettingValue("max_coins", 2) + 1) % 10);
|
||||||
}
|
}
|
||||||
|
|
||||||
},{"@parcel/transformer-js/src/esmodule-helpers.js":"gkKU3"}],"gkKU3":[function(require,module,exports,__globalThis) {
|
},{"@parcel/transformer-js/src/esmodule-helpers.js":"gkKU3"}],"gkKU3":[function(require,module,exports,__globalThis) {
|
||||||
|
|
44
src/game.ts
44
src/game.ts
|
@ -27,24 +27,21 @@ import {
|
||||||
max_levels,
|
max_levels,
|
||||||
pickedUpgradesHTMl,
|
pickedUpgradesHTMl,
|
||||||
reasonLevelIsLocked,
|
reasonLevelIsLocked,
|
||||||
sample,
|
sample, sumOfValues,
|
||||||
} from "./game_utils";
|
} from "./game_utils";
|
||||||
|
|
||||||
import "./PWA/sw_loader";
|
import "./PWA/sw_loader";
|
||||||
import { getCurrentLang, languages, t } from "./i18n/i18n";
|
import { getCurrentLang, languages, t } from "./i18n/i18n";
|
||||||
import {
|
import {
|
||||||
cycleMaxCoins,
|
cycleMaxCoins,
|
||||||
cycleMaxParticles,
|
|
||||||
getCurrentMaxCoins,
|
getCurrentMaxCoins,
|
||||||
getCurrentMaxParticles,
|
|
||||||
getSettingValue,
|
getSettingValue,
|
||||||
getTotalScore,
|
getTotalScore,
|
||||||
setSettingValue,
|
setSettingValue,
|
||||||
} from "./settings";
|
} from "./settings";
|
||||||
import {
|
import {
|
||||||
forEachLiveOne,
|
forEachLiveOne,
|
||||||
gameStateTick,
|
gameStateTick, liveCount,
|
||||||
liveCount,
|
|
||||||
normalizeGameState,
|
normalizeGameState,
|
||||||
pickRandomUpgrades,
|
pickRandomUpgrades,
|
||||||
setLevel,
|
setLevel,
|
||||||
|
@ -97,7 +94,6 @@ import { runHistoryViewerMenuEntry } from "./runHistoryViewer";
|
||||||
import { getNearestUnlockHTML, openScorePanel } from "./openScorePanel";
|
import { getNearestUnlockHTML, openScorePanel } from "./openScorePanel";
|
||||||
import { monitorLevelsUnlocks } from "./monitorLevelsUnlocks";
|
import { monitorLevelsUnlocks } from "./monitorLevelsUnlocks";
|
||||||
import { levelEditorMenuEntry } from "./levelEditor";
|
import { levelEditorMenuEntry } from "./levelEditor";
|
||||||
import {toast} from "./toast";
|
|
||||||
|
|
||||||
export async function play() {
|
export async function play() {
|
||||||
if (await applyFullScreenChoice()) return;
|
if (await applyFullScreenChoice()) return;
|
||||||
|
@ -424,13 +420,15 @@ export function hitsSomething(x: number, y: number, radius: number) {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
export function tick() {
|
export function tick() {
|
||||||
|
startWork('tick init')
|
||||||
|
|
||||||
const currentTick = performance.now();
|
const currentTick = performance.now();
|
||||||
const timeDeltaMs = currentTick - gameState.lastTick;
|
const timeDeltaMs = currentTick - gameState.lastTick;
|
||||||
gameState.lastTick = currentTick;
|
gameState.lastTick = currentTick;
|
||||||
|
|
||||||
let frames = Math.min(4, timeDeltaMs / (1000 / 60));
|
let frames = Math.min(4, timeDeltaMs / (1000 / 60));
|
||||||
|
|
||||||
if (gameState.keyboardPuckSpeed) {
|
if (gameState.keyboardPuckSpeed) {
|
||||||
setMousePos(
|
setMousePos(
|
||||||
gameState,
|
gameState,
|
||||||
|
@ -444,23 +442,30 @@ export function tick() {
|
||||||
1,
|
1,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
normalizeGameState(gameState);
|
|
||||||
|
|
||||||
|
startWork('normalizeGameState')
|
||||||
|
normalizeGameState(gameState);
|
||||||
|
startWork('gameStateTick')
|
||||||
if (gameState.running) {
|
if (gameState.running) {
|
||||||
gameState.levelTime += timeDeltaMs * frames;
|
gameState.levelTime += timeDeltaMs * frames;
|
||||||
gameState.runStatistics.runTime += timeDeltaMs * frames;
|
gameState.runStatistics.runTime += timeDeltaMs * frames;
|
||||||
gameStateTick(gameState, frames);
|
gameStateTick(gameState, frames);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
startWork('render')
|
||||||
if (gameState.running || gameState.needsRender) {
|
if (gameState.running || gameState.needsRender) {
|
||||||
gameState.needsRender = false;
|
gameState.needsRender = false;
|
||||||
render(gameState);
|
render(gameState);
|
||||||
}
|
}
|
||||||
|
startWork('recordOneFrame')
|
||||||
if (gameState.running) {
|
if (gameState.running) {
|
||||||
recordOneFrame(gameState);
|
recordOneFrame(gameState);
|
||||||
}
|
}
|
||||||
|
startWork('playPendingSounds')
|
||||||
if (isOptionOn("sound")) {
|
if (isOptionOn("sound")) {
|
||||||
playPendingSounds(gameState);
|
playPendingSounds(gameState);
|
||||||
}
|
}
|
||||||
|
startWork('idle')
|
||||||
|
|
||||||
requestAnimationFrame(tick);
|
requestAnimationFrame(tick);
|
||||||
FPSCounter++;
|
FPSCounter++;
|
||||||
|
@ -468,13 +473,32 @@ export function tick() {
|
||||||
|
|
||||||
let FPSCounter = 0;
|
let FPSCounter = 0;
|
||||||
export let lastMeasuredFPS = 60;
|
export let lastMeasuredFPS = 60;
|
||||||
|
|
||||||
setInterval(() => {
|
setInterval(() => {
|
||||||
lastMeasuredFPS = FPSCounter;
|
lastMeasuredFPS = FPSCounter;
|
||||||
FPSCounter = 0;
|
FPSCounter = 0;
|
||||||
|
|
||||||
}, 1000);
|
}, 1000);
|
||||||
|
|
||||||
|
let total={}
|
||||||
|
let lastTick=performance.now();
|
||||||
|
let doing= ''
|
||||||
|
function startWork(what){
|
||||||
|
const newNow=performance.now();
|
||||||
|
if(doing) {
|
||||||
|
total[doing] = (total[doing]||0) + ( newNow-lastTick )
|
||||||
|
}
|
||||||
|
lastTick=newNow
|
||||||
|
doing=what
|
||||||
|
}
|
||||||
|
setInterval(()=>{
|
||||||
|
const totalTime = sumOfValues(total)
|
||||||
|
console.log(
|
||||||
|
liveCount(gameState.coins) +' coins\n'+
|
||||||
|
Object.entries(total).sort((a,b)=>b[1]-a[1]).filter(a=>a[1]>1).map(t=>t[0]+':'+(t[1]/totalTime*100).toFixed(2)+'% ('+t[1]+'ms)').join('\n'))
|
||||||
|
|
||||||
|
total={}
|
||||||
|
},2000)
|
||||||
|
|
||||||
|
|
||||||
setInterval(() => {
|
setInterval(() => {
|
||||||
monitorLevelsUnlocks(gameState);
|
monitorLevelsUnlocks(gameState);
|
||||||
}, 500);
|
}, 500);
|
||||||
|
|
|
@ -12,6 +12,7 @@ let mediaRecorder: MediaRecorder | null,
|
||||||
recordCanvasCtx: CanvasRenderingContext2D;
|
recordCanvasCtx: CanvasRenderingContext2D;
|
||||||
|
|
||||||
export function recordOneFrame(gameState: GameState) {
|
export function recordOneFrame(gameState: GameState) {
|
||||||
|
|
||||||
if (!isOptionOn("record")) {
|
if (!isOptionOn("record")) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,15 +2,20 @@
|
||||||
|
|
||||||
let cachedSettings: { [key: string]: unknown } = {};
|
let cachedSettings: { [key: string]: unknown } = {};
|
||||||
|
|
||||||
export function getSettingValue<T>(key: string, defaultValue: T) {
|
|
||||||
if (typeof cachedSettings[key] == "undefined") {
|
|
||||||
try {
|
try {
|
||||||
const ls = localStorage.getItem(key);
|
for(let key in localStorage){
|
||||||
if (ls) cachedSettings[key] = JSON.parse(ls) as T;
|
|
||||||
|
try {
|
||||||
|
cachedSettings[key] = JSON.parse(localStorage.getItem(key)||'null') ;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.warn(e);
|
console.warn(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
} catch (e) {
|
||||||
|
console.warn(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getSettingValue<T>(key: string, defaultValue: T) {
|
||||||
return (cachedSettings[key] as T) ?? defaultValue;
|
return (cachedSettings[key] as T) ?? defaultValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,11 +33,11 @@ export function getTotalScore() {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getCurrentMaxCoins() {
|
export function getCurrentMaxCoins() {
|
||||||
return Math.pow(2, getSettingValue("max_coins", 6)) * 200;
|
return Math.pow(2, getSettingValue("max_coins", 2)) * 200;
|
||||||
}
|
}
|
||||||
export function getCurrentMaxParticles() {
|
export function getCurrentMaxParticles() {
|
||||||
return getCurrentMaxCoins()
|
return getCurrentMaxCoins()
|
||||||
}
|
}
|
||||||
export function cycleMaxCoins() {
|
export function cycleMaxCoins() {
|
||||||
setSettingValue("max_coins", (getSettingValue("max_coins", 6) + 1) % 6);
|
setSettingValue("max_coins", (getSettingValue("max_coins", 2) + 1) % 10);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue