Commit 52c68a72 by BellCodeEditor

save project

parent 8337023a
Showing with 17 additions and 4 deletions
import pygame import pygame
from pygame import locals from pygame import locals
import random import random
import json
pygame.init() # 初始化 pygame.init() # 初始化
...@@ -27,6 +28,12 @@ class Player(pygame.sprite.Sprite): # 悟空 ...@@ -27,6 +28,12 @@ class Player(pygame.sprite.Sprite): # 悟空
self.rect.y = 400 self.rect.y = 400
# 创建一个窗口 # 创建一个窗口
with open('record.txt','r',encoding='utf-8') as f:
cen = f.read()
record = json.loads(cen)
one = record["第1名"]
two = record["第2名"]
three= record["第3名"]
screen = pygame.display.set_mode((1000, 600)) screen = pygame.display.set_mode((1000, 600))
FPS = pygame.time.Clock() # pygame时钟,控制游戏速度(帧数) FPS = pygame.time.Clock() # pygame时钟,控制游戏速度(帧数)
pygame.display.set_caption("悟空酷跑") pygame.display.set_caption("悟空酷跑")
...@@ -67,8 +74,8 @@ while True: ...@@ -67,8 +74,8 @@ while True:
if jumpState == "runing": if jumpState == "runing":
if event.key == locals.K_SPACE: if event.key == locals.K_SPACE:
jumpState = "up" jumpState = "up"
if event.key == locals.K_D: # if event.key == locals.K_D:
die = not die # die = not die
# 悟空造型 # 悟空造型
wukong = Player(hero[index]) wukong = Player(hero[index])
...@@ -124,7 +131,7 @@ while True: ...@@ -124,7 +131,7 @@ while True:
gameover = pygame.image.load('gameover.png') # 游戏结束 gameover = pygame.image.load('gameover.png') # 游戏结束
screen.blit(gameover, (400, 200)) screen.blit(gameover, (400, 200))
if die : if die :
gamestate = False gamestate = False
else: else:
if sprite.rect.x+sprite.rect.width<wukong.rect.x: if sprite.rect.x+sprite.rect.width<wukong.rect.x:
score += sprite.score score += sprite.score
...@@ -134,8 +141,14 @@ while True: ...@@ -134,8 +141,14 @@ while True:
scoresy.play() scoresy.play()
old_score = score old_score = score
scoreSurf = basic_font.render("分数:"+str(score),True,(255,0,0)) scoreSurf = basic_font.render("分数:"+str(score),True,(255,0,0))
dieXX = basic_font.render("是否死亡"+str(die),True,(255,0,0))
screen.blit(scoreSurf,(850,20)) screen.blit(scoreSurf,(850,20))
# dieXX = basic_font.render("是否死亡"+str(die),True,(255,0,0))
scoreSurf = basic_font.render("第一名:"+str(one),True,(255,0,0))
screen.blit(scoreSurf,(850,40))
scoreSurf = basic_font.render("第二名:"+str(one),True,(255,0,0))
screen.blit(scoreSurf,(850,60))
scoreSurf = basic_font.render("第三名:"+str(one),True,(255,0,0))
screen.blit(scoreSurf,(850,80))
# 刷新画面 # 刷新画面
pygame.display.update() pygame.display.update()
......
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