diff --git a/my_game.py b/my_game.py index 7cca968..6887950 100644 --- a/my_game.py +++ b/my_game.py @@ -12,7 +12,7 @@ class Block(pygame.sprite.Sprite): self.rect.y=500-self.rect.height screen = pygame.display.set_mode((1000, 600)) FPS = pygame.time.Clock() # pygame时钟,控制游戏速度(帧数) - +zaw_list=pygame.sprite.Group() # 载入图片 background = pygame.image.load('bg.png') # 背景 road = pygame.image.load('road.png') # 路 @@ -35,7 +35,7 @@ y=400 #z=random.choice([stone,cacti,apple]) #rect=stone.get_rect() #z_x=1000 - +time=0 road_x=0 bg_x=0 while True: @@ -74,10 +74,20 @@ while True: #z_x-=8 road_x-=8 bg_x-=1 - if zaw.rect.x<= 0-zaw.rect.width: - zaw=Block(stone,cacti,apple) - screen.blit(zaw.image, (zaw.rect.x, 500-zaw.rect.height)) - zaw.rect.x-=8 + #if zaw.rect.x<= 0-zaw.rect.width: + time+=1 + if time>=60: + time=0 + num=random.randint(0,50) + if num>20: + zaw=Block(stone,cacti,apple) + zaw_list.add(zaw) + for i in zaw_list: + i.rect.x-=8 + screen.blit(i.image, (i.rect.x, 500-i.rect.height)) + if i.rect.x<=0-i.rect.width: + i.kill() + #z=random.choice([stone,cacti,apple]) #rect=stone.get_rect() #z_x=1000