NODE
node
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
"use strict"
function renderScreen(screen, game, requestAnimationFrame) {
console.log(game.state);
const ctx = screen.getContext("2d");
ctx.clearRect(0, 0, screen.width, screen.height);
for (const playerId in game.state.players) {
const player = game.state.players[playerId];
ctx.fillStyle = "#4c7370";
ctx.fillRect(player.x, player.y, 1, 1);
}
for (const fruitId in game.state.fruits) {
const fruit = game.state.fruits[fruitId];
ctx.fillStyle = "#90a32a";
ctx.fillRect(fruit.x, fruit.y, 1, 1);
}
requestAnimationFrame(() => renderScreen(screen, game, requestAnimationFrame));
}
export default renderScreen;
Enter to Rename, Shift+Enter to Preview
OUTPUT
Run