Commit ac9335ac by BellCodeEditor

save project

parent 864ebc7d
Showing with 60 additions and 48 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,54 +50,59 @@ while True: ...@@ -43,54 +50,59 @@ 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 jumpState == "up" : if game_statu==True:
if t > 0: if jumpState == "up" :
y -= t if t > 0:
t -= 2 wukong.rect.y=y
else: t -= 2
jumpState = "down" else:
if jumpState == "down": jumpState = "down"
if t <= 30: if jumpState == "down":
y += t if t <= 30:
t += 2 y += t
else: t += 2
t = 30 else:
jumpState = "running" t = 30
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:
i = 0 i = 0
road_x-=8 road_x-=8
if road_x<=-1000: if road_x<=-1000:
road_x=0 road_x=0
b_x-=2 b_x-=2
if b_x<=-1000: if b_x<=-1000:
b_x=0 b_x=0
# 将背景图画上去 # 将背景图画上去
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, (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)
# obstacle.rect.x -= 8 # obstacle.rect.x -= 8
# screen.blit(obstacle.image,(obstacle.rect.x,obstacle.rect.y)) # screen.blit(obstacle.image,(obstacle.rect.x,obstacle.rect.y))
time+=1 time+=1
if time>=60: if time>=60:
time=0 time=0
num=random.randint(0,50) num=random.randint(0,50)
if num>20: if num>20:
obstacle =Block(stone,cacti,bush) obstacle =Block(stone,cacti,bush)
block_list.add(obstacle) block_list.add(obstacle)
for sprite in block_list: for sprite in block_list:
sprite.rect.x-=8 sprite.rect.x-=8
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()
FPS.tick(60) FPS.tick(60)
\ No newline at end of file \ 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