game: inline effects

This commit is contained in:
He4eT 2025-06-05 19:33:29 +02:00
commit bb1a405c11

33
game.js
View file

@ -127,7 +127,7 @@ function handleMorse() {
x: enemies[0].x[0], x: enemies[0].x[0],
y: enemies[0].y[0], y: enemies[0].y[0],
}, },
frameColors: [1, 2, 3, 4, 7, 7, 7, 6, 5, 4, 3, 2, 1], frames: [1, 2, 3, 4, 7, 7, 7, 6, 5, 4, 3, 2, 1],
}) })
enemies.shift() enemies.shift()
trace(enemies.length) trace(enemies.length)
@ -193,26 +193,25 @@ function drawArena() {
} }
function drawFX() { function drawFX() {
const laser = (effect) => { effects
const color = effect.frameColors.shift() .map((effect) => ({
const from = arenaToScreen(effect.from) ...effect,
const to = arenaToScreen(effect.to) from: arenaToScreen(effect.from),
to: arenaToScreen(effect.to),
line(from.x, from.y, to.x, to.y, color) }))
.forEach((effect) =>
circ(from.x, from.y, effect.frameColors.length / 2, color)
circ(to.x, to.y, effect.frameColors.length / 2, color)
circb(to.x, to.y, effect.frameColors.length, color + 3)
}
effects.forEach((effect) =>
({ ({
laser, laser: ({ from, to, frames }) => {
const color = frames.shift()
line(from.x, from.y, to.x, to.y, color)
circ(from.x, from.y, frames.length / 2, color)
circ(to.x, to.y, frames.length / 2, color)
circb(to.x, to.y, frames.length, color + 3)
},
})[effect.type](effect), })[effect.type](effect),
) )
effects = effects.filter(({ frameColors }) => frameColors.length > 0) effects = effects.filter(({ frames }) => frames.length > 0)
} }
function drawEnemies() { function drawEnemies() {