pygame logo

Making a snake clone in pygame

Introduction and Setup

pygame is a python wrapper for SDL(Simple DirectMedia Layer). SDL provides cross platform, low level access to the system's hardware components such as keyboard, mouse, sound and graphics. With pygame you can make games and multimedia applications using python. pygame only provides you with basic features like an event loop, drawing of objects and images on the screen, a game loop, playing sounds, etc. You'll have to combine all these features to create a game.

Setup:

To install pygame on your computer, use the pip command:
pip install pygame

Making a snake clone

I am going to be teaching you how to make a classic game, Snake 🐍. It is a good way to build up your python and pygame skills. This blog post will be half me explaining how pygame works and half about me building a snake game

Basic Window Setup

To create a window on the screen write this:

# pygame setup
pygame.init()
WINDOW_WIDTH = 800
WINDOW_HEIGHT = 500
screen = pygame.display.set_mode((WINDOW_WIDTH, WINDOW_HEIGHT))
pygame.display.set_caption('Snake clone')
clock = pygame.time.Clock()
running = True


while running:
	# event loop
	for event in pygame.event.get():
		if event.type == pygame.QUIT:
			running = False
        
	# RENDER YOUR GAME HERE
	# fill the screen with a green color
	screen.fill(‘green’)        


	# Update the screen with what you have drawn
	pygame.display.update()
	# limit fps to 60
	clock.tick(60)
pygame.quit()

🚨Page under construction🚨