Making the snake die

Tired of playing with "God Mode" on? Ok, let's make the snake die.

The idea: The snake will die if one of these conditions is verified:

  1. The snake's head hits a wall
  2. The snake's head hits any part of the snake's body
  3. The snake's head leaves the stage

In some versions of the game, when the snake leaves the stage crossing through one boundary, it appears on the opposite side, but in this game the snake cannot leave the stage.

Also, the snake has only one life, so when the snake dies, it's game over.

The development: Each time the snake moves, we must check if the head is in the same tile occupied by an obstacle or by a piece of the snake's body. Also, we must check if the head is in the stage.

But first, let's see what should happen ...

Get Flash Game Development by Example now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.