Commit d354f024 by BellCodeEditor

save project

parent 69cdbf6b
Showing with 10 additions and 7 deletions
......@@ -22,7 +22,7 @@ apple_x=360
apple_y=300
setheading="right" #头部初始变量
snack_head=right #头部初始朝向
snake_head=right #头部初始朝向
while True:
for event in pygame.event.get(): #遍历事件
......@@ -31,16 +31,16 @@ while True:
elif event.type==locals.KEYDOWN:
if event.key==locals.K_RIGHT and setheading!='left':
setheading='right'
snack_head=right
snake_head=right
if event.key==locals.K_LEFT and setheading!='right':
setheading='left'
snack_head=left
snake_head=left
if event.key==locals.K_UP and setheading!='down':
setheading='up'
snack_head=up
snake_head=up
if event.key==locals.K_DOWN and setheading!='up':
setheading='down'
snack_head=down #判断按键
snake_head=down #判断按键
if setheading=='right':
x+=30
elif setheading=='left':
......@@ -51,8 +51,11 @@ while True:
y+=30 #移动
position.append((x,y))
if x==apple_x and y==apple_y:
apple_x=random.randint(0,660)
apple_y=random.randint(0,480)
num1=random.randint(0,22)
num2=random.randint(0,16)
apple_x=num1*30-30
apple_y=num2*30-30
else:
position.pop(0)
screen.blit(background, (0, 0)) #将背景图画上去
screen.blit(right,position[-1]) #将贪吃蛇画上去
......
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