Commit 1a315f5e by BellCodeEditor

save project

parent 3aed82c0
Showing with 58 additions and 51 deletions
...@@ -42,6 +42,7 @@ t = 30 ...@@ -42,6 +42,7 @@ t = 30
bg_x = 0 bg_x = 0
road_x = 0 road_x = 0
time = 0 time = 0
gamestate = True
block_list = pygame.sprite.Group() block_list = pygame.sprite.Group()
obstacle = Block(stone,bush,cacti) obstacle = Block(stone,bush,cacti)
...@@ -56,55 +57,61 @@ while True: ...@@ -56,55 +57,61 @@ while True:
if event.key == locals.K_SPACE: if event.key == locals.K_SPACE:
jumpState = "up" jumpState = "up"
if jumpState == "up": # 起跳状态 wukong = Player(hero[index])
if t > 0:
y -= t
t -= 2
else:
jumpState = "down"
if jumpState == "down": # 降落状态
if t <= 30:
y += t
t += 2
else:
jumpState = "runing"
t =30
# 悟空造型
wukong = hero[index]
if jumpState == "runing": # 跑步状态下
index += 1
if index >= 5:
index = 0
# 将背景图画上去
bg_x -= 1
if bg_x <= -1000:
bg_x = 0
screen.blit(background, (bg_x, 0)) # 远处背景 if gamestate == True:
road_x -= 8 if jumpState == "up": # 起跳状态
if road_x <= -1000: if t > 0:
road_x = 0 y -= t
screen.blit(road, (road_x, 500)) # 路 wukong.rect.y = y
screen.blit(wukong, (150, y)) # 悟空 t -= 2
else:
jumpState = "down"
if jumpState == "down": # 降落状态
if t <= 30:
y += t
t += 2
else:
jumpState = "runing"
t =30
# 悟空造型
if jumpState == "runing": # 跑步状态下
index += 1
if index >= 5:
index = 0
# 将背景图画上去
bg_x -= 1
if bg_x <= -1000:
bg_x = 0
# if obstacle.rect.x <= 0-obstacle.rect.width: # 障碍物消失 screen.blit(background, (bg_x, 0)) # 远处背景
# # 创建障碍物对象 road_x -= 8
# obstacle = Block(stone,bush,cacti) if road_x <= -1000:
# obstacle.rect.x -= 8 road_x = 0
time += 1 screen.blit(road, (road_x, 500)) # 路
if time >= 60: screen.blit(wukong.image, (150, y)) # 悟空
r = random.randint(0,100)
if r > 40: # if obstacle.rect.x <= 0-obstacle.rect.width: # 障碍物消失
obstacle = Block(stone,bush,cacti) # # 创建障碍物对象
block_list.add(obstacle) # obstacle = Block(stone,bush,cacti)
time =0 # obstacle.rect.x -= 8
for prop in block_list: time += 1
prop.rect.x -= 8 if time >= 60:
screen.blit(prop.image,(prop.rect.x,prop.rect.y)) r = random.randint(0,100)
if prop.rect.x <=0-prop.rect.width: if r > 40:
prop.kill() obstacle = Block(stone,bush,cacti)
screen.blit(obstacle.image, (obstacle.rect.x, obstacle.rect.y)) block_list.add(obstacle)
# 刷新画面 time =0
pygame.display.update() for sprite in block_list:
FPS.tick(150) sprite.rect.x -= 8
\ No newline at end of file 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,sprite):
gameover = pygame.image.load('gameover.png')
screen.blit(gameover,(400,200))
gamestate = False
# 刷新画面
pygame.display.update()
FPS.tick(150)
\ 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