import Dvd from "./dvd.js" export default class Game { constructor(canvas) { this.canvas = canvas this.ctx = canvas.getContext("2d") this.timestamp = 0 this.actors = [] this.actors.push(new Dvd(this, 200, 200)) } 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) { this.actors.forEach(actor => actor.tick(dt)) } draw() { const { canvas, ctx } = this ctx.fillStyle = "#222" ctx.fillRect(0, 0, canvas.width, canvas.height) this.actors.forEach(actor => actor.draw(ctx)) } }