Commit dd873c4b by BellCodeEditor

save project

parent 283d8b11
Showing with 11 additions and 13 deletions
...@@ -10,16 +10,17 @@ FPSCLOCK = pygame.time.Clock() # pygame时钟,控制游戏速度(帧数) ...@@ -10,16 +10,17 @@ FPSCLOCK = pygame.time.Clock() # pygame时钟,控制游戏速度(帧数)
# 背景 # 背景
background = pygame.image.load('bg.png') background = pygame.image.load('bg.png')
right = pygame.image.load('right.png') # 头 朝右 d = pygame.image.load('right.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') # 身体
left = pygame.image.load('left.png') # 头 朝左 a = pygame.image.load('left.png') # 头 朝左
up = pygame.image.load('up.png') # 头 朝上 w = pygame.image.load('up.png') # 头 朝上
down = pygame.image.load('down.png') # 头 朝下 s = pygame.image.load('down.png') # 头 朝下
x, y = 240, 120 x, y = 240, 120
position = [(180, 90), (180, 120), (210, 120), (x, y)] position = [(180, 90), (180, 120), (210, 120), (x, y)]
apple_x=360
apple_y=300
setheading = "d" setheading = "d"
snake_head = d snake_head = d
...@@ -27,9 +28,6 @@ while True: ...@@ -27,9 +28,6 @@ while True:
for event in pygame.event.get(): for event in pygame.event.get():
if event.type == locals.QUIT: if event.type == locals.QUIT:
# 接收到退出事件后退出程序 # 接收到退出事件后退出程序
apple_x=360
apple_y=300
exit() exit()
if event.type == locals.KEYDOWN: if event.type == locals.KEYDOWN:
if event.key == locals.K_d and setheading != "a": if event.key == locals.K_d and setheading != "a":
...@@ -39,11 +37,11 @@ while True: ...@@ -39,11 +37,11 @@ while True:
setheading = 'a' setheading = 'a'
snake_head = a snake_head = a
if event.key == locals.K_w and setheading != "s": if event.key == locals.K_w and setheading != "s":
setheading = 'a' setheading = 'w'
snake_head = a snake_head = w
if event.key == locals.K_s and setheading != "w": if event.key == locals.K_s and setheading != "w":
setheading = 's' setheading = 's'
snake_head = w snake_head = s
# 设置贪吃蛇的头部坐标 # 设置贪吃蛇的头部坐标
if setheading == "d": if setheading == "d":
...@@ -72,4 +70,4 @@ while True: ...@@ -72,4 +70,4 @@ while True:
screen.blit(food, (apple_x,apple_y )) screen.blit(food, (apple_x,apple_y ))
# 刷新画面 # 刷新画面
pygame.display.update() pygame.display.update()
FPSCLOCK.tick(3) FPSCLOCK.tick(5)
\ 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