Commit bb9dfc6a by BellCodeEditor

save project

parent 93d99492
Showing with 8 additions and 1 deletions
import pygame
import random
from pygame import locals
# 初始化pygame,为使用硬件做准备
pygame.init()
......@@ -14,6 +15,8 @@ left = pygame.image.load('left.png')
down = pygame.image.load('down.png')
up = pygame.image.load('up.png')
x,y=240,120
apple_x=360
apple_y=300
position=[(180,90),(180,120),(210,120),(x,y)]
setheading='right'
snake_head=right
......@@ -44,6 +47,9 @@ while True:
if setheading=='up' and setheading!='down':
y-=30
position.append((x,y))
if x==apple_x and y==apple_y:
apple_x = random.randint(0,630)
apple_y = random.randint(0,450)
position.pop(0)
# 将背景图画上去
screen.blit(background, (0, 0))
......@@ -53,7 +59,7 @@ while True:
# 将贪吃蛇画上去
screen.blit(snake_head,position[-1])
# 将果实画上去
screen.blit(food, (360, 300))
screen.blit(food, (apple_x, apple_y))
# 刷新画面
pygame.display.update()
FPSclock.tick(0.01)
\ 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