mirror of
https://gitlab.com/lecarore/breakout71.git
synced 2025-04-21 04:26:14 -04:00
Re-introduced power saving mode
This commit is contained in:
parent
9bf7e9534d
commit
bdfe5408b9
6 changed files with 3702 additions and 4 deletions
3687
dist/index.html
vendored
3687
dist/index.html
vendored
File diff suppressed because one or more lines are too long
11
src/game.ts
11
src/game.ts
|
@ -84,6 +84,7 @@ export function pause(playerAskedForPause: boolean) {
|
||||||
gameState.pauseTimeout = null;
|
gameState.pauseTimeout = null;
|
||||||
document.body.className = gameState.running ? " running " : " paused ";
|
document.body.className = gameState.running ? " running " : " paused ";
|
||||||
scoreDisplay.className = "";
|
scoreDisplay.className = "";
|
||||||
|
gameState.needsRender=true
|
||||||
},
|
},
|
||||||
Math.min(Math.max(0, gameState.pauseUsesDuringRun - 5) * 50, 500),
|
Math.min(Math.max(0, gameState.pauseUsesDuringRun - 5) * 50, 500),
|
||||||
);
|
);
|
||||||
|
@ -455,8 +456,13 @@ export function tick() {
|
||||||
gameState.runStatistics.runTime += timeDeltaMs;
|
gameState.runStatistics.runTime += timeDeltaMs;
|
||||||
gameStateTick(gameState, frames);
|
gameStateTick(gameState, frames);
|
||||||
}
|
}
|
||||||
render(gameState);
|
if(gameState.running || gameState.needsRender){
|
||||||
recordOneFrame(gameState);
|
gameState.needsRender=false
|
||||||
|
render(gameState);
|
||||||
|
}
|
||||||
|
if(gameState.running){
|
||||||
|
recordOneFrame(gameState);
|
||||||
|
}
|
||||||
requestAnimationFrame(tick);
|
requestAnimationFrame(tick);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -684,6 +690,7 @@ async function openSettingsPanel() {
|
||||||
});
|
});
|
||||||
if (cb) {
|
if (cb) {
|
||||||
cb();
|
cb();
|
||||||
|
gameState.needsRender=true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -35,6 +35,7 @@ import { isOptionOn } from "./options";
|
||||||
export function setMousePos(gameState: GameState, x: number) {
|
export function setMousePos(gameState: GameState, x: number) {
|
||||||
// Sets the puck position, and updates the ball position if they are supposed to follow it
|
// Sets the puck position, and updates the ball position if they are supposed to follow it
|
||||||
gameState.puckPosition = x;
|
gameState.puckPosition = x;
|
||||||
|
gameState.needsRender=true
|
||||||
}
|
}
|
||||||
|
|
||||||
function getBallDefaultVx(gameState: GameState) {
|
function getBallDefaultVx(gameState: GameState) {
|
||||||
|
@ -43,6 +44,7 @@ function getBallDefaultVx(gameState: GameState) {
|
||||||
(Math.random() > 0.5 ? gameState.baseSpeed : -gameState.baseSpeed)
|
(Math.random() > 0.5 ? gameState.baseSpeed : -gameState.baseSpeed)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function resetBalls(gameState: GameState) {
|
export function resetBalls(gameState: GameState) {
|
||||||
const count = 1 + (gameState.perks?.multiball || 0);
|
const count = 1 + (gameState.perks?.multiball || 0);
|
||||||
const perBall = gameState.puckWidth / (count + 1);
|
const perBall = gameState.puckWidth / (count + 1);
|
||||||
|
|
|
@ -88,6 +88,8 @@ export function newGameState(params: RunParams): GameState {
|
||||||
},
|
},
|
||||||
lastOffered: {},
|
lastOffered: {},
|
||||||
levelTime: 0,
|
levelTime: 0,
|
||||||
|
levelWallBounces: 0,
|
||||||
|
needsRender: true,
|
||||||
autoCleanUses: 0,
|
autoCleanUses: 0,
|
||||||
};
|
};
|
||||||
resetBalls(gameState);
|
resetBalls(gameState);
|
||||||
|
|
|
@ -15,7 +15,7 @@ export function recordOneFrame(gameState: GameState) {
|
||||||
if (!isOptionOn("record")) {
|
if (!isOptionOn("record")) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!gameState.running) return;
|
// if (!gameState.running) return;
|
||||||
if (!captureStream) return;
|
if (!captureStream) return;
|
||||||
drawMainCanvasOnSmallCanvas(gameState);
|
drawMainCanvasOnSmallCanvas(gameState);
|
||||||
if (captureTrack?.requestFrame) {
|
if (captureTrack?.requestFrame) {
|
||||||
|
|
2
src/types.d.ts
vendored
2
src/types.d.ts
vendored
|
@ -190,6 +190,8 @@ export type GameState = {
|
||||||
combo: number;
|
combo: number;
|
||||||
// Whether the game is running or paused
|
// Whether the game is running or paused
|
||||||
running: boolean;
|
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.
|
// Position of the center of the puck on the canvas in pixels, from the left of the canvas.
|
||||||
puckPosition: number;
|
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,
|
// 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,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue