From 5ea8760ed233deba0c444de627c8d86cf8458aeb Mon Sep 17 00:00:00 2001 From: flifloo Date: Tue, 30 Mar 2021 08:32:00 +0200 Subject: [PATCH] Update docstring --- sources/js/Game.js | 1 - sources/js/Tile.js | 9 +++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/sources/js/Game.js b/sources/js/Game.js index 5c0a724..a641870 100644 --- a/sources/js/Game.js +++ b/sources/js/Game.js @@ -155,7 +155,6 @@ export class Game { /** * Update the snake on the world and check for collision */ - updateSnake() { this.snake.body.forEach(([x,y], i) => { if (!(x in this.world) || !(y in this.world[x])) diff --git a/sources/js/Tile.js b/sources/js/Tile.js index e89f465..0a6837b 100644 --- a/sources/js/Tile.js +++ b/sources/js/Tile.js @@ -191,6 +191,10 @@ export class Tile { this.game.ctx.stroke(); } + /** + * Get the direction of a sprite depending of the next sprite + * @returns {directions} + */ getDirection() { const np = this.game.snake.body[this.game.snake.body.findIndex(([x,y]) => x === this.x && y === this.y)-1]; const d = [this.x, this.y].map((n, i) => -(n - np[i])); @@ -198,6 +202,11 @@ export class Tile { return Object.values(directions).find(([x, y]) => d[0] === x && d[1] === y); } + /** + * Rotate a sprite depending of the input direction or the next sprite + * @param {[int, int]} canvasPos + * @param {[int, int]} size + */ rotate(canvasPos, size) { const cx = canvasPos[0] + 0.5 * size[0]; const cy = canvasPos[1] + 0.5 * size[1];