Snake is a classic video game in which a player controls a Snake that must eat apples and avoid walls. Each time, you eat an apple, the Snake grows. The Snake’s goal is to eat the maximum of apples.¬†It’s a game of kind infinite. Snake is also an ideal game to create when you want to learn to create 2D games in Java. In this tutorial, you’re going to learn how to create a Snake in Java 2D with Swing. The tutorial is in video, so you can follow the creation of the game step by step. It has 8 parts :

1. Creation of the Board and constants for the game

 

2. Images loading and Timer starting

 

3. Define the draw method to display the Snake on the screen

 

4. Define key algorithm for the game with the move and checkCollision methods

 

5. Create the Event Loop for the game

 

6. Manage user events to move the Snake

 

7. Assemble all the pieces of the puzzle

 

8. Play with the Snake !