This commit is contained in:
Renan LE CARO 2025-03-19 21:58:50 +01:00
parent dce41a43ec
commit d2266de792
13 changed files with 2155 additions and 2103 deletions

View file

@ -11,8 +11,8 @@ android {
applicationId = "me.lecaro.breakout"
minSdk = 21
targetSdk = 34
versionCode = 29040074
versionName = "29040074"
versionCode = 29040298
versionName = "29040298"
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables {
useSupportLibrary = true

File diff suppressed because one or more lines are too long

6
dist/index.html vendored
View file

@ -1270,7 +1270,7 @@ const upgrades = (0, _upgrades.rawUpgrades).map((u)=>({
}));
},{"./data/palette.json":"ktRBU","./data/levels.json":"8JSUc","./data/version.json":"iyP6E","./getLevelBackground":"7OIPf","./levelIcon":"6rQoT","@parcel/transformer-js/src/esmodule-helpers.js":"gkKU3","./upgrades":"1u3Dx"}],"iyP6E":[function(require,module,exports,__globalThis) {
module.exports = JSON.parse("\"29040074\"");
module.exports = JSON.parse("\"29040298\"");
},{}],"6rQoT":[function(require,module,exports,__globalThis) {
var parcelHelpers = require("@parcel/transformer-js/src/esmodule-helpers.js");
@ -2402,7 +2402,7 @@ function spawnExplosion(gameState, count, x, y, color) {
for(let i = 0; i < count; i++)makeParticle(gameState, x + (Math.random() - 0.5) * gameState.brickWidth / 2, y + (Math.random() - 0.5) * gameState.brickWidth / 2, (Math.random() - 0.5) * 30, (Math.random() - 0.5) * 30, color, false);
}
function explosionAt(gameState, index, x, y, ball) {
if (gameState.bricks[index] == 'black') delete gameState.bricks[index];
if (gameState.bricks[index] == "black") delete gameState.bricks[index];
schedulGameSound(gameState, "explode", ball.x, 1);
const col = index % gameState.gridSize;
const row = Math.floor(index / gameState.gridSize);
@ -2710,7 +2710,7 @@ frames = 1) {
if (!gameState.perks.etherealcoins) {
const flip = gameState.perks.helium > 0 && Math.abs(coin.x - gameState.puckPosition) * 2 > gameState.puckWidth + coin.size;
coin.vy += frames * coin.weight * 0.8 * (flip ? -1 : 1);
if (flip && !(0, _options.isOptionOn)('basic') && Math.random() < 0.1) makeParticle(gameState, coin.x, coin.y, 0, gameState.baseSpeed, rainbowColor(), true, 5, 250);
if (flip && !(0, _options.isOptionOn)("basic") && Math.random() < 0.1) makeParticle(gameState, coin.x, coin.y, 0, gameState.baseSpeed, rainbowColor(), true, 5, 250);
}
const speed = Math.abs(coin.sx) + Math.abs(coin.sx);
const hitBorder = bordersHitCheck(gameState, coin, coin.size / 2, frames);

View file

@ -1,5 +1,5 @@
// The version of the cache.
const VERSION = "29040074";
const VERSION = "29040298";
// The name of the cache
const CACHE_NAME = `breakout-71-${VERSION}`;

View file

@ -1 +1 @@
"29040074"
"29040298"

View file

@ -12,7 +12,12 @@ import {
Upgrade,
} from "./types";
import { getAudioContext, playPendingSounds } from "./sounds";
import {currentLevelInfo, getRowColIndex, max_levels, pickedUpgradesHTMl,} from "./game_utils";
import {
currentLevelInfo,
getRowColIndex,
max_levels,
pickedUpgradesHTMl,
} from "./game_utils";
import "./PWA/sw_loader";
import { getCurrentLang, t } from "./i18n/i18n";
@ -25,10 +30,26 @@ import {
setLevel,
setMousePos,
} from "./gameStateMutators";
import {backgroundCanvas, ctx, gameCanvas, render, scoreDisplay,} from "./render";
import {pauseRecording, recordOneFrame, resumeRecording, startRecordingGame,} from "./recording";
import {
backgroundCanvas,
ctx,
gameCanvas,
render,
scoreDisplay,
} from "./render";
import {
pauseRecording,
recordOneFrame,
resumeRecording,
startRecordingGame,
} from "./recording";
import { newGameState } from "./newGameState";
import {alertsOpen, asyncAlert, AsyncAlertAction, closeModal,} from "./asyncAlert";
import {
alertsOpen,
asyncAlert,
AsyncAlertAction,
closeModal,
} from "./asyncAlert";
import { isOptionOn, options, toggleOption } from "./options";
import { hashCode } from "./getLevelBackground";
@ -406,8 +427,7 @@ async function openScorePanel() {
async function openSettingsPanel() {
pause(true);
const actions: AsyncAlertAction<() => void>[] = [
];
const actions: AsyncAlertAction<() => void>[] = [];
for (const key of Object.keys(options) as OptionId[]) {
if (options[key])
@ -449,21 +469,18 @@ async function openSettingsPanel() {
});
}
}
actions.push(
{
actions.push({
text: t("main_menu.resume"),
help: t("main_menu.resume_help"),
value() {},
})
});
actions.push({
text: t("main_menu.unlocks"),
help: t("main_menu.unlocks_help"),
value() {
openUnlocksList();
},
})
});
actions.push({
text: t("sandbox.title"),

View file

@ -23,7 +23,8 @@ import {
getRowColIndex,
isTelekinesisActive,
isYoyoActive,
max_levels, sample,
max_levels,
sample,
shouldPierceByColor,
} from "./game_utils";
import { t } from "./i18n/i18n";
@ -32,7 +33,15 @@ import {icons} from "./loadGameData";
import { addToTotalScore } from "./settings";
import { background } from "./render";
import { gameOver } from "./gameOver";
import {brickIndex, fitSize, gameState, hasBrick, hitsSomething, openUpgradesPicker, pause,} from "./game";
import {
brickIndex,
fitSize,
gameState,
hasBrick,
hitsSomething,
openUpgradesPicker,
pause,
} from "./game";
import { stopRecording } from "./recording";
import { isOptionOn } from "./options";
@ -227,12 +236,11 @@ export function spawnExplosion(
export function explosionAt(
gameState: GameState,
index: number,
x: number, y: number,
ball: Ball) {
if(gameState.bricks[index]=='black')
delete gameState.bricks[index];
x: number,
y: number,
ball: Ball,
) {
if (gameState.bricks[index] == "black") delete gameState.bricks[index];
schedulGameSound(gameState, "explode", ball.x, 1);
@ -277,7 +285,7 @@ export function explosionAt(
gameState.runStatistics.bricks_broken++;
if (gameState.perks.zen) {
resetCombo(gameState, x,y)
resetCombo(gameState, x, y);
}
}
@ -293,10 +301,7 @@ export function explodeBrick(
if (color === "black") {
const x = brickCenterX(gameState, index),
y = brickCenterY(gameState, index);
explosionAt(gameState,
index, x, y,
ball)
explosionAt(gameState, index, x, y, ball);
} else if (color) {
// Even if it bounces we don't want to count that as a miss
@ -351,7 +356,8 @@ export function explodeBrick(
);
}
gameState.combo += gameState.perks.streak_shots +
gameState.combo +=
gameState.perks.streak_shots +
gameState.perks.compound_interest +
gameState.perks.left_is_lava +
gameState.perks.right_is_lava +
@ -359,9 +365,7 @@ export function explodeBrick(
gameState.perks.picky_eater +
gameState.perks.asceticism +
gameState.perks.zen +
gameState.perks.unbounded
;
gameState.perks.unbounded;
if (!isExplosion) {
// color change
@ -475,7 +479,7 @@ export function addToScore(gameState: GameState, coin: Coin) {
}
gameState.runStatistics.score += coin.points;
if (gameState.perks.asceticism) {
resetCombo(gameState, coin.x, coin.y)
resetCombo(gameState, coin.x, coin.y);
}
}
@ -498,7 +502,7 @@ export async function setLevel(gameState: GameState, l: number) {
// Reset combo silently
if (!gameState.perks.shunt) {
gameState.combo = baseCombo(gameState)
gameState.combo = baseCombo(gameState);
}
gameState.combo += gameState.perks.hot_start * 15;
@ -630,7 +634,7 @@ export function attract(gameState: GameState, a: Ball, b: Ball, power: number) {
}
export function coinBrickHitCheck(gameState: GameState, coin: Coin) {
if(gameState.perks.ghost_coins)return undefined
if (gameState.perks.ghost_coins) return undefined;
// Make ball/coin bonce, and return bricks that were hit
const radius = coin.size / 2;
const { x, y, previousX, previousY } = coin;
@ -697,7 +701,10 @@ export function bordersHitCheck(
let vhit = 0,
hhit = 0;
if (coin.x < gameState.offsetXRoundedDown + radius && !gameState.perks.unbounded) {
if (
coin.x < gameState.offsetXRoundedDown + radius &&
!gameState.perks.unbounded
) {
coin.x =
gameState.offsetXRoundedDown +
radius +
@ -710,7 +717,10 @@ export function bordersHitCheck(
coin.vy *= -1;
vhit = 1;
}
if (coin.x > gameState.canvasWidth - gameState.offsetXRoundedDown - radius && !gameState.perks.unbounded) {
if (
coin.x > gameState.canvasWidth - gameState.offsetXRoundedDown - radius &&
!gameState.perks.unbounded
) {
coin.x =
gameState.canvasWidth -
gameState.offsetXRoundedDown -
@ -765,9 +775,13 @@ export function gameStateTick(
gameState.autoCleanUses++;
}
if (!remainingBricks && gameState.noBricksSince == 0) {
gameState.noBricksSince ||= gameState.levelTime
gameState.noBricksSince ||= gameState.levelTime;
}
if (!remainingBricks && (!liveCount(gameState.coins) || (gameState.levelTime > gameState.noBricksSince + 5000))) {
if (
!remainingBricks &&
(!liveCount(gameState.coins) ||
gameState.levelTime > gameState.noBricksSince + 5000)
) {
if (gameState.currentLevel + 1 < max_levels(gameState)) {
setLevel(gameState, gameState.currentLevel + 1);
} else {
@ -781,25 +795,30 @@ export function gameStateTick(
forEachLiveOne(gameState.coins, (coin, coinIndex) => {
if (gameState.perks.coin_magnet) {
const strength = 100 / (100 +
const strength =
(100 /
(100 +
Math.pow(coin.y - gameState.gameZoneHeight, 2) +
Math.pow(coin.x - gameState.puckPosition, 2)) *
Math.pow(coin.x - gameState.puckPosition, 2))) *
gameState.perks.coin_magnet;
const attractionX = frames * (gameState.puckPosition - coin.x) * strength
const attractionX =
frames * (gameState.puckPosition - coin.x) * strength;
coin.vx += attractionX;
coin.vy += frames * (gameState.gameZoneHeight - coin.y) * strength / 2
coin.vy +=
(frames * (gameState.gameZoneHeight - coin.y) * strength) / 2;
coin.sa -= attractionX / 10;
}
if (gameState.perks.ball_attracts_coins) {
gameState.balls.forEach(ball=>{
const d2= distance2(ball, coin)
coin.vx+=(ball.x-coin.x)/d2*30*gameState.perks.ball_attracts_coins
coin.vy+=(ball.y-coin.y)/d2*30*gameState.perks.ball_attracts_coins
})
gameState.balls.forEach((ball) => {
const d2 = distance2(ball, coin);
coin.vx +=
((ball.x - coin.x) / d2) * 30 * gameState.perks.ball_attracts_coins;
coin.vy +=
((ball.y - coin.y) / d2) * 30 * gameState.perks.ball_attracts_coins;
});
}
const ratio = 1 - (gameState.perks.viscosity * 0.03 + 0.005) * frames;
@ -816,10 +835,14 @@ export function gameStateTick(
// Gravity
if (!gameState.perks.etherealcoins) {
const flip = gameState.perks.helium > 0 && Math.abs(coin.x - gameState.puckPosition) * 2 > gameState.puckWidth + coin.size
const flip =
gameState.perks.helium > 0 &&
Math.abs(coin.x - gameState.puckPosition) * 2 >
gameState.puckWidth + coin.size;
coin.vy += frames * coin.weight * 0.8 * (flip ? -1 : 1);
if (flip && !isOptionOn('basic') && Math.random() < 0.1) {
makeParticle(gameState,
if (flip && !isOptionOn("basic") && Math.random() < 0.1) {
makeParticle(
gameState,
coin.x,
coin.y,
0,
@ -827,10 +850,9 @@ export function gameStateTick(
rainbowColor(),
true,
5,
250
)
250,
);
}
}
const speed = Math.abs(coin.sx) + Math.abs(coin.sx);
@ -851,12 +873,14 @@ export function gameStateTick(
if (gameState.perks.compound_interest) {
resetCombo(gameState, coin.x, coin.y);
}
} else if (gameState.perks.unbounded && (coin.x < -50 || coin.x > gameState.canvasWidth + 50)) {
} else if (
gameState.perks.unbounded &&
(coin.x < -50 || coin.x > gameState.canvasWidth + 50)
) {
// Out of bound on sides
destroy(gameState.coins, coinIndex);
}
const hitBrick = coinBrickHitCheck(gameState, coin);
if (gameState.perks.metamorphosis && typeof hitBrick !== "undefined") {
@ -891,29 +915,41 @@ export function gameStateTick(
if (gameState.perks.shocks) {
gameState.balls.forEach((a, ai) =>
gameState.balls.forEach((b, bi) => {
if (ai < bi && !a.destroyed && !b.destroyed && distance2(a, b) < gameState.ballSize * gameState.ballSize) {
let tempVx = a.vx
let tempVy = a.vy
a.vx = b.vx
a.vy = b.vy
b.vx = tempVx
b.vy = tempVy
if (
ai < bi &&
!a.destroyed &&
!b.destroyed &&
distance2(a, b) < gameState.ballSize * gameState.ballSize
) {
let tempVx = a.vx;
let tempVy = a.vy;
a.vx = b.vx;
a.vy = b.vy;
b.vx = tempVx;
b.vy = tempVy;
let x = (a.x + b.x) / 2
let y = (a.y + b.y) / 2
const limit = gameState.baseSpeed
a.vx += clamp(a.x - x, -limit, limit)+(Math.random()-0.5) * limit/3
a.vy += clamp(a.y - y, -limit, limit)+(Math.random()-0.5) * limit/3
b.vx += clamp(b.x - x, -limit, limit)+(Math.random()-0.5) * limit/3
b.vy += clamp(b.y - y, -limit, limit)+(Math.random()-0.5) * limit/3
let x = (a.x + b.x) / 2;
let y = (a.y + b.y) / 2;
const limit = gameState.baseSpeed;
a.vx +=
clamp(a.x - x, -limit, limit) +
((Math.random() - 0.5) * limit) / 3;
a.vy +=
clamp(a.y - y, -limit, limit) +
((Math.random() - 0.5) * limit) / 3;
b.vx +=
clamp(b.x - x, -limit, limit) +
((Math.random() - 0.5) * limit) / 3;
b.vy +=
clamp(b.y - y, -limit, limit) +
((Math.random() - 0.5) * limit) / 3;
let index = brickIndex(x, y)
let index = brickIndex(x, y);
explosionAt(gameState, index, x, y, a)
explosionAt(gameState, index, x, y, a);
}
}
)
)
}),
);
}
if (gameState.perks.wind) {
@ -1081,9 +1117,7 @@ export function ballTick(gameState: GameState, ball: Ball, delta: number) {
if (isYoyoActive(gameState, ball)) {
speedLimitDampener += 3;
ball.vx +=
((gameState.puckPosition - ball.x) / 1000) *
delta *
gameState.perks.yoyo;
((gameState.puckPosition - ball.x) / 1000) * delta * gameState.perks.yoyo;
}
if (
@ -1163,7 +1197,12 @@ export function ballTick(gameState: GameState, ball: Ball, delta: number) {
}
}
const borderHitCode = bordersHitCheck(gameState, ball, gameState.ballSize / 2, delta);
const borderHitCode = bordersHitCheck(
gameState,
ball,
gameState.ballSize / 2,
delta,
);
if (borderHitCode) {
if (
gameState.perks.left_is_lava &&
@ -1216,46 +1255,43 @@ export function ballTick(gameState: GameState, ball: Ball, delta: number) {
} else {
ball.vy *= -1;
gameState.perks.extra_life -= 1
gameState.perks.extra_life -= 1;
if (gameState.perks.extra_life < 0) {
gameState.perks.extra_life=0
gameState.perks.extra_life = 0;
} else if (gameState.perks.sacrifice) {
if (liveCount(gameState.coins) < gameState.MAX_COINS / 2) {
// true duplication
let remaining = liveCount(gameState.coins)
let remaining = liveCount(gameState.coins);
forEachLiveOne(gameState.coins, (source, index) => {
if(!remaining) return
append(gameState.coins, copy=>{
copy.points=source.points
copy.color=source.color
copy.x=source.x
copy.y=source.y
copy.size=source.size
copy.previousX=source.previousX
copy.previousY=source.previousY
copy.vx=-source.vx
copy.vy=-source.vy
copy.sx=source.sx
copy.sy=source.sy
copy.a=source.a
copy.sa=-source.sa
copy.weight=source.weight
copy.coloredABrick=source.coloredABrick
})
remaining--
})
if (!remaining) return;
append(gameState.coins, (copy) => {
copy.points = source.points;
copy.color = source.color;
copy.x = source.x;
copy.y = source.y;
copy.size = source.size;
copy.previousX = source.previousX;
copy.previousY = source.previousY;
copy.vx = -source.vx;
copy.vy = -source.vy;
copy.sx = source.sx;
copy.sy = source.sy;
copy.a = source.a;
copy.sa = -source.sa;
copy.weight = source.weight;
copy.coloredABrick = source.coloredABrick;
});
remaining--;
});
} else {
forEachLiveOne(gameState.coins, (source, index) => {
source.points*=2
})
source.points *= 2;
});
// spawn a few coins for effect, but mostly increment poitns counter
}
}
schedulGameSound(gameState, "lifeLost", ball.x, 1);
if (!isOptionOn("basic")) {
for (let i = 0; i < 10; i++)
@ -1276,16 +1312,15 @@ export function ballTick(gameState: GameState, ball: Ball, delta: number) {
resetCombo(gameState, ball.x, ball.y);
}
if (gameState.perks.trampoline) {
gameState.combo+=gameState.perks.trampoline
gameState.combo += gameState.perks.trampoline;
}
if (gameState.perks.nbricks) {
if (ball.hitSinceBounce) {
if (gameState.perks.nbricks === ball.hitSinceBounce) {
gameState.combo += gameState.perks.nbricks
gameState.combo += gameState.perks.nbricks;
} else {
resetCombo(gameState, ball.x, ball.y)
resetCombo(gameState, ball.x, ball.y);
}
}
}
@ -1303,10 +1338,11 @@ export function ballTick(gameState: GameState, ball: Ball, delta: number) {
gameState.runStatistics.misses++;
gameState.levelMisses++;
if (gameState.perks.forgiving) {
const indexes = gameState.bricks.map((b,i)=>b ? i:-1)
.filter(i=>i>-1)
const pick = sample(indexes)
explodeBrick(gameState,pick, ball, false)
const indexes = gameState.bricks
.map((b, i) => (b ? i : -1))
.filter((i) => i > -1);
const pick = sample(indexes);
explodeBrick(gameState, pick, ball, false);
} else {
resetCombo(gameState, ball.x, ball.y);
}
@ -1326,10 +1362,12 @@ export function ballTick(gameState: GameState, ball: Ball, delta: number) {
ball.piercedSinceBounce = 0;
}
const lostOnSides = gameState.perks.unbounded && ball.x < 50 || ball.x > gameState.canvasWidth + 50
if (gameState.running &&
const lostOnSides =
(gameState.perks.unbounded && ball.x < 50) ||
ball.x > gameState.canvasWidth + 50;
if (
gameState.running &&
(ball.y > gameState.gameZoneHeight + gameState.ballSize / 2 || lostOnSides)
) {
ball.destroyed = true;
gameState.runStatistics.balls_lost++;

View file

@ -103,9 +103,8 @@ export function distanceBetween(
return Math.sqrt(distance2(a, b));
}
export function clamp(value, min, max){
return Math.max(min, Math.min(value, max))
export function clamp(value: number, min: number, max: number) {
return Math.max(min, Math.min(value, max));
}
export function defaultSounds() {
return {

View file

@ -218,7 +218,9 @@ export function render(gameState: GameState) {
ctx.fillRect(
gameState.perks.unbounded ? 0 : gameState.offsetXRoundedDown,
gameState.gameZoneHeight - gameState.puckHeight / 2 + 2 * i,
gameState.perks.unbounded ? gameState.canvasWidth : gameState.gameZoneWidthRoundedUp,
gameState.perks.unbounded
? gameState.canvasWidth
: gameState.gameZoneWidthRoundedUp,
1,
);
}
@ -251,9 +253,6 @@ export function render(gameState: GameState) {
);
ctx.stroke();
}
});
// The puck
ctx.globalAlpha = 1;
@ -318,7 +317,7 @@ export function render(gameState: GameState) {
const hasCombo = gameState.combo > baseCombo(gameState);
ctx.globalCompositeOperation = "source-over";
ctx.globalAlpha = gameState.perks.unbounded ? 0.1 : 1
ctx.globalAlpha = gameState.perks.unbounded ? 0.1 : 1;
if (gameState.offsetXRoundedDown) {
// draw outside of gaming area to avoid capturing borders in recordings
ctx.fillStyle =

View file

@ -1,11 +1,11 @@
import _rawLevelsList from "./data/levels.json";
import { rawUpgrades } from "./upgrades";
describe("rawUpgrades", () => {
it('has an icon for each upgrade',()=>{
const missingIcon = rawUpgrades.map(u=>u.id).filter(id=>!_rawLevelsList.find(l=>l.name === 'icon:'+id))
expect(missingIcon.join(', ')).toEqual('')
})
})
it("has an icon for each upgrade", () => {
const missingIcon = rawUpgrades
.map((u) => u.id)
.filter((id) => !_rawLevelsList.find((l) => l.name === "icon:" + id));
expect(missingIcon.join(", ")).toEqual("");
});
});

View file

@ -512,5 +512,4 @@ export const rawUpgrades = [
help: (lvl: number) => t("upgrades.ball_attracts_coins.help"),
fullHelp: t("upgrades.ball_attracts_coins.fullHelp"),
},
] as const;