Untitled
unknown
plain_text
2 years ago
1.5 kB
11
Indexable
import pygame
from random import randint
pygame.init()
screen = pygame.display.set_mode((678, 611))
pygame.display.set_caption('Snake')
green = (112, 220, 71)
dark_green = (15, 27, 11)
red = (235, 50, 50)
apple = False
new_apple = False
direction = False
border = 8
pixel = 67
br = 10
w = randint(0, 9)
h = randint(0, 8)
snake = [[border, border + pixel * 4, 59, 59], [border + pixel, border + pixel * 4, 59, 59], [border + pixel * 2, border + pixel * 4, 59, 59], [border + pixel * 3, border + pixel * 4, 59, 59]]
def d():
w
h
if [border + pixel * w, border + pixel * h, 59, 59] in snake:
while [border + pixel * w, border + pixel * h, 59, 59] in snake:
w
h
d()
apple_poswh = [border + pixel * w, border + pixel * h, 59, 59]
clock = pygame.time.Clock()
while True:
clock.tick(8)
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_d:
direction = "Right"
screen.fill(dark_green)
if direction == False:
for i in snake:
pygame.draw.rect(screen, green, i, 0, br)
pygame.draw.rect(screen, red, [border + pixel * 7, border + pixel * 4, 59, 59], 0, br)
elif direction == "Right":
pass
if new_apple == True:
d()
if apple == True:
pygame.draw.rect(screen, red, [border + pixel * w, border + pixel * h, 59, 59], 0, br)
new_apple = False
pygame.display.update()
Editor is loading...