Commit 689bffa9 by BellCodeEditor

save project

parent 11b481ff
Showing with 11 additions and 2 deletions
...@@ -4,6 +4,7 @@ from pygame import locals ...@@ -4,6 +4,7 @@ from pygame import locals
# 初始化pygame,为使用硬件做准备 # 初始化pygame,为使用硬件做准备
pygame.init() pygame.init()
s="right" s="right"
# 创建一个窗口 # 创建一个窗口
screen = pygame.display.set_mode((660, 480)) screen = pygame.display.set_mode((660, 480))
x=240 x=240
...@@ -11,10 +12,14 @@ y=120 ...@@ -11,10 +12,14 @@ y=120
zb=[(160,90),(180,120),(210,120),(x,y)] zb=[(160,90),(180,120),(210,120),(x,y)]
# 背景 # 背景
background = pygame.image.load('bg.png') background = pygame.image.load('bg.png')
left = pygame.image.load('left.png')
up = pygame.image.load('up.png')
down = pygame.image.load('down.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')
G=pygame.time.Clock() G=pygame.time.Clock()
a=right
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:
...@@ -23,13 +28,17 @@ while True: ...@@ -23,13 +28,17 @@ while True:
if event.type==locals.KEYDOWN: if event.type==locals.KEYDOWN:
if event.key==locals.K_UP and s!="down": if event.key==locals.K_UP and s!="down":
s="up" s="up"
a=up
if event.key==locals.K_DOWN and s!="up": if event.key==locals.K_DOWN and s!="up":
s="down" s="down"
a=down
if event.key==locals.K_LEFT and s!="right": if event.key==locals.K_LEFT and s!="right":
s="left" s="left"
a=left
if event.key==locals.K_RIGHT and s!="left": if event.key==locals.K_RIGHT and s!="left":
s="right" s="right"
x=x+30 a=right
if s=="right": if s=="right":
...@@ -46,7 +55,7 @@ while True: ...@@ -46,7 +55,7 @@ while True:
# 将背景图画上去 # 将背景图画上去
screen.blit(background, (0, 0)) screen.blit(background, (0, 0))
# 将贪吃蛇画上去 # 将贪吃蛇画上去
screen.blit(right, (x, y)) screen.blit(a, (x, y))
for i in range(len(zb)-1): for i in range(len(zb)-1):
screen.blit(body,zb[i]) screen.blit(body,zb[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