import Dvd from "./dvd.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 Dvd(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)) if (this.input.isInputPressed("attack")) console.log("attack!") if (this.input.isInputPressed("interact")) console.log("interact!") if (this.input.isInputPressed("up")) console.log("up!") if (this.input.isInputPressed("down")) console.log("down!") if (this.input.isInputPressed("left")) console.log("left!") if (this.input.isInputPressed("right")) console.log("right!") } draw() { const { canvas, ctx } = this ctx.fillStyle = "#222" ctx.fillRect(0, 0, canvas.width, canvas.height) this.actors.forEach(actor => actor.draw(ctx)) } }