GrandTabernacleAutoVI/render.js
2023-11-14 17:53:29 +01:00

31 lines
No EOL
724 B
JavaScript

class Render {
constructor(id) {
this.canvas = document.getElementById(id);
this.ctx = canvas.getContext("2d");
this.players = [];
this.ReloadAff();
}
AddPlayer(player) {
this.players[player.id] = player;
}
RenderPlayer(player) {
const img = new Image();
img.src = "./assets/body.png";
this.ctx.save();
this.ctx.translate(player.x, player.y);
this.ctx.rotate(player.angle);
this.ctx.drawImage(img, -playerSize / 2, -playerSize / 2, playerSize, playerSize);
this.ctx.restore();
}
ReloadAff() {
this.ctx.fillStyle = "red";
this.ctx.fillRect(0,0,this.canvas.width,this.canvas.height);
this.players.forEach((player) => {
this.RenderPlayer(player);
})
}
}