add tweening

This commit is contained in:
2025-01-11 19:38:40 +09:00
parent 4aba510ec0
commit 462dfe7b9a
6 changed files with 56 additions and 25 deletions
+9 -1
View File
@@ -72,6 +72,10 @@ export default class Entity {
return entityColliders.concat(terrainColliders)
}
fixPosition() {
this.#position = SATX.fixCollisions(this.#position, this.collidables(), this.radius, this.game?.width, this.game?.height)
}
isColliding(...colliders) {
return SATX.collideObjects(this.collider, colliders)
}
@@ -91,9 +95,12 @@ export default class Entity {
}
teleport(x, y) {
this.position.set(x, y)
const position = SATX.fixCollisions(new Vector2(x, y), this.collidables(), this.radius, this.game?.width, this.game?.height)
this.position.set(position.x, position.y)
}
// TODO: unset destination on teleports, etc.
// TODO: recalculate path on obstructions (currently next waypoint is used)
takeStep(distanceTraveled = 0) {
const speed = (this.speed / (this.game?.tickBudget ?? 1000)) - distanceTraveled
const collidables = this.collidables()
@@ -140,6 +147,7 @@ export default class Entity {
update() {
this.takeStep()
this.fixPosition()
}
waypoints() {