Commit 91a61b71 by BellCodeEditor

save project

parent d5739bd2
Showing with 7 additions and 0 deletions
import pygame import pygame
from pygame import locals from pygame import locals
import random
# 初始化pygame,为使用硬件做准备 # 初始化pygame,为使用硬件做准备
pygame.init() pygame.init()
...@@ -19,6 +20,7 @@ down = pygame.image.load('down.png') # 头 朝下 ...@@ -19,6 +20,7 @@ down = 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,apple_y = 300,360
setheading = "right" setheading = "right"
snake_head = right snake_head = right
...@@ -41,6 +43,10 @@ while True: ...@@ -41,6 +43,10 @@ while True:
if event.key == locals.K_DOWN and setheading != "up": if event.key == locals.K_DOWN and setheading != "up":
setheading = 'down' setheading = 'down'
snake_head = down snake_head = down
if x == apple_x and y == apple_y:
apple_x = random.randint(0,660)
apple_y = random.randint(0,480)
# 设置贪吃蛇的头部坐标 # 设置贪吃蛇的头部坐标
if setheading == "right": if setheading == "right":
...@@ -61,6 +67,7 @@ while True: ...@@ -61,6 +67,7 @@ while True:
for i in range(len(position)-1): for i in range(len(position)-1):
screen.blit(body, position[i]) screen.blit(body, position[i])
# 将果实画上去 # 将果实画上去
screen.blit(food, (360, 300)) screen.blit(food, (360, 300))
# 刷新画面 # 刷新画面
......
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