Commit c7a81cd0 by BellCodeEditor

save project

parent dbfc61f9
Showing with 23 additions and 23 deletions
...@@ -48,7 +48,7 @@ score_audio = pygame.mixer.Sound('score.wav') ...@@ -48,7 +48,7 @@ score_audio = pygame.mixer.Sound('score.wav')
index = 0 index = 0
y = 400 y = 400
jumpState = "runing" jumpState = "runing"
t = 30 t = 35
score=0 score=0
road_x = 0 road_x = 0
bg_x = 0 bg_x = 0
...@@ -91,13 +91,13 @@ while True: ...@@ -91,13 +91,13 @@ while True:
else: else:
jumpState = "down" jumpState = "down"
if jumpState == "down": # 降落状态 if jumpState == "down": # 降落状态
if t <= 30: if t <= 35:
y += t y += t
wukong.rect.y = y wukong.rect.y = y
t += 2 t += 2
else: else:
jumpState = "runing" jumpState = "runing"
t =30 t =35
# 将背景图画上去 # 将背景图画上去
...@@ -107,7 +107,7 @@ while True: ...@@ -107,7 +107,7 @@ while True:
screen.blit(background, (bg_x, 0)) # 远景 screen.blit(background, (bg_x, 0)) # 远景
road_x -= speed road_x -= speed
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)) # 道路
...@@ -129,36 +129,36 @@ while True: ...@@ -129,36 +129,36 @@ while True:
gameover = pygame.image.load('gameover.png') # 游戏结束 gameover = pygame.image.load('gameover.png') # 游戏结束
screen.blit(gameover, (400, 200)) screen.blit(gameover, (400, 200))
gamestate = False gamestate = False
if score>three: if score > three:
if score>one: if score > one:
record['第1名']=score record['第1名'] = score
record['第2名']=one record['第2名'] = one
record['第3名']=two record['第3名'] = two
elif score>two: elif score > two:
record['第2名']=score record['第2名'] = score
record['第3名']=two record['第3名'] = two
else: else:
record['第3名']=score record['第3名'] = score
record=json.dumps(record,ensure_ascii=False) record=json.dumps(record,ensure_ascii=False)
with open('record.txt','w',encoding='utf-8') as f: with open('record.txt','w',encoding='utf-8') as f:
f.write(record) f.write(record)
else: else:
if sprite.rect.x+sprite.rect.width<wukong.rect.x: if sprite.rect.x + sprite.rect.width < wukong.rect.x:
score+=sprite.score score += sprite.score
sprite.score=0 sprite.score = 0
if score>old_score: if score>old_score:
score_audio.play() score_audio.play()
old_score=score old_score=score
scoreSurf = basic_font.render("分数:"+str(score),True,(0,0,0)) scoreSurf = basic_font.render("分数:" + str(score),True,(0,0,0))
screen.blit(scoreSurf,(850,20)) screen.blit(scoreSurf,(850,20))
scoreSurf = basic_font.render("第一名:"+str(one),True,(0,0,0)) scoreSurf = basic_font.render("第一名:" + str(one),True,(0,0,0))
screen.blit(scoreSurf,(850,50)) screen.blit(scoreSurf,(850,50))
scoreSurf = basic_font.render("第二名:"+str(two),True,(0,0,0)) scoreSurf = basic_font.render("第二名:" + str(two),True,(0,0,0))
screen.blit(scoreSurf,(850,80)) screen.blit(scoreSurf,(850,80))
scoreSurf = basic_font.render("第三名:"+str(three),True,(0,0,0)) scoreSurf = basic_font.render("第三名:" + str(three),True,(0,0,0))
screen.blit(scoreSurf,(850,110)) screen.blit(scoreSurf,(850,110))
# 刷新画面 # 刷新画面
pygame.display.update() pygame.display.update()
......
{"第1名": 1, "第2名": 1, "第3名": 0} {"第1名": 0, "第2名": 0, "第3名": 0}
\ 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