diff --git a/dist/index.html b/dist/index.html index e17e4e7..4e9e640 100644 --- a/dist/index.html +++ b/dist/index.html @@ -1 +1,3686 @@ -Breakout 71 \ No newline at end of file + + + + + + + Breakout 71 + + + + + + + + + + + + + diff --git a/src/game.ts b/src/game.ts index 17c22e2..1dc56a9 100644 --- a/src/game.ts +++ b/src/game.ts @@ -84,6 +84,7 @@ export function pause(playerAskedForPause: boolean) { gameState.pauseTimeout = null; document.body.className = gameState.running ? " running " : " paused "; scoreDisplay.className = ""; + gameState.needsRender=true }, Math.min(Math.max(0, gameState.pauseUsesDuringRun - 5) * 50, 500), ); @@ -455,8 +456,13 @@ export function tick() { gameState.runStatistics.runTime += timeDeltaMs; gameStateTick(gameState, frames); } - render(gameState); - recordOneFrame(gameState); + if(gameState.running || gameState.needsRender){ + gameState.needsRender=false + render(gameState); + } + if(gameState.running){ + recordOneFrame(gameState); + } requestAnimationFrame(tick); } @@ -684,6 +690,7 @@ async function openSettingsPanel() { }); if (cb) { cb(); + gameState.needsRender=true } } diff --git a/src/gameStateMutators.ts b/src/gameStateMutators.ts index 342674e..f4577a1 100644 --- a/src/gameStateMutators.ts +++ b/src/gameStateMutators.ts @@ -35,6 +35,7 @@ import { isOptionOn } from "./options"; export function setMousePos(gameState: GameState, x: number) { // Sets the puck position, and updates the ball position if they are supposed to follow it gameState.puckPosition = x; + gameState.needsRender=true } function getBallDefaultVx(gameState: GameState) { @@ -43,6 +44,7 @@ function getBallDefaultVx(gameState: GameState) { (Math.random() > 0.5 ? gameState.baseSpeed : -gameState.baseSpeed) ); } + export function resetBalls(gameState: GameState) { const count = 1 + (gameState.perks?.multiball || 0); const perBall = gameState.puckWidth / (count + 1); diff --git a/src/newGameState.ts b/src/newGameState.ts index 8ec312d..ebbf744 100644 --- a/src/newGameState.ts +++ b/src/newGameState.ts @@ -88,6 +88,8 @@ export function newGameState(params: RunParams): GameState { }, lastOffered: {}, levelTime: 0, + levelWallBounces: 0, + needsRender: true, autoCleanUses: 0, }; resetBalls(gameState); diff --git a/src/recording.ts b/src/recording.ts index bca9fc2..33d2db7 100644 --- a/src/recording.ts +++ b/src/recording.ts @@ -15,7 +15,7 @@ export function recordOneFrame(gameState: GameState) { if (!isOptionOn("record")) { return; } - if (!gameState.running) return; + // if (!gameState.running) return; if (!captureStream) return; drawMainCanvasOnSmallCanvas(gameState); if (captureTrack?.requestFrame) { diff --git a/src/types.d.ts b/src/types.d.ts index 20efae2..67fb742 100644 --- a/src/types.d.ts +++ b/src/types.d.ts @@ -190,6 +190,8 @@ export type GameState = { combo: number; // Whether the game is running or paused running: boolean; + // Whether the game should be re-rendered once even if not running + needsRender: boolean; // Position of the center of the puck on the canvas in pixels, from the left of the canvas. puckPosition: number; // Will be set if the game is about to be paused. Game pause is delayed by a few milliseconds if you pause a few times in a run,