Commit 625f5053 by BellCodeEditor

save project

parent 6e0aa71e
Showing with 39 additions and 3 deletions
File added
import pygame
from pygame import locals
import random
import json
pygame.init() # 初始化
# 创建一个窗口
screen = pygame.display.set_mode((1000, 600))
#导入
FPS = pygame.time.Clock() # pygame时钟,控制游戏速度(帧数)
pygame.display.set_caption("悟空酷跑")
background = pygame.image.load('bg.png') # 背景
......@@ -18,6 +20,7 @@ hero = [pygame.image.load('hero1.png'),
pygame.image.load('hero3.png'),
pygame.image.load('hero4.png'),
pygame.image.load('hero5.png')]
hero_list = 0
y=400
jump="runing"
......@@ -44,9 +47,21 @@ bg_x=0
c=True
score=0
speed=8
old_score=0
score_music=pygame.mixer.Sound("Coin.wav")
with open("score.txt","r",encoding="utf-8") as file:
abc=file.read()
bcd=json.loads(abc)
one=bcd["第1名"]
two=bcd["第2名"]
three=bcd["第3名"]
while True:
speed=8+score//3
speed=8+score//2
if score>old_score:
score_music.play()
old_score=score
for event in pygame.event.get():
if event.type == locals.QUIT:
# 接收到退出事件后退出程序
......@@ -104,6 +119,20 @@ while True:
gameover=pygame.image.load("gameover.png")
screen.blit(gameover,(400,200))
c=False
if score>three:
if score>one:
bcd["第1名"]=score
bcd["第2名"]=one
bcd["第3名"]=two
elif score>two:
bcd["第2名"]=score
bcd["第3名"]=two
else:
bcd["第3名"]=score
bcd=json.dumps(bcd,ensure_ascii=False)
with open("score.txt","w",encoding="utf-8") as file1:
file1.write(bcd)
else:
if sprite.rect.x+sprite.rect.width<wukong.rect.x:
score+=sprite.score
......@@ -111,6 +140,12 @@ while True:
info="游戏分数:"+str(score)
text=font.render(info,True,(255,255,255))
screen.blit(text,(880,20))
one_1=font.render("第一名:"+str(one),True,(255,255,255))
screen.blit(one_1,(880,45))
two_1=font.render("第二名:"+str(two),True,(255,255,255))
screen.blit(two_1,(880,70))
three_1=font.render("第三名:"+str(three),True,(255,255,255))
screen.blit(three_1,(880,95))
# 刷新画面
pygame.display.update()
FPS.tick(60)
\ No newline at end of file
{"第1名": 0, "第2名": 0, "第3名": 0}
\ No newline at end of file
{"第1名": 10, "第2名": 5, "第3名": 3}
\ 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