Commit e45e03aa by BellCodeEditor

save project

parent 5d2278c0
Showing with 65 additions and 26 deletions
import pygame import pygame
from pygame import locals from pygame import locals
pygame.init()
# 初始化pygame,为使用pygame做准备 ticks=pygame.time.Clock()
pygame.init() a="right"
# 创建一个窗口 x=330
screen =pygame.display.set_mode((660,480)) y=60
bg=pygame.image.load("bg.png") location=[(270,90),(300,90),(300,60),(x,y)]
apple=pygame.image.load("apple.png") screen=pygame.display.set_mode((660,480))
body=pygame.image.load("body.png") apple=pygame.image.load("apple.png")
down=pygame.image.load("down.png") bg=pygame.image.load("bg.png")
while True: body=pygame.image.load("body.png")
for event in pygame.event.get(): down=pygame.image.load("down.png")
if event.type == locals.QUIT: left=pygame.image.load("left.png")
exit() right=pygame.image.load("right.png")
screen.blit(bg,(0,0)) up=pygame.image.load("up.png")
screen.blit(apple,(270,240)) b=right
screen.blit(body,(240,90)) while True:
screen.blit(body,(240,60))
screen.blit(body,(240,30)) for i in pygame.event.get():
screen.blit(body,(210,30)) if i.type == locals.QUIT:
screen.blit(body,(180,30)) exit()
screen.blit(body,(150,30)) elif i.type==locals.KEYDOWN:
screen.blit(down,(240,120)) if i.key==locals.K_RIGHT and a != "left":
pygame.display.update() a="right"
b=right
elif i.key==locals.K_LEFT and a != "right":
a="left"
b=left
elif i.key==locals.K_UP and a != "down":
a="up"
b=up
elif i.key==locals.K_DOWN and a != "up":
a="down"
b=down
if a=="right":
x+=30
elif a=="left":
x-=30
elif a=="up":
y-=30
elif a=="down":
y+=30
location.append((x,y))
location.pop(0)
screen.blit(bg,(0,0))
screen.blit(apple,(30,90))
for j in range(len(location)-1):
screen.blit(body,location[j])
screen.blit(b,location[-1])
pygame.display.update()
ticks.tick(5)
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