replace most systems with THREE
This commit is contained in:
+13
-7
@@ -1,25 +1,31 @@
|
||||
import { System } from 'detect-collisions'
|
||||
import { EventEmitter } from 'node:events'
|
||||
|
||||
export default class Game {
|
||||
entities = []
|
||||
tickRate = 30
|
||||
currentTick = 0
|
||||
width = 15000
|
||||
height = 15000
|
||||
|
||||
#entities = []
|
||||
#eventEmitter = new EventEmitter()
|
||||
#system = new System()
|
||||
#tickBudget = Math.floor(1000 / this.tickRate)
|
||||
|
||||
get entities() { return this.#entities }
|
||||
get eventEmitter() { return this.#eventEmitter }
|
||||
get system() { return this.#system }
|
||||
get tickBudget() { return this.#tickBudget }
|
||||
|
||||
spawn_entity(entity) {
|
||||
this.entities.push(entity)
|
||||
this.#system.insert(entity.collider)
|
||||
this.#entities.push(entity)
|
||||
entity.game = this
|
||||
}
|
||||
|
||||
state() {
|
||||
return {
|
||||
...this,
|
||||
entities: this.#entities.map((e) => e.state()),
|
||||
}
|
||||
}
|
||||
|
||||
async start() {
|
||||
const start = performance.now()
|
||||
await this.update()
|
||||
@@ -27,7 +33,7 @@ export default class Game {
|
||||
}
|
||||
|
||||
async update() {
|
||||
Promise.allSettled(this.entities.map((e) => e.update()))
|
||||
Promise.allSettled(this.#entities.map((e) => e.update()))
|
||||
this.currentTick++
|
||||
this.eventEmitter.emit('tick')
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user