fix dead state

This commit is contained in:
2025-01-22 22:52:08 +09:00
parent 4f8dcebcd1
commit 0db1ceeedc
10 changed files with 263 additions and 43 deletions
+7 -8
View File
@@ -19,21 +19,18 @@ export default class Game {
tickRate = 30
width = 0
#eventEmitter = new EventEmitter()
#gameLoopIntervalId = null
#logic = null
#nextTickAt = 0
#startTimestamp = 0
#subscriptions = new Map()
#tickBudget = 1000 / this.tickRate
get logic() { return this.#logic }
get eventEmitter() { return this.#eventEmitter }
get tickBudget() { return this.#tickBudget }
set logic(value) { this.#logic = value }
get subscriptions() { return this.#subscriptions }
constructor() {
this.#eventEmitter.setMaxListeners(20)
}
set logic(value) { this.#logic = value }
action(id, options) {
const entity = this.entities.find((it) => it.id == id)
@@ -140,6 +137,10 @@ export default class Game {
}
update() {
for (const subscription of this.#subscriptions.values()) {
subscription()
}
const callUpdate = function callUpdate(object) { object.update() }
this.entities.forEach(callUpdate) // TODO: entity with lower ID has unfair collision advantage (regular loop + until it fully loops around with an offset?)
this.projectiles.forEach(callUpdate)
@@ -147,8 +148,6 @@ export default class Game {
this.#logic()
}
this.eventEmitter.emit('tick')
this.currentTick++
}