add vision
This commit is contained in:
+24
-3
@@ -1,7 +1,7 @@
|
||||
import { Vector2 } from 'three'
|
||||
import Entity from './entity.js'
|
||||
import SAT from 'sat'
|
||||
import SATX from './satx.js'
|
||||
import Entity from './entity.js'
|
||||
|
||||
export default class Projectile {
|
||||
id = `projectile-${Projectile.nextId()}`
|
||||
@@ -13,8 +13,11 @@ export default class Projectile {
|
||||
memory = {}
|
||||
owner = null
|
||||
position = new Vector2()
|
||||
radius = 5
|
||||
radius = 0
|
||||
speed = 1000
|
||||
team = null
|
||||
visibleThroughTerrain = true
|
||||
visionRange = 0
|
||||
visualRadius = null
|
||||
|
||||
#after = null
|
||||
@@ -56,6 +59,15 @@ export default class Projectile {
|
||||
this.game?.despawn(this)
|
||||
}
|
||||
|
||||
entitiesInVision() {
|
||||
const entities = this.game?.entities
|
||||
if (entities == null) { return }
|
||||
|
||||
const entitiesInVisionRange = entities.filter((it) => it.id != this.id && it.distanceTo(this.position) <= this.visionRange + it.radius)
|
||||
|
||||
return entitiesInVisionRange.concat([this]).map((it) => it.id)
|
||||
}
|
||||
|
||||
setPosition(vector) {
|
||||
this.position.copy(vector)
|
||||
this.#calculateBbox()
|
||||
@@ -66,10 +78,19 @@ export default class Projectile {
|
||||
this.#checkStationaryCollisions()
|
||||
this.#checkIfArrived()
|
||||
if (this.#logic != null) {
|
||||
this.#logic()
|
||||
this.#logic(this)
|
||||
}
|
||||
}
|
||||
|
||||
projectilesInVision() {
|
||||
const projectiles = this.game?.projectiles
|
||||
if (projectiles == null) { return }
|
||||
|
||||
const projectilesInVisionRange = projectiles.filter((it) => this.position.distanceTo(it.position) <= this.visionRange + it.radius)
|
||||
|
||||
return projectilesInVisionRange.map((it) => it.id)
|
||||
}
|
||||
|
||||
#calculateBbox() {
|
||||
this.bbox[0] = this.position.y + this.radius
|
||||
this.bbox[1] = this.position.x + this.radius
|
||||
|
||||
Reference in New Issue
Block a user