Commit b1adcb5c by BellCodeEditor

save project

parent 538dcffc
Showing with 12 additions and 10 deletions
...@@ -6,7 +6,7 @@ pygame.init() ...@@ -6,7 +6,7 @@ pygame.init()
# 创建一个窗口 # 创建一个窗口
screen = pygame.display.set_mode((660, 480)) screen = pygame.display.set_mode((660, 480))
p=pygame.time.Clock()
# 背景 # 背景
background = pygame.image.load('bg.png') background = pygame.image.load('bg.png')
right = pygame.image.load('right.png') right = pygame.image.load('right.png')
...@@ -16,9 +16,9 @@ left= pygame.image.load('left.png') ...@@ -16,9 +16,9 @@ left= pygame.image.load('left.png')
up= pygame.image.load('up.png') up= pygame.image.load('up.png')
down= pygame.image.load('down.png') down= pygame.image.load('down.png')
right_a='right' right_a='right'
right_b='right' right_b=right
x,y=240,120 x,y=240,120
abab=[(210,120),(180,120),(180,90),(x,y)] abab=[(150,120),(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:
...@@ -40,13 +40,14 @@ while True: ...@@ -40,13 +40,14 @@ while True:
if right_a=='right': if right_a=='right':
x+=30 x+=30
if right_a=='left': if right_a=='left':
x+=30 x-=30
if right_a=='up': if right_a=='up':
x+=30 y-=30
if right_a=='down': if right_a=='down':
x+=30 y+=30
abab.append((x,y)) x+=30
abab.pop(0) abab.append((x,y))
abab.pop(0)
# 将背景图画上去 # 将背景图画上去
screen.blit(background, (0, 0)) screen.blit(background, (0, 0))
# 将贪吃蛇画上去 # 将贪吃蛇画上去
...@@ -60,4 +61,5 @@ while True: ...@@ -60,4 +61,5 @@ while True:
# 将果实画上去 # 将果实画上去
screen.blit(food, (360, 300)) screen.blit(food, (360, 300))
# 刷新画面 # 刷新画面
pygame.display.update() pygame.display.update()
\ No newline at end of file p.tick(2)
\ 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