You are browsing as a guest. Sign up (or log in) to start making projects!

1h 39m 48s logged


Dev Vlog #9 — Added Snake Game!


Hey everyone, welcome back to another WebOS update!

This time I made a game, quite a popular one, Snake Game.

Some lines of code to make its movement and food growth work, like:

currentWindows.map((appWindow) => {
  const game = appWindow.gameState?.snake;
  if (!game || game.status !== 'playing') return appWindow;

  const head = game.body[0];
  const direction = game.nextDirection;

  const nextHead = {
    x: (head.x + direction.x + SNAKE_SIZE) % SNAKE_SIZE,
    y: (head.y + direction.y + SNAKE_SIZE) % SNAKE_SIZE,
  };

  const hitSelf = game.body.some(
    (point) => point.x === nextHead.x && point.y === nextHead.y
  );

  if (hitSelf) {
    return {
      ...appWindow,
      gameState: {
        ...appWindow.gameState,
        snake: { ...game, status: 'lost' },
      },
    };
  }

It does not die when it hits the wall, but ends up on the other side of the screen. It dies when it hits itself.

OK then , its all for today if will make minesweeper next it may take AI to help , but i will try my best 🤧🤧


0
23

Comments 0

No comments yet. Be the first!