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