diff --git a/my_game.py b/my_game.py index fab5ace..6eeb714 100644 --- a/my_game.py +++ b/my_game.py @@ -3,6 +3,10 @@ from pygame import locals import random asa='541880452' qqq=input('Are you SB?') +bg_x=0 +roed_x=0 +time=0 + if qqq==asa: pygame.init() # 初始化 class le(pygame.sprite.Sprite): @@ -30,6 +34,7 @@ if qqq==asa: index = 0 y = 400 jumpState = "runing" + t = 30 obstacle = random.choice([bush, stone, cacti]) rect = obstacle.get_rect() @@ -60,7 +65,7 @@ if qqq==asa: if jumpState == "down": # 降落状态 if t <= 30: y += t - t += 2 + t += 2 else: jumpState = "runing" t =30 @@ -72,18 +77,35 @@ if qqq==asa: if index >= 5: index = 0 # 将背景图画上去 + bg _x-=1 + if bg_x<=-1000: + bg_x=0 + screen.blit(background,(bg_x,0)) + roed_x-=8 + if roed_x<=-1000: + roed_x=0 + screen.blit(roed,(roed,0)) + screen.blit(background, (0, 0)) # 远处背景 screen.blit(road, (0, 500)) # 路 screen.blit(wukong, (150, y)) # 悟空 + if time > 60: + r=random.randint(0,100) + if r>40: + obstacle =Block(bush,cacti,stone) + block_list.add(obstacle) + time=0 + for prop in block_list: + prop.rect.x_=8 + screen.blit(prop.image,(prop.rect.x,prop.rect.y)) + if prop.rect.x<=0-prop.rect.width: + prop.kill() - 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)) + + + # 刷新画面 pygame.display.update() - FPS.tick(60) \ No newline at end of file + FPS.tick(60) +print('SB') + diff --git a/qqqqqqqqq.py b/qqqqqqqqq.py index 644e740..db60193 100644 --- a/qqqqqqqqq.py +++ b/qqqqqqqqq.py @@ -26,7 +26,7 @@ obstacle = random.choice([bush, stone, cacti]) rect = obstacle.get_rect() rect.x = 1000 rect.y = 500 - rect.height - +#block_lisst= while True: for event in pygame.event.get(): if event.type == locals.QUIT: @@ -62,13 +62,9 @@ while True: screen.blit(road, (0, 500)) # 路 screen.blit(wukong, (150, y)) # 悟空 - 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 + + #obstacle = random.choice([bush,stone,cacti]) + #block_ screen.blit(obstacle, (rect.x, rect.y)) # 刷新画面 pygame.display.update()