mirror of
https://github.com/He4eT/DotDashPit.git
synced 2026-05-05 01:47:22 +00:00
game: extract effectHandlers
This commit is contained in:
parent
8e6723efc3
commit
66a70082cf
1 changed files with 40 additions and 42 deletions
78
game.js
78
game.js
|
|
@ -358,45 +358,45 @@ function drawArena() {
|
||||||
}
|
}
|
||||||
|
|
||||||
const effectHandlers = {
|
const effectHandlers = {
|
||||||
laser: ({ from, to, frames }) => {
|
laser: ({ from, to, frames }) => {
|
||||||
const color = frames.shift()
|
const color = frames.shift()
|
||||||
line(from.x, from.y, to.x, to.y, color)
|
line(from.x, from.y, to.x, to.y, color)
|
||||||
circ(from.x, from.y, frames.length / 3, color)
|
circ(from.x, from.y, frames.length / 3, color)
|
||||||
circ(to.x, to.y, frames.length / 2, color)
|
circ(to.x, to.y, frames.length / 2, color)
|
||||||
circb(to.x, to.y, frames.length, color + 3)
|
circb(to.x, to.y, frames.length, color + 3)
|
||||||
},
|
},
|
||||||
nuke: ({ to, frames }) => {
|
nuke: ({ to, frames }) => {
|
||||||
const color = frames.shift()
|
const color = frames.shift()
|
||||||
circ(to.x, to.y, Math.pow(frames.length, 5), color)
|
circ(to.x, to.y, Math.pow(frames.length, 5), color)
|
||||||
},
|
},
|
||||||
verticalLine: ({ to, frames }) => {
|
verticalLine: ({ to, frames }) => {
|
||||||
const color = frames.shift()
|
const color = frames.shift()
|
||||||
rect(0, to.y - frames.length, SCREEN_W, frames.length * 2, color)
|
rect(0, to.y - frames.length, SCREEN_W, frames.length * 2, color)
|
||||||
},
|
},
|
||||||
horizontalLine: ({ to, frames }) => {
|
horizontalLine: ({ to, frames }) => {
|
||||||
const color = frames.shift()
|
const color = frames.shift()
|
||||||
rect(to.x - frames.length, 0, frames.length * 2, SCREEN_W, color)
|
rect(to.x - frames.length, 0, frames.length * 2, SCREEN_W, color)
|
||||||
},
|
},
|
||||||
detection: ({ to, frames }) => {
|
detection: ({ to, frames }) => {
|
||||||
const color = frames.shift()
|
const color = frames.shift()
|
||||||
const w = arena.spriteHalfSize
|
const w = arena.spriteHalfSize
|
||||||
const d = frames.length + 2 * w
|
const d = frames.length + 2 * w
|
||||||
const corners = [
|
const corners = [
|
||||||
[+1, +1],
|
[+1, +1],
|
||||||
[+1, -1],
|
[+1, -1],
|
||||||
[-1, +1],
|
[-1, +1],
|
||||||
[-1, -1],
|
[-1, -1],
|
||||||
]
|
]
|
||||||
|
|
||||||
corners.forEach(([dx, dy]) => {
|
corners.forEach(([dx, dy]) => {
|
||||||
const x = to.x + dx * d
|
const x = to.x + dx * d
|
||||||
const y = to.y + dy * d
|
const y = to.y + dy * d
|
||||||
|
|
||||||
line(x, y, x - dx * w, y, color)
|
line(x, y, x - dx * w, y, color)
|
||||||
line(x, y, x, y - dy * w, color)
|
line(x, y, x, y - dy * w, color)
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
function drawFX() {
|
function drawFX() {
|
||||||
effects
|
effects
|
||||||
|
|
@ -405,9 +405,7 @@ function drawFX() {
|
||||||
from: arenaToScreen(effect.from ?? {}),
|
from: arenaToScreen(effect.from ?? {}),
|
||||||
to: arenaToScreen(effect.to ?? {}),
|
to: arenaToScreen(effect.to ?? {}),
|
||||||
}))
|
}))
|
||||||
.forEach((effect) =>
|
.forEach((effect) => effectHandlers[effect.type](effect))
|
||||||
effectHandlers[effect.type](effect),
|
|
||||||
)
|
|
||||||
|
|
||||||
effects = effects.filter(({ frames }) => frames.length > 0)
|
effects = effects.filter(({ frames }) => frames.length > 0)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue