Commit c996bf3e by BellCodeEditor

save project

parent 58b3c267
Showing with 37 additions and 33 deletions
...@@ -42,6 +42,7 @@ time = 0 ...@@ -42,6 +42,7 @@ time = 0
road_x = 0 road_x = 0
bg_x = 0 bg_x = 0
wukong = Wukong(hero[0]) wukong = Wukong(hero[0])
gameState = 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:
...@@ -65,36 +66,39 @@ while True: ...@@ -65,36 +66,39 @@ while True:
else: else:
jumpState = "runing" jumpState = "runing"
t =30 t =30
if gameState == True:
# 悟空造型 # 悟空造型
wukong.image = hero[index] ` wukong.image = hero[index]
if jumpState == "runing": # 跑步状态下 if jumpState == "runing": # 跑步状态下
index += 1 index += 1
if index >= 5: if index >= 5:
index = 0 index = 0
# 将背景图画上去 # 将背景图画上去
bg_x -= 1 bg_x -= 1
if bg_x <= -1000: if bg_x <= -1000:
bg_x = 0 bg_x = 0
screen.blit(background, (bg_x, 0)) screen.blit(background, (bg_x, 0))
road_x -= 8 road_x -= 8
if road_x <= -1000: if road_x <= -1000:
road_x = 0 road_x = 0
# 远处背景 # 远处背景
screen.blit(road, (road_x, 500)) # 路 screen.blit(road, (road_x, 500)) # 路
screen.blit(wukong.image, (wukong.rect.x,wukong.rect.y)) # 悟空 screen.blit(wukong.image, (wukong.rect.x,wukong.rect.y)) # 悟空
time += 1 time += 1
if time >= 60: if time >= 60:
time = 0 time = 0
jian = random.randint(0,5) jian = random.randint(0,5)
if jian >= 2: if jian >= 2:
obstacle = Block(bush,stone,cacti) obstacle = Block(bush,stone,cacti)
block_list.add(obstacle) block_list.add(obstacle)
for obstacle in block_list: for obstacle in block_list:
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))
if obstacle.rect.x <= 0-obstacle.rect.width: if obstacle.rect.x <= 0-obstacle.rect.width:
obstacle.kill() obstacle.kill()
if pygame.sprite.collide_rect(wukong,obstacle):
pygame.display.update() gameOver = pygame.image.load('gameover.png')
FPS.tick(60) screen.blit(gameOver,(400,200))
\ No newline at end of file gameState = False
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