Commit e49a3760 by BellCodeEditor

save project

parent 67686519
Showing with 24 additions and 12 deletions
...@@ -43,7 +43,7 @@ gameover = pygame.image.load('gameover.png') ...@@ -43,7 +43,7 @@ gameover = pygame.image.load('gameover.png')
chenggong = pygame.image.load('cg.png') chenggong = pygame.image.load('cg.png')
block_list = pygame.sprite.Group() block_list = pygame.sprite.Group()
basic_font = pygame.font.Font('STKAITI.TTF',32) basic_font = pygame.font.Font('STKAITI.TTF',30)
score_music = pygame.mixer.Sound('score.wav') score_music = pygame.mixer.Sound('score.wav')
#pygame.mixer.music.load('孤勇者.mp3') #pygame.mixer.music.load('孤勇者.mp3')
pygame.mixer.music.load('西瓜冬瓜哈密瓜(抖音DJ完整版) - 莹酱.mp3') pygame.mixer.music.load('西瓜冬瓜哈密瓜(抖音DJ完整版) - 莹酱.mp3')
...@@ -59,12 +59,12 @@ speed = 15 ...@@ -59,12 +59,12 @@ speed = 15
kaishi = 'T' kaishi = 'T'
score = 0 score = 0
#创建障碍物 #创建障碍物
with open("score.txt","r",encoding="utf-8") as f: with open("record.txt","r",encoding="utf-8") as f:
content = f.read() content = f.read()
zhi = json.loads(content) record = json.loads(content)
one = zhi["第1名"] one = record["第1名"]
two = zhi["第2名"] two = record["第2名"]
three = zhi["第3名"] three = record["第3名"]
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:
...@@ -125,7 +125,20 @@ while True: ...@@ -125,7 +125,20 @@ while True:
sprite.kill() sprite.kill()
if pygame.sprite.collide_rect(wukong,sprite): if pygame.sprite.collide_rect(wukong,sprite):
screen.blit(gameover, (400,200)) screen.blit(gameover, (400,200))
kaishi = 'F' kaishi = 'F'
if score > three:
if score > one:
record['第1名'] = score
record['第2名'] = one
record['第3名'] = two
elif score > two:
record['第2名'] = score
record['第3名'] = two
else:
record['第3名'] = score
record = json.dumps(record,ensure_ascii=False)
with open("record.txt","w",encoding="utf-8") as s:
s.write()
else: else:
if sprite.rect.x + sprite.rect.width < 150: if sprite.rect.x + sprite.rect.width < 150:
score += sprite.score score += sprite.score
...@@ -143,9 +156,9 @@ while True: ...@@ -143,9 +156,9 @@ while True:
yi = basic_font.render("第1名:" + str(one),True,(0,0,0)) yi = basic_font.render("第1名:" + str(one),True,(0,0,0))
er = basic_font.render("第2名:" + str(two),True,(0,0,0)) er = basic_font.render("第2名:" + str(two),True,(0,0,0))
san = basic_font.render("第3名:" + str(three),True,(0,0,0)) san = basic_font.render("第3名:" + str(three),True,(0,0,0))
screen.blit(yi,(850,100)) screen.blit(yi,(850,50))
screen.blit(er,(850,150)) screen.blit(er,(850,80))
screen.blit(san,(850,200)) screen.blit(san,(850,110))
# 刷新画面 # 刷新画面
pygame.display.update() pygame.display.update()
FPS.tick(60) FPS.tick(60)
\ No newline at end of file
{"第1名": 0, "第2名": 0, "第3名": 0}
\ 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