add tweening
This commit is contained in:
+9
-1
@@ -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() {
|
||||
|
||||
+6
-5
@@ -10,6 +10,7 @@ const game = new Game()
|
||||
|
||||
app.use('/', express.static('public'))
|
||||
app.use('/three/', express.static('node_modules/three'))
|
||||
app.use('/@tweenjs/', express.static('node_modules/@tweenjs'))
|
||||
app.use(express.urlencoded({ extended: true }))
|
||||
|
||||
app.ws('/ws', async (req, res) => {
|
||||
@@ -50,11 +51,11 @@ app.listen(port, () => {
|
||||
entity1.radius = 50
|
||||
game.spawn_entity(entity1)
|
||||
|
||||
// const entity2 = new Entity()
|
||||
// entity2.id = '2'
|
||||
// entity2.teleport(110, 110)
|
||||
// entity2.radius = 50
|
||||
// game.spawn_entity(entity2)
|
||||
const entity2 = new Entity()
|
||||
entity2.id = '2'
|
||||
entity2.teleport(110, 110)
|
||||
entity2.radius = 50
|
||||
game.spawn_entity(entity2)
|
||||
|
||||
// const triangle = new Terrain([
|
||||
// { x: 400, y: 200 },
|
||||
|
||||
Reference in New Issue
Block a user