Commit 898443ff by BellCodeEditor

save project

parent 710eb662
Showing with 17 additions and 6 deletions
import pygame
from pygame import locals
import random
import json
pygame.init() # 初始化
class Block(pygame.sprite.Sprite): # 障碍物精灵类
......@@ -25,7 +25,12 @@ class Player(pygame.sprite.Sprite): # 悟空
self.rect = self.image.get_rect()
self.rect.x = 150
self.rect.y = 400
with open('record.txt','r',encoding='utf-8') as f:
content=f.read()
record=json.loads(content)
one=record["第1名"]
two=record["第2名"]
thr=record["第3名"]
# 创建一个窗口
screen = pygame.display.set_mode((1000, 600))
FPS = pygame.time.Clock() # pygame时钟,控制游戏速度(帧数)
......@@ -52,7 +57,7 @@ bg_x = 0
time = 0
gamestate = True
score=0
old_score=0
old_score=0
block_list =pygame.sprite.Group() # 创建精灵组
while True:
......@@ -81,13 +86,13 @@ while True:
else:
jumpState = "down"
if jumpState == "down": # 降落状态
if t <= 30:
if t <= 40:
y += t
wukong.rect.y = y
t += 2
else:
jumpState = "runing"
t =30
t =40
# 将背景图画上去
bg_x -= 1
......@@ -127,7 +132,12 @@ while True:
old_score=score
scoreSurf = basic_font.render("分数:"+str(score),True,(255,0,0))
screen.blit(scoreSurf,(850,20))
scoreSurf = basic_font.render("第1名:"+str(one),True,(255,0,0))
screen.blit(scoreSurf,(850,50))
scoreSurf = basic_font.render("第2名:"+str(two),True,(255,0,0))
screen.blit(scoreSurf,(850,80))
scoreSurf = basic_font.render("第3名:"+str(thr),True,(255,0,0))
screen.blit(scoreSurf,(850,110))
# 刷新画面
pygame.display.update()
FPS.tick(60)
\ 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