make projectiles use bounding boxes too
This commit is contained in:
+22
-9
@@ -25,6 +25,7 @@ export default class Entity {
|
||||
visualRadius = null
|
||||
|
||||
#attacking = false
|
||||
#colliders = []
|
||||
#dest = null
|
||||
#game = null
|
||||
#logic = null
|
||||
@@ -123,6 +124,8 @@ export default class Entity {
|
||||
if (this.visualRadius == null) {
|
||||
this.visualRadius = this.radius
|
||||
}
|
||||
|
||||
this.#calculateCollider()
|
||||
}
|
||||
|
||||
get attacking() { return this.#attacking }
|
||||
@@ -256,11 +259,11 @@ export default class Entity {
|
||||
}
|
||||
|
||||
collider() {
|
||||
return Entity.collider(this.position.x, this.position.y, this.radius)
|
||||
return this.#colliders.at(0)
|
||||
}
|
||||
|
||||
colliders() {
|
||||
return [this.collider()]
|
||||
return this.#colliders
|
||||
}
|
||||
|
||||
cooldown(id) {
|
||||
@@ -329,7 +332,10 @@ export default class Entity {
|
||||
}
|
||||
|
||||
fixPosition() {
|
||||
this.position = this.fixFuturePosition(this.position.clone()).clone()
|
||||
const fixedPosition = this.fixFuturePosition(this.position)
|
||||
if (this.position.equals(fixedPosition)) { return }
|
||||
|
||||
this.setPosition(fixedPosition)
|
||||
}
|
||||
|
||||
fixFuturePosition(futurePosition) {
|
||||
@@ -400,14 +406,18 @@ export default class Entity {
|
||||
}
|
||||
|
||||
respawn() {
|
||||
this.position = this.#spawnPosition.clone()
|
||||
this.setPosition(this.#spawnPosition)
|
||||
this.health = this.maxHealth
|
||||
this.dead = false
|
||||
}
|
||||
|
||||
setPosition(vector) {
|
||||
this.position.copy(vector)
|
||||
this.#calculateCollider()
|
||||
}
|
||||
|
||||
teleport(cursor) {
|
||||
this.position = cursor.clone()
|
||||
this.fixPosition()
|
||||
this.setPosition(this.fixFuturePosition(cursor))
|
||||
}
|
||||
|
||||
update() {
|
||||
@@ -425,8 +435,6 @@ export default class Entity {
|
||||
if (this.#logic != null) {
|
||||
this.#logic()
|
||||
}
|
||||
|
||||
this.#calculateBbox()
|
||||
}
|
||||
|
||||
waypoints() {
|
||||
@@ -456,6 +464,11 @@ export default class Entity {
|
||||
this.bbox[3] = this.position.x - this.radius
|
||||
}
|
||||
|
||||
#calculateCollider() {
|
||||
this.#calculateBbox()
|
||||
this.#colliders = [Entity.collider(this.position.x, this.position.y, this.radius)]
|
||||
}
|
||||
|
||||
#cast() {
|
||||
if (this.casting == null) {
|
||||
return false
|
||||
@@ -574,7 +587,7 @@ export default class Entity {
|
||||
this.rotation = rotation
|
||||
|
||||
if (!this.willCollide(position)) {
|
||||
this.position.copy(position)
|
||||
this.setPosition(position)
|
||||
}
|
||||
|
||||
if (this.position.equals(destination)) {
|
||||
|
||||
Reference in New Issue
Block a user