Commit 6dd3c705 by BellCodeEditor

save project

parent d3cad4cd
Showing with 12 additions and 20 deletions
import pygame
from pygame import locals
import random
# 初始化pygame,为使用硬件做准备
pygame.init()
# 创建一个窗口
screen = pygame.display.set_mode((660, 480))
# 背景
background = pygame.image.load('bg.png')
right = pygame.image.load('right.png')
......@@ -19,8 +17,8 @@ f=pygame.time.Clock()
x,y=240,120
p=[(180,90),(180,120),(210,120),(x,y)]
setheading="right"
apple_x=300
apple_y=360
while True:
for event in pygame.event.get():
if event.type == locals.QUIT:
......@@ -35,14 +33,9 @@ while True:
setheading="up"
if event.key==locals.K_DOWN and setheading != "up":
setheading="down"
# 将背景图画上去
screen.blit(background, (0, 0))
# 将贪吃蛇画上去
# screen.blit(right, (x, y))
# 将贪吃蛇画上去
# 将贪吃蛇的身体画上去
if setheading=="right":
x+=30
......@@ -56,16 +49,16 @@ while True:
else :
y+=30
screen.blit(down,(x,y))
p.append((x,y))
p.pop(0)
#screen.blit(body, (210, 120))
#screen.blit(body, (180, 120))
#screen.blit(body, (180, 90))
p.append((x,y))
for i in range (len(p)-1):
screen.blit(body,p[i])
if x==apple_x and y==apple_y:
apple_x=random.randint(0,21)*30
apple_y=random.randint(0,15)*30
else:
p.pop(0)
# 将果实画上去
screen.blit(food, (360, 300))
screen.blit(food, (apple_x,apple_y))
# 刷新画面
pygame.display.update()
f.tick(3)
\ No newline at end of file
f.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