add homing projectiles
This commit is contained in:
+15
-2
@@ -13,12 +13,25 @@ export default class Projectile {
|
||||
|
||||
#position = new Vector2()
|
||||
#dest = null
|
||||
#homingTarget = null
|
||||
#game = null
|
||||
|
||||
get collider() {
|
||||
return new SAT.Circle(new SAT.Vector(this.x, this.y), this.radius)
|
||||
}
|
||||
|
||||
get homing() {
|
||||
return !!this.#homingTarget
|
||||
}
|
||||
|
||||
get destination() {
|
||||
return this.#dest ?? this.#homingTarget?.position
|
||||
}
|
||||
|
||||
set homingTarget(value) {
|
||||
this.#homingTarget = value
|
||||
}
|
||||
|
||||
constructor(...options) {
|
||||
Object.entries(options).forEach((value, key) => this[key] = value)
|
||||
}
|
||||
@@ -43,7 +56,7 @@ export default class Projectile {
|
||||
}
|
||||
|
||||
checkIfArrived() {
|
||||
if (!this.#position.equals(this.#dest)) { return }
|
||||
if (!this.#position.equals(this.destination)) { return }
|
||||
|
||||
if (this.after != null) {
|
||||
this.after(this)
|
||||
@@ -68,7 +81,7 @@ export default class Projectile {
|
||||
|
||||
takeStep() {
|
||||
const speed = (this.speed / (this.game?.tickBudget ?? 1000))
|
||||
const destination = this.#dest
|
||||
const destination = this.destination
|
||||
const difference = destination.clone().sub(this.position)
|
||||
const distance = difference.length()
|
||||
const direction = difference.clone().normalize()
|
||||
|
||||
Reference in New Issue
Block a user