Commit 614dd8a7 by BellCodeEditor

save project

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