Commit 24f4984a by BellCodeEditor

save project

parent f721c202

2.05 KB | W: | H:

165 Bytes | W: | H:

apple.png
apple.png
apple.png
apple.png
  • 2-up
  • Swipe
  • Onion skin

22.5 KB | W: | H:

6.04 KB | W: | H:

bg.png
bg.png
bg.png
bg.png
  • 2-up
  • Swipe
  • Onion skin

1.4 KB | W: | H:

161 Bytes | W: | H:

body.png
body.png
body.png
body.png
  • 2-up
  • Swipe
  • Onion skin

2.01 KB | W: | H:

162 Bytes | W: | H:

down.png
down.png
down.png
down.png
  • 2-up
  • Swipe
  • Onion skin

2.07 KB | W: | H:

162 Bytes | W: | H:

left.png
left.png
left.png
left.png
  • 2-up
  • Swipe
  • Onion skin

2.05 KB | W: | H:

162 Bytes | W: | H:

right.png
right.png
right.png
right.png
  • 2-up
  • Swipe
  • Onion skin
...@@ -23,7 +23,7 @@ position = [(180, 90),(180, 120),(210, 120),(x, y)] ...@@ -23,7 +23,7 @@ position = [(180, 90),(180, 120),(210, 120),(x, y)]
ax,ay = randint(0,21),randint(0,15) ax,ay = randint(0,21),randint(0,15)
setheading = "right" setheading = "right"
snake_head = right
while True: while True:
for event in pygame.event.get(): for event in pygame.event.get():
...@@ -31,20 +31,14 @@ while True: ...@@ -31,20 +31,14 @@ while True:
# 接收到退出事件后退出程序 # 接收到退出事件后退出程序
exit() exit()
if event.type == locals.KEYDOWN: if event.type == locals.KEYDOWN:
print(ax,ay)
if event.key == locals.K_RIGHT and setheading != "left": if event.key == locals.K_RIGHT and setheading != "left":
setheading = 'right' setheading = 'right'
snake_head = right
if event.key == locals.K_LEFT and setheading != "right": if event.key == locals.K_LEFT and setheading != "right":
setheading = 'left' setheading = 'left'
snake_head = left
if event.key == locals.K_UP and setheading != "down": if event.key == locals.K_UP and setheading != "down":
setheading = 'up' setheading = 'up'
snake_head = up
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
# 设置贪吃蛇的头部坐标 # 设置贪吃蛇的头部坐标
if setheading == "right": if setheading == "right":
x += 30 x += 30
...@@ -55,14 +49,15 @@ while True: ...@@ -55,14 +49,15 @@ while True:
else: else:
y += 30 y += 30
position.append((x, y)) position.append((x, y))
position.pop(0) if x!=ax*30 or y!=ay*30:
position.pop(0)
if x==ax*30 and y==ay*30: if x==ax*30 and y==ay*30:
ax,ay = randint(0,21),randint(0,15) ax,ay = randint(0,21),randint(0,15)
print(ax,ay) print(ax,ay)
# 将背景图画上去 # 将背景图画上去
screen.blit(background, (0, 0)) screen.blit(background, (0, 0))
# 将贪吃蛇的头画上去 # 将贪吃蛇的头画上去
screen.blit(snake_head, position[-1]) screen.blit(right, position[-1])
# 将贪吃蛇的身体画上去 # 将贪吃蛇的身体画上去
for i in range(len(position)-1): for i in range(len(position)-1):
screen.blit(body, position[i]) screen.blit(body, position[i])
......

2.05 KB | W: | H:

162 Bytes | W: | H:

up.png
up.png
up.png
up.png
  • 2-up
  • Swipe
  • Onion skin
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