Global constants for snake game
We will need to add a few constants to our game which can be used to handle the movements, total size and grid architecture of the game. For our snake game, the snake will be any one of these grids at any given time. I am creating a new file to keep all my constants.
constants.py
SCREEN_WIDTH: int = 810
SCREEN_HEIGHT: int = 510
# number of grids
GRID_SIZE: int = 30
# Height and width of single grid
GRID_WIDTH: int = SCREEN_WIDTH / GRID_SIZE
GRID_HEIGHT: int = SCREEN_HEIGHT / GRID_SIZE
# Movements
MOVE_UP: tuple = (0, -1)
MOVE_DOWN: tuple = (0, 1)
MOVE_LEFT: tuple = (-1, 0)
MOVE_RIGHT: tuple = (1, 0)
main.py
file.
from constants import SCREEN_WIDTH, SCREEN_HEIGHT
# width, height
SCREEN_SIZE: tuple = SCREEN_WIDTH, SCREEN_HEIGHT
pygame.display.set_mode(SCREEN_SIZE)
About Author
Ranvir Singh
Greetings! Ranvir is an Engineering professional with 3+ years of experience in Software development.
Please share your Feedback:
Did you enjoy reading or think it can be improved? Don’t forget to leave your thoughts in the comments section below! If you liked this article, please share it with your friends, and read a few more!