game: simple js

This commit is contained in:
He4eT 2025-06-07 03:19:24 +02:00
commit 28961352f5

42
game.js
View file

@ -287,23 +287,21 @@ function spawnEnemies() {
return { x, y } return { x, y }
} }
enemies = Array(enemyCount) enemies = arr(enemyCount).map(() => {
.fill() const type = getType(arena.wave)
.map(() => { return {
const type = getType(arena.wave) type,
return { letter: 'e',
type, positions: [getSpawnPosition(), getSpawnPosition()],
letter: 'e', dangerZone: getDangerZone(type),
positions: [getSpawnPosition(), getSpawnPosition()], }
dangerZone: getDangerZone(type), })
}
})
enemies.forEach((enemy) => { enemies.forEach((enemy) => {
effects.unshift({ effects.unshift({
type: 'detection', type: 'detection',
to: enemy.positions[0], to: enemy.positions[0],
frames: Array(10).fill(4), frames: arr(10, 4),
}) })
}) })
} }
@ -416,6 +414,15 @@ function drawFX() {
/* Utils */ /* Utils */
function arr(n, filler) {
const result = []
for (let i = 0; i < n; i++) {
result.push(filler)
}
return result
}
function rnd(from, to) { function rnd(from, to) {
return Math.floor(Math.random() * (to - from + 1)) + from return Math.floor(Math.random() * (to - from + 1)) + from
} }
@ -438,9 +445,14 @@ const SCREEN_W = 240
const SCREEN_H = 136 const SCREEN_H = 136
/* Buttons */ /* Buttons */
const [BTN_U, BTN_D, BTN_L, BTN_R, BTN_A, BTN_B, BTN_X, BTN_Y] = [ const BTN_U = 0;
...Array(8).keys(), const BTN_D = 1;
] const BTN_L = 2;
const BTN_R = 3;
const BTN_A = 4;
const BTN_B = 5;
const BTN_X = 6;
const BTN_Y = 7;
/* Types */ /* Types */