mirror of
https://gitlab.com/lecarore/breakout71.git
synced 2025-04-22 04:56:15 -04:00
wip
This commit is contained in:
parent
581ee412d4
commit
ab3e4818db
5 changed files with 67 additions and 10 deletions
|
@ -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)
|
||||
|
||||
}
|
|
@ -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
15
src/types.d.ts
vendored
|
@ -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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue