Skip to content

🐍 A simple snake game made in python inspired by the following amazing tutorial with some modifications : https://www.youtube.com/watch?v=QFvqStqPCRU

Notifications You must be signed in to change notification settings

Moodrammer/snake-game-python

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Welcome to Snake 🐍 game !

✅ Todo:

  • Add Sounds to the game.
  • Add a gameover screen displaying the final score.
  • Add a two-player mode with two snakes.
  • Some code refactoring.
  • Train an RL agent to play the game.

grass_border grass_border grass_border grass_border grass_border grass_border grass_border grass_border grass_border grass_border grass_border grass_border grass_border grass_border grass_border grass_border grass_border

🎨 Game Sprites

All sprites are drawn by me 😊 using the following website pixel art tool Pixilart

tomato tomato_1 tomato_2

snake_head snake_head_1 snake_body snake_body

grass_border grass_border grass_border grass_border grass_border grass_border grass_border grass_border grass_border grass_border grass_border grass_border grass_border grass_border grass_border grass_border grass_border

🎮 Demo

game_gif

Update #2

  • Adding some animation
  • Adding grass borders

game_gif_2

grass_border grass_border grass_border grass_border grass_border grass_border grass_border grass_border grass_border grass_border grass_border grass_border grass_border grass_border grass_border grass_border grass_border grass_border

🕹️ Game Logic

First of all we assume a virtual grid that the snake moves on and on which the fruits appear the grid ⏹️ has 40x40 cells each of size 20*20

⏹️ ⏹️ ⏹️ ⏹️ ⏹️ ⏹️ ⏹️ ⏹️ ⏹️ ⏹️

⏹️ ⏹️ ⏹️ ⏹️ ⏹️ ⏹️ ⏹️ ⏹️ ⏹️ ⏹️

⏹️ ⏹️ ⏹️ ⏹️ ⏹️ ⏹️ ⏹️ ⏹️ ⏹️ ⏹️

⏹️ ⏹️ ⏹️ ⏹️ ⏹️ ⏹️ ⏹️ ⏹️ ⏹️ ⏹️

⏹️ ⏹️ ⏹️ ⏹️ ⏹️ ⏹️ ⏹️ ⏹️ ⏹️ ⏹️

⏹️ ⏹️ ⏹️ ⏹️ ⏹️ ⏹️ ⏹️ ⏹️ ⏹️ ⏹️

⏹️ ⏹️ ⏹️ ⏹️ ⏹️ ⏹️ ⏹️ ⏹️ ⏹️ ⏹️

The game logic is simple, it can be divided into two parts:

🐍 Snake Movement

For the snake movement, there are two cases:

  • First Case the snake moves without eating a fruit, in that case each body cell takes the position of the body cell that precedes it in the snake while at the same time the snake head takes its new position according to the direction input by the user.
  • Second Case the snake moves and eats a fruit, in that case each body cell takes the position of the body cell that preceds it in the snake, then a new body cell is added at the snake's head position, while the snake head goes to the next cell according to the direction input by the user so that the snake gets longer by one cell.

🍎 Fruit Collection

A fruit appears on a random grid cell and each time the snake eats a fruit another fruit appears at a different location on a different grid cell.

grass_border grass_border grass_border grass_border grass_border grass_border grass_border grass_border grass_border grass_border grass_border grass_border grass_border grass_border grass_border grass_border grass_border grass_border

📚 References

About

🐍 A simple snake game made in python inspired by the following amazing tutorial with some modifications : https://www.youtube.com/watch?v=QFvqStqPCRU

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages