Commit ac9335ac by BellCodeEditor

save project

parent 864ebc7d
Showing with 60 additions and 48 deletions
......@@ -10,6 +10,12 @@ pygame.display.set_caption("悟空酷跑")
class Block(pygame.sprite.Sprite):
def __init__(self,imagel,image2,image3):
super().__init__()
self.image=image
self.rect=self.image.get_rect()
self.rect.x=150
self.rect.y=400
def __init__(self,imagel,image2,image3):
super().__init__()
self.image=random.choice([imagel,image2,image3])
self.rect=self.image.get_rect()
self.rect.x=1000
......@@ -34,6 +40,7 @@ jumpState = "running"
obstacle = Block(stone,cacti,bush)
block_list=pygame.sprite.Group()
time=0
game_statu=True
while True:
for event in pygame.event.get():
if event.type == locals.QUIT:
......@@ -43,54 +50,59 @@ while True:
if event.key == locals.K_SPACE:
if jumpState == "running":
jumpState = "up"
if jumpState == "up" :
if t > 0:
y -= t
t -= 2
else:
jumpState = "down"
if jumpState == "down":
if t <= 30:
y += t
t += 2
else:
t = 30
jumpState = "running"
if game_statu==True:
if jumpState == "up" :
if t > 0:
wukong.rect.y=y
t -= 2
else:
jumpState = "down"
if jumpState == "down":
if t <= 30:
y += t
t += 2
else:
t = 30
jumpState = "running"
wukong = hero[i]
if jumpState == "running":
i += 1
if i > 4:
i = 0
road_x-=8
if road_x<=-1000:
road_x=0
b_x-=2
if b_x<=-1000:
b_x=0
wukong =player(hero[index])
if jumpState == "running":
i += 1
if i > 4:
i = 0
road_x-=8
if road_x<=-1000:
road_x=0
b_x-=2
if b_x<=-1000:
b_x=0
# 将背景图画上去
screen.blit(background, (b_x, 0))
screen.blit(road, (road_x, 500))
screen.blit(wukong, (150, y))
# 将背景图画上去
screen.blit(background, (b_x, 0))
screen.blit(road, (road_x, 500))
screen.blit(wukong, (150, y))
# if obstacle.rect.x < 0-obstacle.rect.width:
# obstacle =Block(stone,cacti,bush)
# obstacle.rect.x -= 8
# screen.blit(obstacle.image,(obstacle.rect.x,obstacle.rect.y))
time+=1
if time>=60:
time=0
num=random.randint(0,50)
if num>20:
obstacle =Block(stone,cacti,bush)
block_list.add(obstacle)
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()
# if obstacle.rect.x < 0-obstacle.rect.width:
# obstacle =Block(stone,cacti,bush)
# obstacle.rect.x -= 8
# screen.blit(obstacle.image,(obstacle.rect.x,obstacle.rect.y))
time+=1
if time>=60:
time=0
num=random.randint(0,50)
if num>20:
obstacle =Block(stone,cacti,bush)
block_list.add(obstacle)
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()
if pygame.sprite.collide_rect(wukong,prop):
gameover=pygame.image.load("gameover.png")
screen.blit(gameover,(400,200))
game_statu=False
# # 刷新画面
pygame.display.update()
FPS.tick(60)
\ No newline at end of file
# # 刷新画面
pygame.display.update()
FPS.tick(60)
\ No newline at end of file
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