The first thing I wrote when I made this blog was a 7-part tutorial series on writing a snake game in Java. Unfortunately, due to inexperience and the tutorial format, the code wasn't very well written and the result was rather sloppy. I decided to spend much of this morning rewriting a greatly improved version of the game from scratch.
The format for this post will be pretty much identical to my Tetris Tutorial. That is, the entire source will be will documented and available at the bottom of this post. If you have any questions about the code, or bugs to report, feel free to send me a message on YouTube, or leave a comment here.
Here are a list of improvements from the original version of the game:
- Larger grid (Was 20x20, now 25x25).
- Improved Input (Fixed the input polling system from the first series).
- Framerate now independent of update rate.
- Snake head looks different than body.
- Snake has a minimum length of 5.
- New sidebar displays statistics and controls.
- Improved scoring system (Was 100 points each, now decreases depending on how long it takes to reach it).
- Now uses pure Swing (Old version mixed AWT Canvas with Swing JFrame).