Skip to content

Propositions de jeu à ajouter à coté du Space Invader #2

Answered by cyrilnapo
estebanstb asked this question in Q&A
Discussion options

You must be logged in to vote

import {apple} from './main.js';
import { RandomPositionX, RandomPositionY } from './apple.js';

let score = 0;

class Snake {
constructor(x, y, size) {
this.x = x;
this.y = y;
this.size = size;
this.segments = [{ x, y }];
}

//affiche le serpent
draw(snake) {
  snake.fillStyle = 'rgb(30, 110, 124)';
  for (let segment of this.segments) {
    snake.fillRect(segment.x, segment.y, this.size, this.size);
  }
}

//gère l'avancement du serpent sur le terrain
move(direction) {
  const head = { ...this.segments[0] };
  if (direction == 0) {
    head.y -= 50;
  } else if (direction == 1) {
    head.y += 50;
  } else if (direction == 2) {
    head.x -= 50;
  } else if (direction == 3) {
    head.x +=…

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by estebanstb
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants