fix vision logic and game tick timer

This commit is contained in:
2025-01-20 11:17:35 +09:00
parent bf38f69071
commit 6b8a220f39
7 changed files with 89 additions and 32 deletions
+19 -2
View File
@@ -64,8 +64,24 @@ export default class Projectile {
if (entities == null) { return }
const entitiesInVisionRange = entities.filter((it) => it.id != this.id && it.distanceTo(this.position) <= this.visionRange + it.radius)
const entitiesInLineOfSight = entitiesInVisionRange.filter((it) => this.isInLineOfVision(it.position))
return entitiesInVisionRange.concat([this]).map((it) => it.id)
return entitiesInLineOfSight.concat([this]).map((it) => it.id)
}
isInLineOfVision(destination) {
const bbox = Entity.tunnelBbox(this.position.x, this.position.y, destination.x, destination.y, 0)
const terrains = this.game?.terrains ?? []
const bboxCheckedObstacles = terrains.filter((it) => SATX.bboxCheck(bbox, it.bbox))
if (bboxCheckedObstacles.length < 1) { return true }
const posCollider = Entity.collider(this.position.x, this.position.y, 1) // TODO: magic number for radius
const posBbox = Entity.bbox(this.position.x, this.position.y, 1) // TODO: magic number for radius
const unpassableTerrain = bboxCheckedObstacles.filter((it) => !(SATX.bboxCheck(posBbox, it.bbox) && it.colliders().some((c) => SATX.collideObject(posCollider, c))))
const colliders = unpassableTerrain.map((it) => it.colliders()).flat()
const collider = Entity.tunnelCollider(this.position.x, this.position.y, destination.x, destination.y, 0)
return !colliders.some((it) => SATX.collideObject(collider, it))
}
setPosition(vector) {
@@ -87,8 +103,9 @@ export default class Projectile {
if (projectiles == null) { return }
const projectilesInVisionRange = projectiles.filter((it) => this.position.distanceTo(it.position) <= this.visionRange + it.radius)
const projectilesInLineOfSight = projectilesInVisionRange.filter((it) => it.visibleThroughTerrain || this.isInLineOfVision(it.position))
return projectilesInVisionRange.map((it) => it.id)
return projectilesInLineOfSight.concat([this]).map((it) => it.id)
}
#calculateBbox() {