From ab3e4818db19d68fc9758888bbd37782aa4ffce7 Mon Sep 17 00:00:00 2001 From: Renan LE CARO Date: Tue, 18 Mar 2025 08:19:20 +0100 Subject: [PATCH] wip --- Readme.md | 4 +--- dist/index.html | 29 +++++++++++++++++++++++++++-- src/gameStateMutators.ts | 22 +++++++++++++++++++++- src/newGameState.ts | 7 +++++-- src/types.d.ts | 15 +++++++++++++-- 5 files changed, 67 insertions(+), 10 deletions(-) diff --git a/Readme.md b/Readme.md index 237e759..a201851 100644 --- a/Readme.md +++ b/Readme.md @@ -23,9 +23,7 @@ There's also an easy mode for kids (slower ball). # Next -- extract sound logic, only set the params as a gamestate object -- separate particles by type -- reuse coins and particles +- separate particles by type, reuse coins and particles - sturdy bricks map of remaining hits # bugs diff --git a/dist/index.html b/dist/index.html index ecd10c1..d79679a 100644 --- a/dist/index.html +++ b/dist/index.html @@ -2919,6 +2919,17 @@ function ballTick(gameState, ball, delta) { } } } +function append(makeItem, where) { + while(where.list[where.indexMin] && !where.list[where.indexMin].destroyed && where.indexMin < where.list.length)where.indexMin++; + if (where.indexMin < where.list.length) { + makeItem(where.list[where.indexMin]); + where.indexMin++; + } else where.list.push(makeItem(null)); +} +function destroy(where, index) { + where.list[index].destroyed = true; + where.indexMin = Math.min(where.indexMin, index); +} },{"./game_utils":"cEeac","./i18n/i18n":"eNPRm","./loadGameData":"l1B4x","./settings":"5blfu","./render":"9AS2t","./gameOver":"caCAf","./game":"edeGs","./recording":"godmD","./options":"d5NoS","@parcel/transformer-js/src/esmodule-helpers.js":"gkKU3"}],"9AS2t":[function(require,module,exports,__globalThis) { var parcelHelpers = require("@parcel/transformer-js/src/esmodule-helpers.js"); @@ -3762,8 +3773,22 @@ function newGameState(params) { balls: [], ballsColor: "white", bricks: [], - flashes: [], - coins: [], + lights: { + indexMin: 0, + list: [] + }, + particles: { + indexMin: 0, + list: [] + }, + texts: { + indexMin: 0, + list: [] + }, + coins: { + indexMin: 0, + list: [] + }, levelStartScore: 0, levelMisses: 0, levelSpawnedCoins: 0, diff --git a/src/gameStateMutators.ts b/src/gameStateMutators.ts index 2e7a22e..199cbff 100644 --- a/src/gameStateMutators.ts +++ b/src/gameStateMutators.ts @@ -1,4 +1,4 @@ -import {Ball, BallLike, Coin, colorString, GameState, PerkId} from "./types"; +import {Ball, BallLike, Coin, colorString, GameState, PerkId, ReusableArray} from "./types"; import { brickCenterX, @@ -1244,3 +1244,23 @@ export function ballTick(gameState: GameState, ball: Ball, delta: number) { } } } + +function append(makeItem:(match:T|null)=>T,where:ReusableArray){ + while(where.list[where.indexMin] && !where.list[where.indexMin].destroyed + && where.indexMin(where:ReusableArray, index:number){ + where.list[index].destroyed=true + where.indexMin = Math.min(where.indexMin, index) + +} \ No newline at end of file diff --git a/src/newGameState.ts b/src/newGameState.ts index 8b124d6..70a7a3f 100644 --- a/src/newGameState.ts +++ b/src/newGameState.ts @@ -5,6 +5,7 @@ import {defaultSounds, getPossibleUpgrades, makeEmptyPerksMap, sumOfKeys,} from import {dontOfferTooSoon, resetBalls} from "./gameStateMutators"; import {isOptionOn} from "./options"; + export function newGameState(params: RunParams): GameState { const totalScoreAtRunStart = getTotalScore(); const firstLevel = params?.level @@ -49,8 +50,10 @@ export function newGameState(params: RunParams): GameState { balls: [], ballsColor: "white", bricks: [], - flashes: [], - coins: [], + lights: {indexMin:0,list:[]}, + particles: {indexMin:0,list:[]}, + texts: {indexMin:0,list:[]}, + coins: {indexMin:0,list:[]}, levelStartScore: 0, levelMisses: 0, levelSpawnedCoins: 0, diff --git a/src/types.d.ts b/src/types.d.ts index 7272db1..64ed9cf 100644 --- a/src/types.d.ts +++ b/src/types.d.ts @@ -150,6 +150,13 @@ export type PerksMap = { [k in PerkId]: number; }; +// TODO ensure T has a destroyed;boolean field +export type ReusableArray = { + // All items below that index should not be destroyed + indexMin:number; + list:T[] +} + export type RunHistoryItem = RunStats & { perks?: PerksMap; appVersion?: string; @@ -213,8 +220,12 @@ export type GameState = { // Array of bricks to display. 'black' means bomb. '' means no brick. bricks: colorString[]; - flashes: Flash[]; - coins: Coin[]; + + + particles: ReusableArray + texts: ReusableArray + lights: ReusableArray + coins: ReusableArray; levelStartScore: number; levelMisses: number; levelSpawnedCoins: number;