[pongwars]: add new modes
This commit is contained in:
parent
fa71caa020
commit
e02d1b855b
@ -47,11 +47,17 @@
|
|||||||
#made {
|
#made {
|
||||||
font-family: monospace;
|
font-family: monospace;
|
||||||
margin-top: auto;
|
margin-top: auto;
|
||||||
margin-bottom: 20px;
|
|
||||||
font-size: 12px;
|
font-size: 12px;
|
||||||
padding-left: 20px;
|
padding-left: 20px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#mode {
|
||||||
|
font-family: monospace;
|
||||||
|
font-size: 12px;
|
||||||
|
list-style-type: none;
|
||||||
|
margin-bottom: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
#instr {
|
#instr {
|
||||||
font-family: monospace;
|
font-family: monospace;
|
||||||
font-size: 12px;
|
font-size: 12px;
|
||||||
@ -69,7 +75,7 @@
|
|||||||
<canvas id="pongCanvas" width="1200" height="800"></canvas>
|
<canvas id="pongCanvas" width="1200" height="800"></canvas>
|
||||||
<div id="score"></div>
|
<div id="score"></div>
|
||||||
<p id="instr">
|
<p id="instr">
|
||||||
balls can be controlled with number keys
|
balls can be controlled with keys shown to the left of their names
|
||||||
</p>
|
</p>
|
||||||
<p id="made">
|
<p id="made">
|
||||||
made by <a href="https://koenvangilst.nl">Koen van Gilst</a> | source on
|
made by <a href="https://koenvangilst.nl">Koen van Gilst</a> | source on
|
||||||
@ -78,6 +84,12 @@
|
|||||||
patches from dogeystamp | patched source on
|
patches from dogeystamp | patched source on
|
||||||
<a href="https://github.com/dogeystamp/garbage-monorepo/tree/main/pongwars">github</a>
|
<a href="https://github.com/dogeystamp/garbage-monorepo/tree/main/pongwars">github</a>
|
||||||
</p>
|
</p>
|
||||||
|
<div id="mode">
|
||||||
|
change mode:
|
||||||
|
<a class="modeLink" data-mode="normal">normal</a>
|
||||||
|
<a class="modeLink" data-mode="big">big</a>
|
||||||
|
<a class="modeLink" data-mode="small">small</a>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
@ -114,7 +126,7 @@
|
|||||||
{
|
{
|
||||||
name: "orange",
|
name: "orange",
|
||||||
color: "coral",
|
color: "coral",
|
||||||
backgroundColor: "chocolate",
|
backgroundColor: "#DD4500",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "white",
|
name: "white",
|
||||||
@ -136,33 +148,79 @@
|
|||||||
color: "gray",
|
color: "gray",
|
||||||
backgroundColor: "#333333",
|
backgroundColor: "#333333",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "yellow",
|
||||||
|
color: "yellow",
|
||||||
|
backgroundColor: "goldenrod",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "pink",
|
||||||
|
color: "darksalmon",
|
||||||
|
backgroundColor: "mediumvioletred",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "turquoise",
|
||||||
|
color: "turquoise",
|
||||||
|
backgroundColor: "royalblue",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "salmon",
|
||||||
|
color: "peachpuff",
|
||||||
|
backgroundColor: "salmon",
|
||||||
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
var state = {}
|
var state = {}
|
||||||
|
|
||||||
const squareSize = 16;
|
|
||||||
const numSquaresX = canvas.width / squareSize;
|
var squareSize = 16;
|
||||||
const numSquaresY = canvas.height / squareSize;
|
var numSquaresX = canvas.width / squareSize;
|
||||||
|
var numSquaresY = canvas.height / squareSize;
|
||||||
let squares = [];
|
let squares = [];
|
||||||
|
|
||||||
// matrix of "timestamps" where each square was claimed
|
// matrix of "timestamps" where each square was claimed
|
||||||
let squareTaken = [];
|
let squareTaken = [];
|
||||||
var squareTime = 0;
|
var squareTime = 0;
|
||||||
|
|
||||||
|
// do not edit without editing the code below for key to idx
|
||||||
|
const idxKeyMap = [..."0123456789abcdefghijklmnopqrstuvwxyz"];
|
||||||
|
function keyToIdx(key) {
|
||||||
|
const keyInt = parseInt(key, 36);
|
||||||
|
if (!isNaN(keyInt) && keyInt < teams.length) return keyInt;
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
document.addEventListener("keydown", (event) => {
|
document.addEventListener("keydown", (event) => {
|
||||||
const key = parseInt(event.key)
|
const idx = keyToIdx(event.key)
|
||||||
if (isNaN(key)) return
|
if (idx === null) return
|
||||||
state[key].boostEnabled = true;
|
state[idx].boostEnabled = true;
|
||||||
})
|
})
|
||||||
document.addEventListener("keyup", (event) => {
|
document.addEventListener("keyup", (event) => {
|
||||||
const key = parseInt(event.key)
|
const idx = keyToIdx(event.key)
|
||||||
if (isNaN(key)) return
|
if (idx === null) return
|
||||||
state[key].boostEnabled = false;
|
state[idx].boostEnabled = false;
|
||||||
})
|
})
|
||||||
|
|
||||||
function initialState() {
|
const params = new URLSearchParams(window.location.search);
|
||||||
state = teams.map((team) => ({
|
|
||||||
elim: false,
|
const modeLinks = document.getElementsByClassName("modeLink");
|
||||||
|
for (let i = 0; i < modeLinks.length; i++) {
|
||||||
|
let loc = new URL(window.location);
|
||||||
|
loc.searchParams.set("size", modeLinks[i].getAttribute("data-mode"));
|
||||||
|
modeLinks[i].href = loc.href;
|
||||||
|
}
|
||||||
|
|
||||||
|
function initialState({gridW = 4, gridH = 2, cols = teams.length, canvasW=1200, canvasH=800, squareSize=16} = {}) {
|
||||||
|
canvas.width = canvasW;
|
||||||
|
canvas.height = canvasH;
|
||||||
|
window.squareSize = squareSize;
|
||||||
|
|
||||||
|
numSquaresX = canvas.width / squareSize;
|
||||||
|
numSquaresY = canvas.height / squareSize;
|
||||||
|
|
||||||
|
state = {};
|
||||||
|
state = teams.map((team, idx) => ({
|
||||||
|
elim: idx >= cols,
|
||||||
boostEnabled: false,
|
boostEnabled: false,
|
||||||
x: 0,
|
x: 0,
|
||||||
y: 0,
|
y: 0,
|
||||||
@ -171,7 +229,7 @@
|
|||||||
score: 0,
|
score: 0,
|
||||||
// how many consecutive contested tiles it has hit
|
// how many consecutive contested tiles it has hit
|
||||||
conflict: 0,
|
conflict: 0,
|
||||||
}))
|
}));
|
||||||
|
|
||||||
// base noise pattern (failsafe in case the grid doesn't cover some part)
|
// base noise pattern (failsafe in case the grid doesn't cover some part)
|
||||||
for (let i = 0; i < numSquaresX; i++) {
|
for (let i = 0; i < numSquaresX; i++) {
|
||||||
@ -186,15 +244,13 @@
|
|||||||
|
|
||||||
const enableGrid = true;
|
const enableGrid = true;
|
||||||
if (enableGrid) {
|
if (enableGrid) {
|
||||||
const gridW = 4;
|
|
||||||
const gridH = 2;
|
|
||||||
for (let i = 0; i < gridW; i++) {
|
for (let i = 0; i < gridW; i++) {
|
||||||
for (let j = 0; j < gridH; j++) {
|
for (let j = 0; j < gridH; j++) {
|
||||||
const gridIdx = j * gridW + i;
|
const gridIdx = j * gridW + i;
|
||||||
const t = (gridIdx < teams.length) ? gridIdx : null;
|
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 x = Math.floor(i/gridW*numSquaresX); x < Math.ceil((i+1)/gridW*numSquaresX); x++) {
|
||||||
for (let y = Math.floor(j/gridH*numSquaresY); y < Math.floor((j+1)/gridH*numSquaresY); y++) {
|
for (let y = Math.floor(j/gridH*numSquaresY); y < Math.ceil((j+1)/gridH*numSquaresY); y++) {
|
||||||
if (t !== null) {
|
if (t !== null) {
|
||||||
squares[x][y] = t;
|
squares[x][y] = t;
|
||||||
}
|
}
|
||||||
@ -215,7 +271,19 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
initialState();
|
|
||||||
|
switch (params.get("size")) {
|
||||||
|
case "big":
|
||||||
|
initialState({gridW: 4, gridH: 3, cols: 12, canvasW: 1600, canvasH: 1000});
|
||||||
|
break;
|
||||||
|
case "small":
|
||||||
|
initialState({gridW: 2, gridH: 1, cols: 2, canvasW: 600, canvasH: 600, squareSize: 25});
|
||||||
|
break;
|
||||||
|
case "normal":
|
||||||
|
default:
|
||||||
|
initialState({gridW: 4, gridH: 2, cols: 8});
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
function randomNum(min, max) {
|
function randomNum(min, max) {
|
||||||
return Math.random() * (max - min) + min;
|
return Math.random() * (max - min) + min;
|
||||||
@ -392,7 +460,7 @@
|
|||||||
|
|
||||||
if (nTeams > 1) {
|
if (nTeams > 1) {
|
||||||
scoreElement.textContent = teams
|
scoreElement.textContent = teams
|
||||||
.map((t, idx) => `(${idx}) ${t.name} ${state[idx].score}`)
|
.map((t, idx) => `(${idxKeyMap[idx]}) ${t.name} ${state[idx].score}`)
|
||||||
.filter((t, idx) => !state[idx].elim)
|
.filter((t, idx) => !state[idx].elim)
|
||||||
.join(" | ") + (suddenDeathCoeff > 0.1 ? " | sudden death!" : "");
|
.join(" | ") + (suddenDeathCoeff > 0.1 ? " | sudden death!" : "");
|
||||||
} else {
|
} else {
|
||||||
@ -451,6 +519,6 @@
|
|||||||
requestAnimationFrame(draw);
|
requestAnimationFrame(draw);
|
||||||
}
|
}
|
||||||
|
|
||||||
requestAnimationFrame(draw);
|
requestAnimationFrame(draw);
|
||||||
</script>
|
</script>
|
||||||
</html>
|
</html>
|
||||||
|
Loading…
Reference in New Issue
Block a user