[pongwars] starting grid configuration

more pretty than pure noise
This commit is contained in:
dogeystamp 2024-02-17 19:42:58 -05:00
parent 7f63fb4c22
commit fba38f982c
Signed by: dogeystamp
GPG Key ID: 7225FE3592EFFA38

View File

@ -178,10 +178,7 @@
},
];
var state = teams.map((team) => ({
elim: false,
boostEnabled: false,
}))
var state = {}
const squareSize = 16;
const numSquaresX = canvas.width / squareSize;
@ -199,6 +196,8 @@
state[key].boostEnabled = false;
})
function initialState() {
// base noise pattern (failsafe in case the grid doesn't cover some part)
for (let i = 0; i < numSquaresX; i++) {
squares[i] = [];
for (let j = 0; j < numSquaresY; j++) {
@ -207,6 +206,43 @@
}
}
const enableGrid = true;
if (enableGrid) {
const gridW = 4;
const gridH = 2;
for (let i = 0; i < gridW; i++) {
for (let j = 0; j < gridH; j++) {
const gridIdx = j * gridW + i;
const t = (gridIdx < teams.length) ? gridIdx : null;
for (let x = Math.floor(i/gridW*numSquaresX); x < Math.floor((i+1)/gridW*numSquaresX); x++) {
for (let y = Math.floor(j/gridH*numSquaresY); y < Math.floor((j+1)/gridH*numSquaresY); y++) {
if (t !== null) {
squares[x][y] = t;
}
}
}
if (t !== null) {
teams[t].x = Math.floor((i+0.5)/gridW*canvas.width);
teams[t].y = Math.floor((j+0.5)/gridH*canvas.height);
}
}
}
for (let i = 0; i < teams.length; i++) {
teams[i].dx = 5 * randInt(-1, 1);
teams[i].dy = 5;
}
}
state = teams.map((team) => ({
elim: false,
boostEnabled: false,
}))
}
initialState();
function randomNum(min, max) {
return Math.random() * (max - min) + min;
}