Skip to content

Instantly share code, notes, and snippets.

@wc-tph
Last active March 12, 2021 02:14
Show Gist options
  • Save wc-tph/2b1efc6e28be22e69859655511868285 to your computer and use it in GitHub Desktop.
Save wc-tph/2b1efc6e28be22e69859655511868285 to your computer and use it in GitHub Desktop.
import pygame
from random import randint
FOOD_SIZE = 10
DISPLAY_WIDTH = 640
DISPLAY_HEIGHT = 480
BG_COLOUR = (44, 62, 80)
SNAKE_COLOUR = (236, 240, 241)
FOOD_COLOUR = (241, 196, 15)
pygame.init()
snake_display = pygame.display.set_mode((DISPLAY_WIDTH, DISPLAY_HEIGHT))
snake_display.fill(BG_COLOUR)
pygame.display.update()
# generate food
for i in range(4):
pygame.draw.rect(snake_display,
FOOD_COLOUR,
(randint(0, DISPLAY_WIDTH - 1) // FOOD_SIZE * FOOD_SIZE,
randint(0, DISPLAY_HEIGHT - 1) // FOOD_SIZE * FOOD_SIZE,
FOOD_SIZE,
FOOD_SIZE))
snake_x = DISPLAY_WIDTH / 2
snake_y = DISPLAY_HEIGHT / 2
pygame.draw.rect(snake_display, SNAKE_COLOUR, (snake_x, snake_y, FOOD_SIZE, FOOD_SIZE))
pygame.display.update()
game_over = False
while not game_over:
for event in pygame.event.get():
print(event)
if event.type == pygame.QUIT:
game_over = True
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment