Commit c222b7f4 by BellCodeEditor

save project

parent 00076631
Showing with 11 additions and 4 deletions
import pygame import pygame
from pygame import locals from pygame import locals
import random
a_x=360
a_y=300
# 初始化pygame,为使用硬件做准备 # 初始化pygame,为使用硬件做准备
pygame.init() pygame.init()
...@@ -48,6 +50,11 @@ while True: ...@@ -48,6 +50,11 @@ while True:
y-=30 y-=30
else: else:
y+=30 y+=30
if x==a_x and y==a_y:
a=random.randint(0,22)
b=random.randint(0,12)
a_x=a*30
a_y=b*30
zuo.append((x,y)) zuo.append((x,y))
zuo.pop(0) zuo.pop(0)
screen.blit(background, (0, 0)) screen.blit(background, (0, 0))
...@@ -55,9 +62,9 @@ while True: ...@@ -55,9 +62,9 @@ while True:
screen.blit(xiang,zuo[-1] ) screen.blit(xiang,zuo[-1] )
# 将贪吃蛇的身体画上去 # 将贪吃蛇的身体画上去
# 将果实画上去 # 将果实画上去
screen.blit(food, (360, 300)) screen.blit(food, (a_x, a_y))
for i in range(len(zuo)-1): for i in range(len(zuo)-1):
screen.blit(body,zuo[i]) screen.blit(body,zuo[i])
# 刷新画面 # 刷新画面
pygame.display.update() pygame.display.update()
fps.tick(3) fps.tick(10)
\ No newline at end of file \ 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