Commit ac9335ac by BellCodeEditor

save project

parent 864ebc7d
Showing with 14 additions and 2 deletions
...@@ -10,6 +10,12 @@ pygame.display.set_caption("悟空酷跑") ...@@ -10,6 +10,12 @@ 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
...@@ -34,6 +40,7 @@ jumpState = "running" ...@@ -34,6 +40,7 @@ jumpState = "running"
obstacle = Block(stone,cacti,bush) obstacle = Block(stone,cacti,bush)
block_list=pygame.sprite.Group() block_list=pygame.sprite.Group()
time=0 time=0
game_statu=True
while True: while True:
for event in pygame.event.get(): for event in pygame.event.get():
if event.type == locals.QUIT: if event.type == locals.QUIT:
...@@ -43,9 +50,10 @@ while True: ...@@ -43,9 +50,10 @@ while True:
if event.key == locals.K_SPACE: if event.key == locals.K_SPACE:
if jumpState == "running": if jumpState == "running":
jumpState = "up" jumpState = "up"
if game_statu==True:
if jumpState == "up" : if jumpState == "up" :
if t > 0: if t > 0:
y -= t wukong.rect.y=y
t -= 2 t -= 2
else: else:
jumpState = "down" jumpState = "down"
...@@ -57,7 +65,7 @@ while True: ...@@ -57,7 +65,7 @@ while True:
t = 30 t = 30
jumpState = "running" jumpState = "running"
wukong = hero[i] wukong =player(hero[index])
if jumpState == "running": if jumpState == "running":
i += 1 i += 1
if i > 4: if i > 4:
...@@ -90,6 +98,10 @@ while True: ...@@ -90,6 +98,10 @@ 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):
gameover=pygame.image.load("gameover.png")
screen.blit(gameover,(400,200))
game_statu=False
# # 刷新画面 # # 刷新画面
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