Commit 9cafdb09 by BellCodeEditor

auto save

parent b7183b00
Showing with 2 additions and 52 deletions
......@@ -60,55 +60,5 @@ while True:
if jumpState == "runing":
if event.key == locals.K_SPACE:
jumpState = "up"
if gamestate == True: # if判断当gamestate的值为True时
if jumpState == "up": # 起跳状态
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 = Player(hero[index]) # 将设置悟空造型的代码改成用类来实现
if jumpState == "runing": # 跑步状态下
index += 1
if index >= 5:
index = 0
# 将背景图画上去
bg_x -= 1 # 将远景x坐标每次循环都-1
if bg_x <= -1000: # if判断当远景x坐标小于-1000
bg_x = 0 # 远景x坐标回到0
screen.blit(background, (bg_x, 0)) # 远景代码中x坐标改为bg_x
road_x -= 8 # 将道路x坐标每次循环都-8 使道路和障碍物以相同速度向左移动
if road_x <= -1000: # if判断当道路x坐标小于-1000
road_x = 0 # 道路x坐标回到0
screen.blit(road, (road_x, 500)) # 道路背景代码中x坐标改为变量road_x
screen.blit(wukong.image, (150, y)) # 悟空代码里参数1改为.image
# 创建障碍物对象
time += 1 # 将time值+1
if time >= 60: # if判断time达到60
r = random.randint(0, 100) # 随机数0,100并赋值给遍历r
if r > 40: # 判断r>40
obstacle = Block(bush,cacti,stone) # 创建障碍物精灵
block_list.add(obstacle) # 将精灵添加进精灵组
time = 0 # 将变量time设为0
for sprite in block_list: # for循环,遍历、展示障碍物
sprite.rect.x -= 8 # 将精灵的x坐标-8
# 将程序渲染出来
screen.blit(sprite.image,(sprite.rect.x, sprite.rect.y))
if sprite.rect.x <= 0-sprite.rect.width: # if判断精灵是否完全消失在窗口左边
sprite.kill() # 使用kill()方法将自己清除
if pygame.sprite.collide_rect(wukong, sprite): # 精灵碰撞检测
gemeover = pygame.image.load('gameover.png') # 导入图片素材,游戏结束
screen.blit(gameover, (400, 200)) # 将游戏结束展示在窗口上
gamestate = False # 将变量gamestate的值设为False
# 刷新画面
pygame.display.update()
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