Commit 4d0c2421 by BellCodeEditor

save project

parent ac9335ac
Showing with 18 additions and 14 deletions
...@@ -10,16 +10,17 @@ pygame.display.set_caption("悟空酷跑") ...@@ -10,16 +10,17 @@ pygame.display.set_caption("悟空酷跑")
class Block(pygame.sprite.Sprite): class Block(pygame.sprite.Sprite):
def __init__(self,imagel,image2,image3): def __init__(self,imagel,image2,image3):
super().__init__() 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.image=random.choice([imagel,image2,image3])
self.rect=self.image.get_rect() self.rect=self.image.get_rect()
self.rect.x=1000 self.rect.x=1000
self.rect.y=500-self.rect.height self.rect.y=500-self.rect.height
class Player(pygame.sprite.Sprite):
def __init__(self,image):
super().__init__()
self.image=image
self.rect=self.image.get_rect()
self.rect.x=150
self.rect.y=400
# 载入图片 # 载入图片
background = pygame.image.load('bg.png') # 背景 background = pygame.image.load('bg.png') # 背景
road = pygame.image.load('road.png') # 路 road = pygame.image.load('road.png') # 路
...@@ -49,10 +50,16 @@ while True: ...@@ -49,10 +50,16 @@ while True:
if event.type == locals.KEYDOWN: if event.type == locals.KEYDOWN:
if event.key == locals.K_SPACE: if event.key == locals.K_SPACE:
if jumpState == "running": if jumpState == "running":
jumpState = "up" jumpState = "up"
wukong =Player(hero[i])
if jumpState == "running":
i += 1
if i > 4:
i = 0
if game_statu==True: if game_statu==True:
if jumpState == "up" : if jumpState == "up" :
if t > 0: if t > 0:
y -= t
wukong.rect.y=y wukong.rect.y=y
t -= 2 t -= 2
else: else:
...@@ -60,16 +67,13 @@ while True: ...@@ -60,16 +67,13 @@ while True:
if jumpState == "down": if jumpState == "down":
if t <= 30: if t <= 30:
y += t y += t
wukong.rect.y=y
t += 2 t += 2
else: else:
t = 30 t = 30
jumpState = "running" jumpState = "running"
wukong =player(hero[index])
if jumpState == "running":
i += 1
if i > 4:
i = 0
road_x-=8 road_x-=8
if road_x<=-1000: if road_x<=-1000:
road_x=0 road_x=0
...@@ -80,7 +84,7 @@ while True: ...@@ -80,7 +84,7 @@ while True:
# 将背景图画上去 # 将背景图画上去
screen.blit(background, (b_x, 0)) screen.blit(background, (b_x, 0))
screen.blit(road, (road_x, 500)) screen.blit(road, (road_x, 500))
screen.blit(wukong, (150, y)) screen.blit(wukong.image, (150, y))
# if obstacle.rect.x < 0-obstacle.rect.width: # if obstacle.rect.x < 0-obstacle.rect.width:
# obstacle =Block(stone,cacti,bush) # obstacle =Block(stone,cacti,bush)
...@@ -98,7 +102,7 @@ while True: ...@@ -98,7 +102,7 @@ while True:
screen.blit(sprite.image,(sprite.rect.x,sprite.rect.y)) screen.blit(sprite.image,(sprite.rect.x,sprite.rect.y))
if sprite.rect.x<=0-sprite.rect.width: if sprite.rect.x<=0-sprite.rect.width:
sprite.kill() sprite.kill()
if pygame.sprite.collide_rect(wukong,prop): if pygame.sprite.collide_rect(wukong,sprite):
gameover=pygame.image.load("gameover.png") gameover=pygame.image.load("gameover.png")
screen.blit(gameover,(400,200)) screen.blit(gameover,(400,200))
game_statu=False game_statu=False
......
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