Commit c55f5d2c by BellCodeEditor

save project

parent 9d94b5cd
Showing with 2 additions and 65 deletions
import pygame
import random
from pygame import locals
pygame.init()
screen = pygame.display.set_mode((660, 480))
asd = pygame.time.Clock()
background = pygame.image.load('bg.png')
right = pygame.image.load('right.png')
up = pygame.image.load('up.png')
left = pygame.image.load('left.png')
down = pygame.image.load('down.png')
food = pygame.image.load('apple.png')
body = pygame.image.load('body.png')
sb=pygame.sb('neuropol.ttf',18)
x,y = 240,120
apple_x,apple_y=300,360
score=0
a12 = [(210,120),(210,120),(210,120),(x,y)]
asdwww = 'right'
add = right
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 asdwww != 'left':
asdwww = 'right'
if event.key == locals.K_LEFT and asdwww != 'right':
asdwww = 'left'
if event.key == locals.K_UP and asdwww != 'down':
asdwww = 'up'
if event.key == locals.K_DOWN and asdwww != 'up':
asdwww = 'down'
if asdwww == 'right':
add = right
x += 30
elif asdwww == 'left':
add = left
x -= 30
elif asdwww == 'up':
add = up
y -= 30
else:
add = down
y += 30
if x==apple_x and y==apple_y:
a=random.randint(0,21)
b=random.randint(0,15)
apple_x=30*a
apple_y=30*b
score+=10
else:
a12.pop(0)
screen.blit(background, (0, 0))
screen.blit(add, (x, y))
a12.append((x,y))
for i in range(len(a12)-1):
screen.blit(body,a12[i])
screen.blit(food, (apple_x, apple_y))
info="Score"+str(score)
text=sb.render(info,True,(0,0,0))
screen.blit(text,(540,10))
pygame.display.update()
asd.tick(3)
\ No newline at end of file
print(5+3==9)
\ No newline at end of file
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