Commit cc5636ea by BellCodeEditor

save project

parent eb6b22b0
Showing with 8 additions and 3 deletions
import random
import pygame import pygame
from pygame import locals from pygame import locals
...@@ -5,7 +6,7 @@ from pygame import locals ...@@ -5,7 +6,7 @@ from pygame import locals
pygame.init() pygame.init()
SB = pygame.time.Clock() SB = pygame.time.Clock()
# 创建一个窗口 # 创建一个窗口
screen = pygame.display.set_mode((6600, 480)) screen = pygame.display.set_mode((660, 480))
# 背景 # 背景
background = pygame.image.load('bg.png') background = pygame.image.load('bg.png')
...@@ -21,6 +22,7 @@ x,y = 240,120 ...@@ -21,6 +22,7 @@ x,y = 240,120
a = [(180,90),(180,120),(210,120),(x,y)] a = [(180,90),(180,120),(210,120),(x,y)]
se = 'ri' se = 'ri'
s_e = ri s_e = ri
a_x,a_y = 360, 300
while True: while True:
for event in pygame.event.get(): for event in pygame.event.get():
if event.type == locals.QUIT: if event.type == locals.QUIT:
...@@ -48,7 +50,9 @@ while True: ...@@ -48,7 +50,9 @@ while True:
y -= 30 y -= 30
else: else:
y += 30 y += 30
if x ==a_x and y == a_y:
a_x = random.randint(0, 660)
a_y = random.randint(0, 480)
a.append((x,y)) a.append((x,y))
a.pop(0) a.pop(0)
# 将背景图画上去 # 将背景图画上去
...@@ -59,7 +63,7 @@ while True: ...@@ -59,7 +63,7 @@ while True:
for i in range(len(a)-1): for i in range(len(a)-1):
screen.blit(body, a[i]) screen.blit(body, a[i])
# 将果实画上去 # 将果实画上去
screen.blit(food, (360, 300)) screen.blit(food, (a_x, a_y))
# 刷新画面 # 刷新画面
pygame.display.update() pygame.display.update()
SB.tick(10) SB.tick(10)
\ 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