Buff Queen AKA "Ez egy fa?"
Because the first placeholder player model resembled a queen that's been to the gym a bit too much. Also, before she got her head and hands, she looked like a tree, legit.
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
import { Circle } from 'detect-collisions'
|
||||
import Victor from 'victor'
|
||||
|
||||
export default class Entity {
|
||||
id = crypto.randomUUID()
|
||||
pos = new Victor(0, 0)
|
||||
radius = 0
|
||||
#collider = null
|
||||
#dest = null
|
||||
#game = null
|
||||
|
||||
constructor(...options) {
|
||||
Object.entries(options).forEach((value, key) => this[key] = value)
|
||||
this.#collider = new Circle(this.pos, this.radius)
|
||||
}
|
||||
|
||||
get collider() { return this.#collider }
|
||||
get game() { return this.#game }
|
||||
get system() { return this.game?.system }
|
||||
set game(value) { this.#game = value }
|
||||
|
||||
moveAction(x, y) {
|
||||
this.#dest = new Victor(x, y)
|
||||
}
|
||||
|
||||
async takeStep() {
|
||||
if (this.#dest != null) {
|
||||
this.pos.add(this.#dest.clone().subtract(this.pos).normalize())
|
||||
if (this.pos.clone().subtract(this.#dest).length() <= 1) {
|
||||
this.pos = this.#dest
|
||||
this.#dest = null
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async updateCollider() {
|
||||
if (this.pos.x != this.collider.pos.x || this.pos.y != this.collider.pos.y || this.radius != this.collider.unscaledRadius) {
|
||||
this.system?.remove(this.#collider)
|
||||
this.#collider = new Circle(this.pos, this.radius)
|
||||
this.system?.insert(this.#collider)
|
||||
}
|
||||
}
|
||||
|
||||
async update() {
|
||||
await Promise.allSettled([
|
||||
this.updateCollider(),
|
||||
this.takeStep(),
|
||||
])
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user