Commit 3966656c by BellCodeEditor

save project

parent 42f1723b
Showing with 57 additions and 54 deletions
import pygame
import random
from pygame import locals
pygame.init()
screen = pygame.display.set_mode((660, 480))
e=pygame.time.Clock()
background = pygame.image.load('bg.png')
right = pygame.image.load('right.png')
left = pygame.image.load('left.png')
up = pygame.image.load('up.png')
down = pygame.image.load('down.png')
food = pygame.image.load('apple.png')
body = pygame.image.load('body.png')
zx='right'
cx=right
x,y=240,120
x1,y1=360,300
lb=[(180,90),(180,120),(210,120),(x,y)]
while True:
for event in pygame.event.get():
if event.type == locals.QUIT:
exit()
elif event.type == locals.KEYDOWN:
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 event.key == locals.K_LEFT and zx != 'right':
zx='left'
cx=left
if event.key == locals.K_RIGHT and zx != 'left':
zx='right'
cx=right
if zx == 'right':
x+=30
elif zx == 'left':
x-=30
elif zx == 'up':
y-=30
else:
y+=30
lb.append((x,y))
lb.pop(0)
screen.blit(background, (0, 0))
screen.blit(cx, (x, y))
for i in range(len(lb)-1):
screen.blit(body,lb[i])
screen.blit(food, (x1, y1))
pygame.display.update()
e.tick(3)
\ No newline at end of file
import pygame
import pygame
import random
from pygame import locals
pygame.init()
screen = pygame.display.set_mode((660, 480))
e=pygame.time.Clock()
background = pygame.image.load('bg.png')
right = pygame.image.load('right.png')
left = pygame.image.load('left.png')
up = pygame.image.load('up.png')
down = pygame.image.load('down.png')
food = pygame.image.load('apple.png')
body = pygame.image.load('body.png')
zx='right'
cx=right
x,y=240,120
x1,y1=360,300
lb=[(180,90),(180,120),(210,120),(x,y)]
while True:
for event in pygame.event.get():
if event.type == locals.QUIT:
exit()
elif event.type == locals.KEYDOWN:
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 event.key == locals.K_LEFT and zx != 'right':
zx='left'
cx=left
if event.key == locals.K_RIGHT and zx != 'left':
zx='right'
cx=right
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:
x1=random.randint(0,660)
y1=random.randint(0,480)
lb.pop(0)
screen.blit(background, (0, 0))
screen.blit(cx, (x, y))
for i in range(len(lb)-1):
screen.blit(body,lb[i])
screen.blit(food, (x1, y1))
pygame.display.update()
e.tick(3)
\ 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