Commit 275f5c93 by BellCodeEditor

save project

parent 1be7df92
Showing with 14 additions and 14 deletions
...@@ -8,7 +8,7 @@ class Black(pygame.sprite.Sprite): ...@@ -8,7 +8,7 @@ class Black(pygame.sprite.Sprite):
def __init__(self,image1,image2,image3): def __init__(self,image1,image2,image3):
super().__init__() super().__init__()
# 创建一个窗口 # 创建一个窗口
screen = pygame.display.set_mode((1000, 600)) screen = pygame.display.set_mode((1000, 600))
...@@ -32,11 +32,9 @@ t = 30 ...@@ -32,11 +32,9 @@ t = 30
bg_x = 0 bg_x = 0
road_x = 0 road_x = 0
time = 0
obstacle = random.choice([bush, stone, cacti]) block_list = pygame.sprite.Group()
rect = obstacle.get_rect()
rect.x = 1000
rect.y = 500 - rect.height
while True: while True:
for event in pygame.event.get(): for event in pygame.event.get():
...@@ -75,17 +73,19 @@ while True: ...@@ -75,17 +73,19 @@ while True:
bg_x = 0 bg_x = 0
# 将背景图画上去 # 将背景图画上去
screen.blit(background, (0, 0)) # 远处背景 screen.blit(background, (bg_x, 0)) # 远处背景
screen.blit(road, (0, 500)) # 路 screen.blit(road, (road_x, 500)) # 路
screen.blit(wukong, (150, y)) # 悟空 screen.blit(wukong, (150, y)) # 悟空
time += 1
if time >= 50:
r = random.randint(0,100)
if r > 40:
obstacle = Block(bush,cacti,stone)
block_list.add(obstacle)
for prop in block_list:
prop.road.x -= 8
screen.blit(prop,image,(prop,rect.x))
if rect.x <= 0-rect.width: # 障碍物消失
# 创建障碍物对象
obstacle = random.choice([bush,stone,cacti])
rect = obstacle.get_rect()
rect.x = 1000
rect.y = 500 - rect.height
rect.x -= 8
screen.blit(obstacle, (rect.x, rect.y)) screen.blit(obstacle, (rect.x, rect.y))
# 刷新画面 # 刷新画面
pygame.display.update() pygame.display.update()
......
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