mirror of
https://github.com/He4eT/DotDashPit.git
synced 2026-05-05 01:47:22 +00:00
game: destroy enemies by letter
This commit is contained in:
parent
ed8f297c7d
commit
d0206ef337
1 changed files with 26 additions and 16 deletions
42
game.js
42
game.js
|
|
@ -78,6 +78,7 @@ let player = {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @typedef {{
|
* @typedef {{
|
||||||
|
* letter: string,
|
||||||
* type: 'zombie',
|
* type: 'zombie',
|
||||||
* dangerZone: number,
|
* dangerZone: number,
|
||||||
* positions: Point[],
|
* positions: Point[],
|
||||||
|
|
@ -173,17 +174,31 @@ function handleMorse() {
|
||||||
player.sprite = btn(BTN_B) ? 65 : 64
|
player.sprite = btn(BTN_B) ? 65 : 64
|
||||||
|
|
||||||
if (btnp(BTN_B, 100, 100)) {
|
if (btnp(BTN_B, 100, 100)) {
|
||||||
if (enemies.length > 0) {
|
destroyEnemiesByLetter('e')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function destroyEnemiesByLetter(letter) {
|
||||||
|
const destructionEffects = [
|
||||||
|
['laser', [1, 2, 3, 4, 7, 7, 7, 6, 5, 4, 3, 2, 1]],
|
||||||
|
['nuke', [7, 6, 5, 4, 3, 2]],
|
||||||
|
['verticalLine', [4, 5, 6, 7, 7, 6, 5, 4]],
|
||||||
|
['horizontalLine', [4, 5, 6, 7, 7, 6, 5, 4]],
|
||||||
|
]
|
||||||
|
|
||||||
|
enemies
|
||||||
|
.filter((enemy) => enemy.letter === letter)
|
||||||
|
.forEach((enemy) => {
|
||||||
|
const [type, frames] = destructionEffects[rnd(0, 3)]
|
||||||
effects.unshift({
|
effects.unshift({
|
||||||
type: 'laser',
|
type,
|
||||||
|
frames,
|
||||||
from: player.position,
|
from: player.position,
|
||||||
to: enemies[0].positions[0],
|
to: enemy.positions[0],
|
||||||
frames: [1, 2, 3, 4, 7, 7, 7, 6, 5, 4, 3, 2, 1],
|
|
||||||
})
|
})
|
||||||
enemies.shift()
|
})
|
||||||
trace(enemies.length)
|
|
||||||
}
|
enemies = enemies.filter((enemy) => enemy.letter !== letter)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Enemies */
|
/* Enemies */
|
||||||
|
|
@ -199,6 +214,7 @@ function spawn() {
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
type: 'zombie',
|
type: 'zombie',
|
||||||
|
letter: 'e',
|
||||||
dangerZone: 8,
|
dangerZone: 8,
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
|
@ -206,7 +222,6 @@ function spawn() {
|
||||||
enemies.forEach((enemy) => {
|
enemies.forEach((enemy) => {
|
||||||
effects.unshift({
|
effects.unshift({
|
||||||
type: 'detection',
|
type: 'detection',
|
||||||
from: {},
|
|
||||||
to: enemy.positions[0],
|
to: enemy.positions[0],
|
||||||
frames: Array(5).fill(4),
|
frames: Array(5).fill(4),
|
||||||
})
|
})
|
||||||
|
|
@ -263,13 +278,12 @@ function drawFX() {
|
||||||
effects
|
effects
|
||||||
.map((effect) => ({
|
.map((effect) => ({
|
||||||
...effect,
|
...effect,
|
||||||
from: arenaToScreen(effect.from),
|
from: arenaToScreen(effect.from ?? {}),
|
||||||
to: arenaToScreen(effect.to),
|
to: arenaToScreen(effect.to ?? {}),
|
||||||
}))
|
}))
|
||||||
.forEach((effect) =>
|
.forEach((effect) =>
|
||||||
({
|
({
|
||||||
laser: ({ from, to, frames }) => {
|
laser: ({ from, to, frames }) => {
|
||||||
/* [1, 2, 3, 4, 7, 7, 7, 6, 5, 4, 3, 2, 1] */
|
|
||||||
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)
|
||||||
|
|
@ -277,22 +291,18 @@ function drawFX() {
|
||||||
circb(to.x, to.y, frames.length, color + 3)
|
circb(to.x, to.y, frames.length, color + 3)
|
||||||
},
|
},
|
||||||
nuke: ({ to, frames }) => {
|
nuke: ({ to, frames }) => {
|
||||||
/* [6, 5, 4, 3, 2] */
|
|
||||||
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 }) => {
|
||||||
/* [4, 5, 6, 7, 7, 6, 5, 4] */
|
|
||||||
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 }) => {
|
||||||
/* [4, 5, 6, 7, 7, 6, 5, 4] */
|
|
||||||
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 }) => {
|
||||||
/* Array(5).fill(4)] */
|
|
||||||
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
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue