Commit 26db4646 by BellCodeEditor

save project

parent 90d47c5c
Showing with 10 additions and 2 deletions
import pygame
from pygame import locals
import random
# 初始化pygame,为使用硬件做准备
pygame.init()
FPSCLOCK=pygame.time.Clock()
......@@ -18,6 +18,8 @@ body = pygame.image.load('body.png')
x,y=240,120
position=[(180,90),(180,120),(210,120),(x,y)]
apple_X=360
apple_Y=300
setheading="right"
snake_head=right
......@@ -49,6 +51,11 @@ while True:
else:
y+=30
position.append((x,y))
if x==apple_X and y==apple_Y:
apple_Y=random.randint(0,660)
apple_X=random.randint(0,480)
position.pop(0)
# 将背景图画上去
screen.blit(background, (0, 0))
......@@ -59,7 +66,7 @@ while True:
screen.blit(body,position[i])
# 将果实画上去
screen.blit(food, (360, 300))
screen.blit(food, (apple_X, apple_Y))
# 刷新画面
pygame.display.update()
FPSCLOCK.tick(3)
\ 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