2025-06-01 15:54:55 -04:00
|
|
|
import Dvd from "./dvd.js"
|
|
|
|
|
2025-06-01 15:30:12 -04:00
|
|
|
export default class Game {
|
|
|
|
constructor(canvas) {
|
|
|
|
this.canvas = canvas
|
|
|
|
this.ctx = canvas.getContext("2d")
|
2025-06-01 15:37:12 -04:00
|
|
|
this.timestamp = 0
|
2025-06-01 15:54:55 -04:00
|
|
|
this.actors = []
|
|
|
|
this.actors.push(new Dvd(this, 200, 200))
|
2025-06-01 15:37:12 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
start() {
|
|
|
|
requestAnimationFrame(this.loop.bind(this))
|
|
|
|
}
|
|
|
|
|
|
|
|
loop(timestamp) {
|
|
|
|
const dt = timestamp - this.timestamp
|
|
|
|
this.timestamp = timestamp
|
|
|
|
this.tick(dt)
|
|
|
|
this.draw()
|
|
|
|
|
|
|
|
requestAnimationFrame(this.loop.bind(this))
|
|
|
|
}
|
|
|
|
|
|
|
|
tick(dt) {
|
2025-06-01 15:54:55 -04:00
|
|
|
this.actors.forEach(actor => actor.tick(dt))
|
2025-06-01 15:30:12 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
draw() {
|
|
|
|
const { canvas, ctx } = this
|
2025-06-01 15:54:55 -04:00
|
|
|
ctx.fillStyle = "#222"
|
|
|
|
ctx.fillRect(0, 0, canvas.width, canvas.height)
|
|
|
|
this.actors.forEach(actor => actor.draw(ctx))
|
2025-06-01 15:30:12 -04:00
|
|
|
}
|
|
|
|
}
|