Commit ce6ffa7d by BellCodeEditor

auto save

parent 6c067fcc
Showing with 20 additions and 13 deletions
...@@ -44,8 +44,10 @@ obstacle = random.choice([stone,cacti,bush]) ...@@ -44,8 +44,10 @@ obstacle = random.choice([stone,cacti,bush])
rect= obstacle.get_rect() #获取图片的坐标和长宽属性 rect= obstacle.get_rect() #获取图片的坐标和长宽属性
rect.x=1000 rect.x=1000
rect.y=500-rect.height rect.y=500-rect.height
time = 0
obstacle=Block(bush,cacti,stone)
block_list=pygame.sprite.Group()#创建精灵组
while True: while True:
...@@ -66,7 +68,7 @@ while True: ...@@ -66,7 +68,7 @@ while True:
if jumpState == "down": # 降落 if jumpState == "down": # 降落
if t <= 30: if t <= 30:
y += t y += t
t += 0.00000002 t += 2
else: else:
jumpState = "running" jumpState = "running"
...@@ -78,23 +80,28 @@ while True: ...@@ -78,23 +80,28 @@ while True:
index+=1 index+=1
if index==5: if index==5:
index=0 index=0
# 将背景图画上去 # 将背景图画上去
screen.blit(background, (0, 0)) screen.blit(background, (0, 0))
screen.blit(road, (0, 500)) screen.blit(road, (0, 500))
screen.blit(wukong, (150, y)) screen.blit(wukong, (150, y))
#一个障碍物消失后,在添加一个新的障碍物
if rect.x<=0-rect.width: time += 1
obstacle=random.choice(zaw) if time >= 60:
rect=obstacle.get_rect() time = 0
rect.x=1000 num = random.randint(0,50)
rect.y=500-rect.width if num > 20:
obstacle=Block(bush,cacti,stone)#创建障碍物精灵
rect.x-=8 block_list.add(obstacle)
screen.blit(obstacle,(rect.x,rect.y)) for sprite in block_list:
sprite.rect.x -=8
screen.blit(sprite.image,(sprite.rect.x,sprite.rect.y))
if sprite.rect.x <= 0-sprite.rect.width:
sprite.kill()
# 刷新画面 # 刷新画面
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