Commit eb6b22b0 by BellCodeEditor

save project

parent 4c51cf58
s.png

172 Bytes

...@@ -5,27 +5,56 @@ from pygame import locals ...@@ -5,27 +5,56 @@ from pygame import locals
pygame.init() pygame.init()
SB = pygame.time.Clock() SB = pygame.time.Clock()
# 创建一个窗口 # 创建一个窗口
screen = pygame.display.set_mode((660, 480)) screen = pygame.display.set_mode((6600, 480))
# 背景 # 背景
background = pygame.image.load('bg.png') background = pygame.image.load('bg.png')
right = pygame.image.load('right.png')
ri = pygame.image.load('right.png')
le = pygame.image.load('left.png')
do = pygame.image.load('down.png')
up = pygame.image.load('up.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')
x,y = 240,120 x,y = 240,120
a = [(180,90),(180,120),(210,120),(x,y)] a = [(180,90),(180,120),(210,120),(x,y)]
se = 'ri'
s_e = ri
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()
x = x+30 if event.type == locals.KEYDOWN:
if event.key ==locals.K_RIGHT and se != 'le':
se = 'ri'
s_e = ri
if event.key ==locals.K_LEFT and se != 'ri':
se = 'le'
s_e = le
if event.key ==locals.K_UP and se != 'do':
se = 'up'
s_e = up
if event.key ==locals.K_DOWN and se != 'up':
se = 'do'
s_e = do
if se == 'ri':
x += 30
elif se == 'le':
x -= 30
elif se == 'up':
y -= 30
else:
y += 30
a.append((x,y)) a.append((x,y))
a.pop(0) a.pop(0)
# 将背景图画上去 # 将背景图画上去
screen.blit(background, (0, 0)) screen.blit(background, (0, 0))
# 将贪吃蛇画上去 # 将贪吃蛇画上去
screen.blit(right, a[-1]) screen.blit(s_e, a[-1])
# 将贪吃蛇的身体画上去 # 将贪吃蛇的身体画上去
for i in range(len(a)-1): for i in range(len(a)-1):
screen.blit(body, a[i]) screen.blit(body, a[i])
...@@ -33,4 +62,4 @@ while True: ...@@ -33,4 +62,4 @@ while True:
screen.blit(food, (360, 300)) screen.blit(food, (360, 300))
# 刷新画面 # 刷新画面
pygame.display.update() pygame.display.update()
SB.tick(3) SB.tick(10)
\ No newline at end of file \ 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