Commit 6c1fab91 by BellCodeEditor

save project

parent 64984c30
apple.png

2.05 KB

bg.png

22.5 KB

body.png

1.4 KB

down.png

2.01 KB

left.png

2.07 KB

File added
right.png

2.05 KB

import pygame
import random
from pygame import locals
pygame.init()
screen = pygame.display.set_mode((660, 480))
FPSCLOCK = pygame.time.Clock()
background = pygame.image.load('bg.png')
right = pygame.image.load('right.png')
food = pygame.image.load('apple.png')
body = pygame.image.load('body.png')
left = pygame.image.load('left.png')
up = pygame.image.load('up.png')
down = pygame.image.load('down.png')
zt=pygame.font.Font('neuropol.ttf',18)
x, y = 240, 120
x1,y1=360,270
lb= [(180, 90), (180, 120), (210, 120), (x, y)]
zx= "right"
cx= right
s=0
while True:
for event in pygame.event.get():
if event.type == locals.QUIT:
exit()
if event.type == locals.KEYDOWN:
if event.key == locals.K_RIGHT and zx != "left":
zx = 'right'
cx = right
if event.key == locals.K_LEFT and zx != "right":
zx = 'left'
cx = left
if event.key == locals.K_UP and zx != "down":
zx = 'up'
cx = up
if event.key == locals.K_DOWN and zx != "up":
zx = 'down'
cx = down
if zx == "right":
x += 30
elif zx == "left":
x -= 30
elif zx == "up":
y -= 30
else:
y += 30
lb.append((x, y))
if x==x1 and y==y1:
xx=random.randint(1,22)
yy=random.randint(1,16)
x1=30*xx-30
y1=30*yy-30
s+=10
else:
lb.pop(0)
screen.blit(background, (0, 0))
screen.blit(cx, lb[-1])
for i in range(len(lb)-1):
screen.blit(body, lb[i])
screen.blit(food, (x1, y1))
q='Score:'+str(s)
t=zt.render(q,True,(0,0,0))
screen.blit(t,(0,10))
pygame.display.update()
FPSCLOCK.tick(3)
\ No newline at end of file
up.png

2.05 KB

Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment