Commit 0c19e969 by BellCodeEditor

auto save

parent 686c5f10
Showing with 29 additions and 4 deletions
File added
import pygame
from pygame import locals
import random
import json
pygame.init() # 初始化
......@@ -11,12 +12,13 @@ class Block(pygame.sprite.Sprite): # 障碍物精灵类
self.image = random.choice([image1, image2, image3])
# 根据障碍物位图的宽高设置矩形
self.rect = self.image.get_rect()
self.score=0
# 障碍物绘制坐标
self.rect.x = 1000
self.rect.y = 500 - self.rect.height
class Player(pygame.sprite.Sprite): # 悟空
def __init__(self, image):
def __init__( self, image):
super().__init__()
# 加载悟空精灵图像
self.image = image
......@@ -49,9 +51,16 @@ road_x = 0
bg_x = 0
time = 0
gamestate = True
score = 0
ole_score = score
block_list =pygame.sprite.Group() # 创建精灵组
with open('score.txt','r',encoding='utf-8')as f:
concert = f.read()
recond=json.loads(content)
one=content['第一名']
two=content['第二名']
thr=content['第三名']
while True:
for event in pygame.event.get():
if event.type == locals.QUIT:
......@@ -115,8 +124,22 @@ while True:
gameover = pygame.image.load('gameover.png') # 游戏结束
screen.blit(gameover, (400, 200))
gamestate = False
scoreSurf = basic_font.render("分数:"+str(score),True,(255,0,0))
screen.blit(scoreSurf,(850,20))
else:
if(sprite.rect.x+sprite.rect.width)<wukong.rect.x:
score+=sprite.score
sprite.score+0
if score>old_score:
score_audio.play()
old_score=score
scoreSurf = basic_font.render("分数:"+str(score),True,(255,255,255))
screen.blit(scoreSurf,(880,20))
scoreSurf = basic_font.render("第一名:"+str(score),True,(255,255,255))
screen.blit(scoreSurf,(880,50))
scoreSurf = basic_font.render("第二名:"+str(score),True,(255,255,255))
screen.blit(scoreSurf,(880,80))
scoreSurf = basic_font.render("第三名:"+str(score),True,(255,255,255))
screen.blit(scoreSurf,(880,110))
# 刷新画面
pygame.display.update()
......
{"第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