Commit 614dd8a7 by BellCodeEditor

save project

parent 22f755b5
Showing with 15 additions and 2 deletions
import pygame
import random
from pygame import locals
# 初始化pygame,为使用硬件做准备
......@@ -15,17 +16,25 @@ body = pygame.image.load('body.png')
left= pygame.image.load('left.png')
down= pygame.image.load('down.png')
up= pygame.image.load('up.png')
x=240
y=120
f=pygame.time.Clock()
p=[(180,90),(180,120),(210,120),(x,y)]
apple_x=360
apple_y=300
setheading='right'
snake=right
while True:
for event in pygame.event.get():
if event.type == locals.QUIT:
# 接收到退出事件后退出程序
exit()
elif event.type==locals.KEYDOWN:
if event.key==locals.K_DOWN and setheading != 'up':
setheading='down'
......@@ -57,12 +66,15 @@ while True:
screen.blit(right,p[-1])
for i in range(len(p)-1):
screen.blit(body,p[i])
# 将贪吃蛇的身体画上去
#screen.blit(body, (210, 120))
#screen.blit(body, (180, 120))
#screen.blit(body, (180, 90))
# 将果实画上去
screen.blit(food, (360, 300))
# 刷新画面
screen.blit(food, (apple_x, apple_y))
if x==apple_x and y==apple_y:
apple_x=random.randint(0,660)
apple_y=random.randint(0,480) # 刷新画面
pygame.display.update()
f.tick(3)
\ 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