mirror of
https://gitlab.com/lecarore/breakout71.git
synced 2025-04-20 20:16:16 -04:00
Updated soft reset perk to just keep lvl*10 % of combo
This commit is contained in:
parent
a3c66fcdea
commit
a1bf54af71
20 changed files with 4543 additions and 4445 deletions
|
@ -1,4 +1,5 @@
|
|||
import { PerkId, PerksMap, Upgrade } from "./types";
|
||||
import {Ball, GameState, PerkId, PerksMap} from "./types";
|
||||
import {icons, upgrades} from "./loadGameData";
|
||||
|
||||
export function getMajorityValue(arr: string[]): string {
|
||||
const count: { [k: string]: number } = {};
|
||||
|
@ -22,3 +23,79 @@ export const makeEmptyPerksMap = (upgrades: { id: PerkId }[]) => {
|
|||
upgrades.forEach((u) => (p[u.id] = 0));
|
||||
return p as PerksMap;
|
||||
};
|
||||
|
||||
export function brickCenterX(gameState: GameState, index: number) {
|
||||
return (
|
||||
gameState.offsetX +
|
||||
((index % gameState.gridSize) + 0.5) * gameState.brickWidth
|
||||
);
|
||||
}
|
||||
|
||||
export function brickCenterY(gameState: GameState, index: number) {
|
||||
return (Math.floor(index / gameState.gridSize) + 0.5) * gameState.brickWidth;
|
||||
}
|
||||
|
||||
export function getRowColIndex(gameState: GameState, row: number, col: number) {
|
||||
if (
|
||||
row < 0 ||
|
||||
col < 0 ||
|
||||
row >= gameState.gridSize ||
|
||||
col >= gameState.gridSize
|
||||
)
|
||||
return -1;
|
||||
return row * gameState.gridSize + col;
|
||||
}
|
||||
|
||||
export function getPossibleUpgrades(gameState: GameState) {
|
||||
return upgrades
|
||||
.filter((u) => gameState.totalScoreAtRunStart >= u.threshold)
|
||||
.filter((u) => !u?.requires || gameState.perks[u?.requires]);
|
||||
}
|
||||
|
||||
export function max_levels(gameState: GameState) {
|
||||
return 7 + gameState.perks.extra_levels;
|
||||
}
|
||||
|
||||
export function pickedUpgradesHTMl(gameState: GameState) {
|
||||
let list = "";
|
||||
for (let u of upgrades) {
|
||||
for (let i = 0; i < gameState.perks[u.id]; i++)
|
||||
list += icons["icon:" + u.id] + " ";
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
export function currentLevelInfo(gameState: GameState) {
|
||||
return gameState.runLevels[
|
||||
gameState.currentLevel % gameState.runLevels.length
|
||||
];
|
||||
}
|
||||
|
||||
export function isTelekinesisActive(gameState: GameState, ball: Ball) {
|
||||
return gameState.perks.telekinesis && !ball.hitSinceBounce && ball.vy < 0;
|
||||
}
|
||||
|
||||
export function findLast<T>(
|
||||
arr: T[],
|
||||
predicate: (item: T, index: number, array: T[]) => boolean,
|
||||
) {
|
||||
let i = arr.length;
|
||||
while (--i)
|
||||
if (predicate(arr[i], i, arr)) {
|
||||
return arr[i];
|
||||
}
|
||||
}
|
||||
|
||||
export function distance2(
|
||||
a: { x: number; y: number },
|
||||
b: { x: number; y: number },
|
||||
) {
|
||||
return Math.pow(a.x - b.x, 2) + Math.pow(a.y - b.y, 2);
|
||||
}
|
||||
|
||||
export function distanceBetween(
|
||||
a: { x: number; y: number },
|
||||
b: { x: number; y: number },
|
||||
) {
|
||||
return Math.sqrt(distance2(a, b));
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue