Commit 7c8ec8fd by BellCodeEditor

save project

parent e8a019d9
Showing with 21 additions and 8 deletions
import pygame
from pygame import locals
import random
import json
pygame.init() # 初始化
class Block(pygame.sprite.Sprite): # 障碍物精灵类
def __init__(self,image1,image2,image3):
super().__init__()
# 加载障碍物的图片
self.image = random.choice([image1, image2, image3])
# 根据障碍物位图的宽高设置矩形
self.rect = self.image.get_rect()
# 障碍物绘制坐标
self.rect.x = 1000
self.rect.y = 500 - self.rect.height
self.score = 1
......@@ -20,6 +13,14 @@ class Player(pygame.sprite.Sprite): # 悟空
def __init__(self, image):
super().__init__()
# 加载悟空精灵图像
class Block(pygame.sprite.Sprite): # 障碍物精灵类
def __init__(self,image1,image2,image3):
super().__init__()
# 加载障碍物的图片
self.image = random.choice([image1, image2, image3])
# 根据障碍物位图的宽高设置矩形
self.rect = self.image.get_rect()
# 障碍物绘制坐标
self.image = image
# image的get_rect()方法,可以返回pygame.Rect(0,0,图像宽,图像高)的对象
self.rect = self.image.get_rect()
......@@ -57,6 +58,13 @@ speed = 0
oldScore = 0
scoreMusic = pygame.mixer.Sound("score.wav")
score = 0
conDic = {}
with open("record.txt" , "r" ,encoding="utf-8") as f:
content = f.read()
conDic = json.loads(content)
one = conDic["第1名"]
two = conDic["第2名"]
three = conDic["第3名"]
while True:
for event in pygame.event.get():
if event.type == locals.QUIT:
......@@ -126,6 +134,11 @@ while True:
sprite.score = 0
scoreSurf = basic_font.render("分数:"+str(score),True,(255,0,0))
screen.blit(scoreSurf,(850,20))
tag = 20
for k in conDic:
tag += 30
show = basic_font.render(k+str(conDic[k]),True,(255,0,0))
screen.blit(show,(850,tag))
if score > oldScore:
scoreMusic.play( )
......
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