Commit 5ac3e881 by BellCodeEditor

save project

parent f2ca35fc
Showing with 7 additions and 1 deletions
import pygame import pygame
import random
from pygame import locals from pygame import locals
a=pygame.time.Clock() a=pygame.time.Clock()
...@@ -19,6 +20,8 @@ body = pygame.image.load('body.png') ...@@ -19,6 +20,8 @@ body = pygame.image.load('body.png')
x,y=240,120 x,y=240,120
eva="right" eva="right"
ave=right ave=right
apple_x=360
apple_y=300
while True: while True:
if eva=="right" : if eva=="right" :
x+=30 x+=30
...@@ -46,6 +49,9 @@ while True: ...@@ -46,6 +49,9 @@ while True:
if event.type == locals.K_RIGHT and eva!="left": if event.type == locals.K_RIGHT and eva!="left":
eva="right" eva="right"
ave=right ave=right
if apple_x==x and apple_y==y:
apple_y=30*random(1,16)-30
apple_x=30*random(1,22)-30
# 将背景图画上去 # 将背景图画上去
screen.blit(background, (0, 0)) screen.blit(background, (0, 0))
# 将贪吃蛇画上去 # 将贪吃蛇画上去
...@@ -55,7 +61,7 @@ while True: ...@@ -55,7 +61,7 @@ while True:
screen.blit(body, (180, 120)) screen.blit(body, (180, 120))
screen.blit(body, (180, 90)) screen.blit(body, (180, 90))
# 将果实画上去 # 将果实画上去
screen.blit(food, (360, 300)) screen.blit(food, (apple_x, apple_y))
# 刷新画面 # 刷新画面
pygame.display.update() pygame.display.update()
a.tick(3) a.tick(3)
......
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