mirror of
https://gitlab.com/lecarore/breakout71.git
synced 2025-04-21 12:36:15 -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;
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -88,6 +88,8 @@ export function newGameState(params: RunParams): GameState {
|
|||
},
|
||||
lastOffered: {},
|
||||
levelTime: 0,
|
||||
levelWallBounces: 0,
|
||||
needsRender: true,
|
||||
autoCleanUses: 0,
|
||||
};
|
||||
resetBalls(gameState);
|
||||
|
|
|
@ -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) {
|
||||
|
|
2
src/types.d.ts
vendored
2
src/types.d.ts
vendored
|
@ -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,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue