Commit 4d0c2421 by BellCodeEditor

save project

parent ac9335ac
Showing with 17 additions and 13 deletions
......@@ -10,16 +10,17 @@ 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
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') # 背景
road = pygame.image.load('road.png') # 路
......@@ -50,9 +51,15 @@ while True:
if event.key == locals.K_SPACE:
if jumpState == "running":
jumpState = "up"
wukong =Player(hero[i])
if jumpState == "running":
i += 1
if i > 4:
i = 0
if game_statu==True:
if jumpState == "up" :
if t > 0:
y -= t
wukong.rect.y=y
t -= 2
else:
......@@ -60,16 +67,13 @@ while True:
if jumpState == "down":
if t <= 30:
y += t
wukong.rect.y=y
t += 2
else:
t = 30
jumpState = "running"
wukong =player(hero[index])
if jumpState == "running":
i += 1
if i > 4:
i = 0
road_x-=8
if road_x<=-1000:
road_x=0
......@@ -80,7 +84,7 @@ while True:
# 将背景图画上去
screen.blit(background, (b_x, 0))
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:
# obstacle =Block(stone,cacti,bush)
......@@ -98,7 +102,7 @@ while True:
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):
if pygame.sprite.collide_rect(wukong,sprite):
gameover=pygame.image.load("gameover.png")
screen.blit(gameover,(400,200))
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