Fixed starting speed of balls

This commit is contained in:
Renan LE CARO 2025-03-24 10:38:01 +01:00
parent 5a10f7d768
commit 0589729fb8
3 changed files with 40 additions and 39 deletions

35
dist/index.html vendored
View file

@ -2578,7 +2578,8 @@ function getBallDefaultVx(gameState) {
return (gameState.perks.concave_puck ? 0 : 1) * (Math.random() > 0.5 ? gameState.baseSpeed : -gameState.baseSpeed); return (gameState.perks.concave_puck ? 0 : 1) * (Math.random() > 0.5 ? gameState.baseSpeed : -gameState.baseSpeed);
} }
function resetBalls(gameState) { function resetBalls(gameState) {
console.log('resetBalls', gameState); // Always compute speed first
normalizeGameState(gameState);
const count = 1 + (gameState.perks?.multiball || 0); const count = 1 + (gameState.perks?.multiball || 0);
const perBall = gameState.puckWidth / (count + 1); const perBall = gameState.puckWidth / (count + 1);
gameState.balls = []; gameState.balls = [];
@ -2596,8 +2597,8 @@ function resetBalls(gameState) {
previousVX: vx, previousVX: vx,
vy: -gameState.baseSpeed, vy: -gameState.baseSpeed,
previousVY: -gameState.baseSpeed, previousVY: -gameState.baseSpeed,
sx: 0, // sx: 0,
sy: 0, // sy: 0,
piercePoints: gameState.perks.pierce * 3, piercePoints: gameState.perks.pierce * 3,
hitSinceBounce: 0, hitSinceBounce: 0,
brokenSinceBounce: 0, brokenSinceBounce: 0,
@ -2622,8 +2623,8 @@ function putBallsAtPuck(gameState) {
// ball.previousVX = ball.vx; // ball.previousVX = ball.vx;
// ball.vy = -gameState.baseSpeed; // ball.vy = -gameState.baseSpeed;
// ball.previousVY = ball.vy; // ball.previousVY = ball.vy;
ball.sx = 0; // ball.sx = 0;
ball.sy = 0; // ball.sy = 0;
ball.hitItem = []; ball.hitItem = [];
ball.hitSinceBounce = 0; ball.hitSinceBounce = 0;
ball.brokenSinceBounce = 0; ball.brokenSinceBounce = 0;
@ -2940,12 +2941,12 @@ function bordersHitCheck(gameState, coin, radius, delta) {
coin.previousY = coin.y; coin.previousY = coin.y;
coin.x += coin.vx * delta; coin.x += coin.vx * delta;
coin.y += coin.vy * delta; coin.y += coin.vy * delta;
coin.sx ||= 0; // coin.sx ||= 0;
coin.sy ||= 0; // coin.sy ||= 0;
coin.sx += coin.previousX - coin.x; // coin.sx += coin.previousX - coin.x;
coin.sy += coin.previousY - coin.y; // coin.sy += coin.previousY - coin.y;
coin.sx *= 0.9; // coin.sx *= 0.9;
coin.sy *= 0.9; // coin.sy *= 0.9;
if (gameState.perks.wind) coin.vx += (gameState.puckPosition - (gameState.offsetX + gameState.gameZoneWidth / 2)) / gameState.gameZoneWidth * gameState.perks.wind * 0.5; if (gameState.perks.wind) coin.vx += (gameState.puckPosition - (gameState.offsetX + gameState.gameZoneWidth / 2)) / gameState.gameZoneWidth * gameState.perks.wind * 0.5;
let vhit = 0, hhit = 0; let vhit = 0, hhit = 0;
if (coin.x < gameState.offsetXRoundedDown + radius && !gameState.perks.unbounded) { if (coin.x < gameState.offsetXRoundedDown + radius && !gameState.perks.unbounded) {
@ -3019,9 +3020,9 @@ frames = 1) {
if (!gameState.perks.etherealcoins) { 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); 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, coin.color, true, 5, 250);
} }
const speed = Math.abs(coin.sx) + Math.abs(coin.sx); const speed = (Math.abs(coin.vx) + Math.abs(coin.vy)) * 10;
const hitBorder = bordersHitCheck(gameState, coin, coin.size / 2, frames); const hitBorder = bordersHitCheck(gameState, coin, coin.size / 2, frames);
if (coin.y > gameState.gameZoneHeight - coinRadius - gameState.puckHeight && coin.y < gameState.gameZoneHeight + gameState.puckHeight + coin.vy && Math.abs(coin.x - gameState.puckPosition) < coinRadius + gameState.puckWidth / 2 + // a bit of margin to be nice if (coin.y > gameState.gameZoneHeight - coinRadius - gameState.puckHeight && coin.y < gameState.gameZoneHeight + gameState.puckHeight + coin.vy && Math.abs(coin.x - gameState.puckPosition) < coinRadius + gameState.puckWidth / 2 + // a bit of margin to be nice
gameState.puckHeight) { gameState.puckHeight) {
@ -3193,8 +3194,8 @@ function ballTick(gameState, ball, delta) {
copy.previousY = source.previousY; copy.previousY = source.previousY;
copy.vx = -source.vx; copy.vx = -source.vx;
copy.vy = -source.vy; copy.vy = -source.vy;
copy.sx = source.sx; // copy.sx = source.sx;
copy.sy = source.sy; // copy.sy = source.sy;
copy.a = source.a; copy.a = source.a;
copy.sa = -source.sa; copy.sa = -source.sa;
copy.weight = source.weight; copy.weight = source.weight;
@ -3302,8 +3303,8 @@ function makeCoin(gameState, x, y, vx, vy, color = "gold", points = 1) {
p.previousY = y; p.previousY = y;
p.vx = vx; p.vx = vx;
p.vy = vy; p.vy = vy;
p.sx = 0; // p.sx = 0;
p.sy = 0; // p.sy = 0;
p.color = color; p.color = color;
p.a = Math.random() * Math.PI * 2; p.a = Math.random() * Math.PI * 2;
p.sa = Math.random() - 0.5; p.sa = Math.random() - 0.5;

View file

@ -70,7 +70,8 @@ function getBallDefaultVx(gameState: GameState) {
} }
export function resetBalls(gameState: GameState) { export function resetBalls(gameState: GameState) {
console.log('resetBalls',gameState) // Always compute speed first
normalizeGameState(gameState)
const count = 1 + (gameState.perks?.multiball || 0); const count = 1 + (gameState.perks?.multiball || 0);
const perBall = gameState.puckWidth / (count + 1); const perBall = gameState.puckWidth / (count + 1);
gameState.balls = []; gameState.balls = [];
@ -94,8 +95,8 @@ export function resetBalls(gameState: GameState) {
vy: -gameState.baseSpeed, vy: -gameState.baseSpeed,
previousVY: -gameState.baseSpeed, previousVY: -gameState.baseSpeed,
sx: 0, // sx: 0,
sy: 0, // sy: 0,
piercePoints: gameState.perks.pierce * 3, piercePoints: gameState.perks.pierce * 3,
hitSinceBounce: 0, hitSinceBounce: 0,
brokenSinceBounce: 0, brokenSinceBounce: 0,
@ -123,8 +124,8 @@ export function putBallsAtPuck(gameState: GameState) {
// ball.previousVX = ball.vx; // ball.previousVX = ball.vx;
// ball.vy = -gameState.baseSpeed; // ball.vy = -gameState.baseSpeed;
// ball.previousVY = ball.vy; // ball.previousVY = ball.vy;
ball.sx = 0; // ball.sx = 0;
ball.sy = 0; // ball.sy = 0;
ball.hitItem = []; ball.hitItem = [];
ball.hitSinceBounce = 0; ball.hitSinceBounce = 0;
ball.brokenSinceBounce = 0; ball.brokenSinceBounce = 0;
@ -772,12 +773,12 @@ export function bordersHitCheck(
coin.previousY = coin.y; coin.previousY = coin.y;
coin.x += coin.vx * delta; coin.x += coin.vx * delta;
coin.y += coin.vy * delta; coin.y += coin.vy * delta;
coin.sx ||= 0; // coin.sx ||= 0;
coin.sy ||= 0; // coin.sy ||= 0;
coin.sx += coin.previousX - coin.x; // coin.sx += coin.previousX - coin.x;
coin.sy += coin.previousY - coin.y; // coin.sy += coin.previousY - coin.y;
coin.sx *= 0.9; // coin.sx *= 0.9;
coin.sy *= 0.9; // coin.sy *= 0.9;
if (gameState.perks.wind) { if (gameState.perks.wind) {
coin.vx += coin.vx +=
@ -952,7 +953,7 @@ export function gameStateTick(
coin.y, coin.y,
0, 0,
gameState.baseSpeed, gameState.baseSpeed,
rainbowColor(), coin.color,
true, true,
5, 5,
250, 250,
@ -960,7 +961,7 @@ export function gameStateTick(
} }
} }
const speed = Math.abs(coin.sx) + Math.abs(coin.sx); const speed =( Math.abs(coin.vx) + Math.abs(coin.vy)) * 10;
const hitBorder = bordersHitCheck(gameState, coin, coin.size / 2, frames); const hitBorder = bordersHitCheck(gameState, coin, coin.size / 2, frames);
if ( if (
@ -1229,7 +1230,6 @@ export function ballTick(gameState: GameState, ball: Ball, delta: number) {
ball.vx += ball.vx +=
((gameState.puckPosition - ball.x) / 1000) * delta * gameState.perks.yoyo; ((gameState.puckPosition - ball.x) / 1000) * delta * gameState.perks.yoyo;
} }
if ( if (
ball.vx * ball.vx + ball.vy * ball.vy < ball.vx * ball.vx + ball.vy * ball.vy <
gameState.baseSpeed * gameState.baseSpeed * 2 gameState.baseSpeed * gameState.baseSpeed * 2
@ -1393,8 +1393,8 @@ export function ballTick(gameState: GameState, ball: Ball, delta: number) {
copy.previousY = source.previousY; copy.previousY = source.previousY;
copy.vx = -source.vx; copy.vx = -source.vx;
copy.vy = -source.vy; copy.vy = -source.vy;
copy.sx = source.sx; // copy.sx = source.sx;
copy.sy = source.sy; // copy.sy = source.sy;
copy.a = source.a; copy.a = source.a;
copy.sa = -source.sa; copy.sa = -source.sa;
copy.weight = source.weight; copy.weight = source.weight;
@ -1613,8 +1613,8 @@ function makeCoin(
p.previousY = y; p.previousY = y;
p.vx = vx; p.vx = vx;
p.vy = vy; p.vy = vy;
p.sx = 0; // p.sx = 0;
p.sy = 0; // p.sy = 0;
p.color = color; p.color = color;
p.a = Math.random() * Math.PI * 2; p.a = Math.random() * Math.PI * 2;
p.sa = Math.random() - 0.5; p.sa = Math.random() - 0.5;

8
src/types.d.ts vendored
View file

@ -75,8 +75,8 @@ export type Coin = {
previousY: number; previousY: number;
vx: number; vx: number;
vy: number; vy: number;
sx: number; // sx: number;
sy: number; // sy: number;
a: number; a: number;
sa: number; sa: number;
weight: number; weight: number;
@ -92,8 +92,8 @@ export type Ball = {
vy: number; vy: number;
previousVX: number; previousVX: number;
previousVY: number; previousVY: number;
sx: number; // sx: number;
sy: number; // sy: number;
// Ability to pierce N HP // Ability to pierce N HP
piercePoints: number; piercePoints: number;
// Any bounce counts, even if brick resisted the hit // Any bounce counts, even if brick resisted the hit