Commit 5f174828 by BellCodeEditor

save project

parent decaf9d9
Showing with 6 additions and 3 deletions
import pygame
from pygame import locals
from random import*
# 初始化pygame,为使用硬件做准备
pygame.init()
......@@ -16,7 +16,7 @@ body = pygame.image.load('body.png') # 身体
left = pygame.image.load('left.png') # 头 朝左
up = pygame.image.load('up.png') # 头 朝上
down = pygame.image.load('down.png') # 头 朝下
fx,fy=360,300
x, y = 240, 120
position = [(180, 90), (180, 120), (210, 120), (x, y)]
......@@ -43,7 +43,6 @@ while True:
snake_head = down
# 设置贪吃蛇的头部坐标
fx,fy=360,300
if setheading == "right":
x += 30
elif setheading == "left":
......@@ -61,6 +60,10 @@ while True:
# 将贪吃蛇的身体画上去
for i in range(len(position)-1):
screen.blit(body, position[i])
if x==fx and y==fy:
fx=randint(0,660)
fy=randint(0,480)
# 将果实画上去
screen.blit(food, (fx, fy))
......
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