1
0
Fork 0

Update docstring

This commit is contained in:
Ethanell 2021-03-30 08:32:00 +02:00
parent 705afa9dfd
commit 5ea8760ed2
2 changed files with 9 additions and 1 deletions

View file

@ -155,7 +155,6 @@ export class Game {
/** /**
* Update the snake on the world and check for collision * Update the snake on the world and check for collision
*/ */
updateSnake() { updateSnake() {
this.snake.body.forEach(([x,y], i) => { this.snake.body.forEach(([x,y], i) => {
if (!(x in this.world) || !(y in this.world[x])) if (!(x in this.world) || !(y in this.world[x]))

View file

@ -191,6 +191,10 @@ export class Tile {
this.game.ctx.stroke(); this.game.ctx.stroke();
} }
/**
* Get the direction of a sprite depending of the next sprite
* @returns {directions}
*/
getDirection() { getDirection() {
const np = this.game.snake.body[this.game.snake.body.findIndex(([x,y]) => x === this.x && y === this.y)-1]; 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])); 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); 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) { rotate(canvasPos, size) {
const cx = canvasPos[0] + 0.5 * size[0]; const cx = canvasPos[0] + 0.5 * size[0];
const cy = canvasPos[1] + 0.5 * size[1]; const cy = canvasPos[1] + 0.5 * size[1];