Commit 360cd3ab by BellCodeEditor

save project

parent 26070c32
Showing with 12 additions and 3 deletions
import pygame import pygame
import random as r
from pygame import locals from pygame import locals
FPSCLOCK=pygame.time.Clock() FPSCLOCK=pygame.time.Clock()
# 初始化pygame,为使用硬件做准备 # 初始化pygame,为使用硬件做准备
...@@ -15,7 +16,8 @@ body = pygame.image.load('body.png') ...@@ -15,7 +16,8 @@ body = pygame.image.load('body.png')
up = pygame.image.load('up.png') up = pygame.image.load('up.png')
down = pygame.image.load('down.png') down = pygame.image.load('down.png')
left = pygame.image.load('left.png') left = pygame.image.load('left.png')
a_x=360
a_y=300
s="right" s="right"
s_h=right s_h=right
x=240 x=240
...@@ -48,7 +50,13 @@ while True: ...@@ -48,7 +50,13 @@ while True:
else: else:
y-=30 y-=30
pos.append((x,y)) pos.append((x,y))
pos.pop(0) if x==a_x and y==a_y:
y1=r.randint(0,15)
x2=r.randint(0,21)
a_x=x2*30
a_y=y1*30
else:
pos.pop(0)
# 将背景图画上去 # 将背景图画上去
screen.blit(background, (0, 0)) screen.blit(background, (0, 0))
# 将贪吃蛇画上去 # 将贪吃蛇画上去
...@@ -57,7 +65,7 @@ while True: ...@@ -57,7 +65,7 @@ while True:
for i in range(len(pos)-1): for i in range(len(pos)-1):
screen.blit(body,pos[i]) screen.blit(body,pos[i])
# 将果实画上去 # 将果实画上去
screen.blit(food, (360, 300)) screen.blit(food, (a_x, a_y))
# 刷新画面 # 刷新画面
pygame.display.update() pygame.display.update()
FPSCLOCK.tick(3) 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