diff --git a/my_game.py b/my_game.py index 006ed0c..e21c359 100644 --- a/my_game.py +++ b/my_game.py @@ -32,13 +32,21 @@ y = 400 jumpState = "runing" t = 30 sb=B(bush,cacti,stone) -sp=pygame.sprite.Group() +sp_list=pygame.sprite.Group() time=0 while True: - if time=60: + time+=1 + if time==60: time=0 - num=random.randint(0,50) - screen.blit(sb.image, (sb.rect.x, sb.rect.y)) + num=random.randint(0,100) + if num>40: + sb=B(bush,cacti,stone) + sp_list.add(sb) + for vk in sp_list: + vk.rect.x-=8 + screen.blit(vk.image, (vk.rect.x, vk.rect.y)) + if vk.rect.x<=0-vk.rect.width: + vk.kill() for event in pygame.event.get(): if event.type == locals.QUIT: # 接收到退出事件后退出程序 @@ -79,13 +87,8 @@ while True: screen.blit(road, (road_x, 500)) # 路 screen.blit(wukong, (150, y)) # 悟空 - if sb.rect.x <= 0-sb .rect.width: # 障碍物消失 - # 创建障碍物对象 - aa=B(bush,cacti,stone) - sb.rect.x -= 8 - - + # 刷新画面 pygame.display.update() FPS.tick(25) \ No newline at end of file