Commit 1fe7b89f by BellCodeEditor

save project

parent 0f4da355
kk.jpg

67.4 KB

......@@ -6,11 +6,11 @@ score=0
pygame.init()
# 创建一个窗口
screen = pygame.display.set_mode((660, 480))
screen = pygame.display.set_mode((1080,1080))
FPSCLOCK = pygame.time.Clock() # pygame时钟,控制游戏速度(帧数)
# 背景
background = pygame.image.load('bg.png')
background = pygame.image.load('kk.jpg')
right = pygame.image.load('right.png') # 头 朝右
food = pygame.image.load('apple.png') # 食物 苹果
body = pygame.image.load('body.png') # 身体
......@@ -34,29 +34,25 @@ while True:
# 接收到退出事件后退出程序
exit()
if event.type == locals.KEYDOWN:
if event.key == locals.K_RIGHT and setheading != "left":
setheading = 'right'
snake_head = right
if event.key == locals.K_RIGHT and setheading !="left":
setheading = "right"
if event.key == locals.K_LEFT and setheading != "right":
setheading = 'left'
snake_head = left
setheading = "left"
if event.key == locals.K_UP and setheading != "down":
setheading = 'up'
snake_head = up
setheading = "up"
if event.key == locals.K_DOWN and setheading != "up":
setheading = 'down'
snake_head = down
setheading = "down"
# 设置贪吃蛇的头部坐标
if setheading == "right":
x += 30
x +=30
elif setheading == "left":
x -= 30
x -=30
elif setheading == "up":
y -= 30
else:
y += 30
position.append((x, y))
if x==food_x and y==food_y:
d_x=random.randint(1,22)
d_y=random.randint(1,16)
......@@ -77,3 +73,5 @@ while True:
screen.blit(fen,(540,0))
# 将果实画上去
screen.blit(food, (food_x, food_y))
pygame.display.update()
FPSCLOCK.tick(20)
\ 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