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

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