mirror of
https://github.com/He4eT/DotDashPit.git
synced 2026-05-05 01:47:22 +00:00
game: safe spawn
This commit is contained in:
parent
d0206ef337
commit
0c8670a0cf
1 changed files with 35 additions and 22 deletions
57
game.js
57
game.js
|
|
@ -40,6 +40,7 @@ let currentStage = 'mainMenu'
|
||||||
* screenPosition: Point,
|
* screenPosition: Point,
|
||||||
* bounds: Bounds,
|
* bounds: Bounds,
|
||||||
* spriteHalfSize: number,
|
* spriteHalfSize: number,
|
||||||
|
* wave: number,
|
||||||
* }} Arena
|
* }} Arena
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
@ -56,6 +57,7 @@ let arena = {
|
||||||
left: 0,
|
left: 0,
|
||||||
},
|
},
|
||||||
spriteHalfSize: 3,
|
spriteHalfSize: 3,
|
||||||
|
wave: 0,
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -204,29 +206,40 @@ function destroyEnemiesByLetter(letter) {
|
||||||
/* Enemies */
|
/* Enemies */
|
||||||
|
|
||||||
function spawn() {
|
function spawn() {
|
||||||
if (enemies.length === 0) {
|
if (enemies.length > 0) {
|
||||||
enemies = [
|
return
|
||||||
{
|
|
||||||
positions: [
|
|
||||||
{
|
|
||||||
x: Math.random() * arena.bounds.right,
|
|
||||||
y: Math.random() * arena.bounds.bottom,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
type: 'zombie',
|
|
||||||
letter: 'e',
|
|
||||||
dangerZone: 8,
|
|
||||||
},
|
|
||||||
]
|
|
||||||
|
|
||||||
enemies.forEach((enemy) => {
|
|
||||||
effects.unshift({
|
|
||||||
type: 'detection',
|
|
||||||
to: enemy.positions[0],
|
|
||||||
frames: Array(5).fill(4),
|
|
||||||
})
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
arena.wave += 1
|
||||||
|
|
||||||
|
const getSpawnPosition = () => {
|
||||||
|
const minDistance = 50
|
||||||
|
let x, y, distance
|
||||||
|
do {
|
||||||
|
x = rnd(arena.bounds.left, arena.bounds.right)
|
||||||
|
y = rnd(arena.bounds.top, arena.bounds.bottom)
|
||||||
|
distance = Math.hypot(x - player.position.x, y - player.position.y)
|
||||||
|
} while (distance < minDistance)
|
||||||
|
|
||||||
|
return { x, y }
|
||||||
|
}
|
||||||
|
|
||||||
|
enemies = [
|
||||||
|
{
|
||||||
|
positions: [getSpawnPosition()],
|
||||||
|
type: 'zombie',
|
||||||
|
letter: 'e',
|
||||||
|
dangerZone: 8,
|
||||||
|
},
|
||||||
|
]
|
||||||
|
|
||||||
|
enemies.forEach((enemy) => {
|
||||||
|
effects.unshift({
|
||||||
|
type: 'detection',
|
||||||
|
to: enemy.positions[0],
|
||||||
|
frames: Array(5).fill(4),
|
||||||
|
})
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
function checkColisions() {
|
function checkColisions() {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue