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:
+32
@@ -0,0 +1,32 @@
|
||||
import { System } from 'detect-collisions'
|
||||
import { EventEmitter } from 'node:events'
|
||||
|
||||
export default class Game {
|
||||
entities = []
|
||||
tickRate = 30
|
||||
currentTick = 0
|
||||
|
||||
#eventEmitter = new EventEmitter()
|
||||
#system = new System()
|
||||
#tickBudget = Math.floor(1000 / this.tickRate)
|
||||
|
||||
get eventEmitter() { return this.#eventEmitter }
|
||||
get system() { return this.#system }
|
||||
|
||||
spawn_entity(entity) {
|
||||
this.entities.push(entity)
|
||||
this.#system.insert(entity.collider)
|
||||
}
|
||||
|
||||
async start() {
|
||||
const start = performance.now()
|
||||
await this.update()
|
||||
setTimeout(() => this.start(), Math.max(0, this.#tickBudget - (performance.now() - start)))
|
||||
}
|
||||
|
||||
async update() {
|
||||
Promise.allSettled(this.entities.map((e) => e.update()))
|
||||
this.currentTick++
|
||||
this.eventEmitter.emit('tick')
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user