mirror of
https://github.com/He4eT/DotDashPit.git
synced 2026-05-04 17:37:23 +00:00
game: reuse bounce behaviour for fidget
This commit is contained in:
parent
3dbf1cc498
commit
2a921c439e
1 changed files with 8 additions and 32 deletions
40
game.js
40
game.js
|
|
@ -132,41 +132,17 @@ const enemyBlueprints = {
|
||||||
dangerZone: 8,
|
dangerZone: 8,
|
||||||
value: 3,
|
value: 3,
|
||||||
behaviour: (enemy) => {
|
behaviour: (enemy) => {
|
||||||
const minSpeed = 0.4
|
if (Math.random() < 0.05) {
|
||||||
const speed = Math.max(minSpeed, enemy.speed)
|
|
||||||
const current = enemy.positions[0]
|
|
||||||
const previous = enemy.positions[1] || current
|
|
||||||
|
|
||||||
let d = getDirection(previous, current)
|
|
||||||
|
|
||||||
if (Math.random() < 0.05 || (d.x === 0 && d.y === 0)) {
|
|
||||||
const angle = Math.random() * 2 * Math.PI
|
const angle = Math.random() * 2 * Math.PI
|
||||||
d = {
|
const current = enemy.positions[0]
|
||||||
x: Math.cos(angle),
|
const randomPrevious = {
|
||||||
y: Math.sin(angle),
|
x: current.x - Math.cos(angle),
|
||||||
|
y: current.y - Math.sin(angle),
|
||||||
}
|
}
|
||||||
|
enemy.positions[1] = randomPrevious
|
||||||
}
|
}
|
||||||
|
|
||||||
let dx = d.x * speed
|
enemyBlueprints.bounce.behaviour(enemy)
|
||||||
let dy = d.y * speed
|
|
||||||
|
|
||||||
let newX = current.x + dx
|
|
||||||
let newY = current.y + dy
|
|
||||||
|
|
||||||
if (newX < arena.bounds.left || newX > arena.bounds.right) {
|
|
||||||
dx = -dx
|
|
||||||
newX = current.x + dx
|
|
||||||
}
|
|
||||||
|
|
||||||
if (newY < arena.bounds.top || newY > arena.bounds.bottom) {
|
|
||||||
dy = -dy
|
|
||||||
newY = current.y + dy
|
|
||||||
}
|
|
||||||
|
|
||||||
enemy.positions = [
|
|
||||||
{ x: newX, y: newY },
|
|
||||||
{ x: current.x, y: current.y },
|
|
||||||
]
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
bounce: {
|
bounce: {
|
||||||
|
|
@ -176,7 +152,7 @@ const enemyBlueprints = {
|
||||||
dangerZone: 8,
|
dangerZone: 8,
|
||||||
value: 5,
|
value: 5,
|
||||||
behaviour: (enemy) => {
|
behaviour: (enemy) => {
|
||||||
const minSpeed = 0.7
|
const minSpeed = 0.6
|
||||||
const speed = Math.max(minSpeed, enemy.speed)
|
const speed = Math.max(minSpeed, enemy.speed)
|
||||||
const current = enemy.positions[0]
|
const current = enemy.positions[0]
|
||||||
const previous = enemy.positions[1]
|
const previous = enemy.positions[1]
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue