add visualRadius

This commit is contained in:
2025-01-17 17:51:00 +09:00
parent a44693aa5d
commit 80ccb92815
6 changed files with 76 additions and 59 deletions
+8 -2
View File
@@ -6,12 +6,13 @@ export default class Projectile {
id = crypto.randomUUID()
after = null
height = 50
memory = {} // TODO: WARNING: currently only used for hit detection (code smell?)
memory = {}
onCollide = null
owner = null
position = new Vector2()
radius = 5
speed = 1000
visualRadius = null
#dest = null
#homingTarget = null
@@ -28,6 +29,9 @@ export default class Projectile {
constructor(options = {}) {
Object.entries(options).forEach(([key, value]) => this[key] = value)
if (this.visualRadius == null) {
this.visualRadius = this.radius
}
}
checkCollisions(collider) {
@@ -39,7 +43,7 @@ export default class Projectile {
}
})
}
collider() {
return new SAT.Circle(new SAT.Vector(this.position.x, this.position.y), this.radius)
}
@@ -72,6 +76,8 @@ export default class Projectile {
}
#move() {
if (this.destination == null) { return }
const speed = (this.speed / (this.game?.tickBudget ?? 1000))
const prevPos = this.position.clone()
if (this.position.distanceTo(this.destination) < speed) {