Commit 9fbdd0d2 by BellCodeEditor

save project

parent 99d09da2
Showing with 33 additions and 6 deletions
import pygame import pygame
import random
from pygame import locals from pygame import locals
pygame.init() pygame.init()
lock=pygame.time.Clock()
screen = pygame.display.set_mode((660, 480)) screen = pygame.display.set_mode((660, 480))
background = pygame.image.load('bg.png') background = pygame.image.load('bg.png')
right = pygame.image.load('right.png') right = pygame.image.load('right.png')
food = pygame.image.load('apple.png') food = pygame.image.load('apple.png')
body = pygame.image.load('body.png') body = pygame.image.load('body.png')
down = pygame.image.load('down.png')
up = pygame.image.load('up.png')
left = pygame.image.load('left.png')
zx='right'
cx=right
x,y=240,120 x,y=240,120
lock=pygame.time.Clock()
flb=[(180,90),(180,120),(210,120),(x,y)] flb=[(180,90),(180,120),(210,120),(x,y)]
while True: while True:
for event in pygame.event.get(): for event in pygame.event.get():
if event.type == locals.QUIT: if event.type == locals.QUIT:
exit() exit()
screen.blit(background, (0, 0)) elif event.type==locals.KEYDOWN:
x=x+30 if event.key == locals.K_UP and zx!='down':
cx=up
zx='up'
if event.key == locals.K_DOWN and zx!='up':
cx=down
zx='down'
if event.key == locals.K_LEFT and zx!='right':
cx=left
zx='left'
if event.key == locals.K_RIGHT and zx!='left':
cx=right
zx='right'
if zx=='left':
x-=30
elif zx=='down':
y+=30
elif zx=='right':
x+=30
else:
y-=30
flb.append((x,y)) flb.append((x,y))
flb.pop(0) flb.pop(0)
screen.blit(right, (flb[-1]))
screen.blit(background, (0, 0))
screen.blit(cx, (x,y))
for i in range(len(flb)-1): for i in range(len(flb)-1):
screen.blit(body,flb[i]) screen.blit(body,flb[i])
......
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