Where to Go From Here?
Download the complete project files by clicking the Download Materials button at the top or bottom of the tutorial. If you want to play around with the code some more, here are a few things you can add to make it more interesting and fun:
- Add collision detection so the game ends if the snake collides with itself. Since you have the position of each and every
Piece
that makes up the snake, it isn't hard to determine whether the snake has run into itself.
- Restrict the snake's movement so it can't double back in the opposite direction of the one it's currently heading in.
- Allow the users to choose if they really want to challenge themselves. If you want to level up the game to hardcore mode, you need to make the speed increases faster and the score increases slower. This makes the game harder.
- You can also keep track of all users' scores. This adds a competitive element to the game by telling the players the scores of all the other players. Who doesn't want to be the top-scoring player?
- Finally, adding sounds to the game will make it much more fun.
Here are a couple of articles that will be helpful in learning more about widgets, drawing and animations in Flutter.
We hope you enjoyed this tutorial. If you have any questions or comments, please join the forum discussion below!