A simple snake game created using Python
Whatever you prefer (e.g. conda
or venv
)
mkdir myproject
$ cd myproject
$ python3 -m venv venv
Windows:
venv\Scripts\activate
Mac / Linux:
. venv/bin/activate
You only need PyGame
:
pip install pygame
Run
python game.py
This will start the game.
Use:
Up Arrow for going UP
Right Arrow for going RIGHT
Down Arrow for going DOWN
Left Arrow for going Left
Have a look at game.py. You can change the game variables according to your own use case.
Change the colours of the game elements over here.
# rgb colors
WHITE = (255, 255, 255)
RED = (200,0,0)
BLUE1 = (0, 0, 255)
BLUE2 = (0, 100, 255)
BLACK = (0,0,0)
Default BLOCK_SIZE (Size of a block in the game) and SPEED (speed of snake) is set to 20.
BLOCK_SIZE = 20
SPEED = 20
In the init function of class SnakeGame; the parameters w and h are the width and height of your game window.
def __init__(self, w=640, h=480):
self.w = w
self.h = h
- Python 3.7 - Creating Project
- Abhijith Udayakumar - Design & Development - Abhijith14
yes, with attribution.
I value keeping my work open source, but as you all know, plagiarism is bad. It's always disheartening whenever I find that someone has copied my work without giving me credit. I spent a non-trivial amount of effort building and designing this project, and I am proud of it! All I ask of you all is to not claim this effort as your own.
Yes, you can fork this repo. Please give me proper credit by linking back to Abhijith14/SnakeGame-PyGame. Thanks!