This commit is contained in:
Renan LE CARO 2025-03-18 08:19:20 +01:00
parent 581ee412d4
commit ab3e4818db
5 changed files with 67 additions and 10 deletions

View file

@ -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

29
dist/index.html vendored
View file

@ -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,

View file

@ -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<T>(makeItem:(match:T|null)=>T,where:ReusableArray<T>){
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<T>(where:ReusableArray<T>, index:number){
where.list[index].destroyed=true
where.indexMin = Math.min(where.indexMin, index)
}

View file

@ -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,

15
src/types.d.ts vendored
View file

@ -150,6 +150,13 @@ export type PerksMap = {
[k in PerkId]: number;
};
// TODO ensure T has a destroyed;boolean field
export type ReusableArray<T> = {
// 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<ParticleFlash>
texts: ReusableArray<TextFlash>
lights: ReusableArray<BallFlash>
coins: ReusableArray<Coin>;
levelStartScore: number;
levelMisses: number;
levelSpawnedCoins: number;