import Player from "./player.js" import Input from "./input.js" export default class Game { constructor(canvas) { this.canvas = canvas this.ctx = canvas.getContext("2d") this.timestamp = 0 this.actors = [] this.actors.push(new Player(this, 200, 200)) this.input = new Input().initialize() } 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.drawImage(this.assets.get("tilesheet"), 0, 0) this.actors.forEach(actor => actor.draw(ctx)) } }