Skip to content
  • P
    Projects
  • G
    Groups
  • S
    Snippets
  • Help

Administrator / pygame_lesson9_diy1

  • This project
    • Loading...
  • Sign in
Go to a project
  • Project
  • Repository
  • Issues 0
  • Merge Requests 0
  • Pipelines
  • Wiki
  • Snippets
  • Members
  • Activity
  • Graph
  • Charts
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
  • Files
  • Commits
  • Branches
  • Tags
  • Contributors
  • Graph
  • Compare
  • Charts
Commit 52c68a72 authored 3 years ago by BellCodeEditor's avatar BellCodeEditor
Browse files
Options
  • Browse Files
  • Download
  • Email Patches
  • Plain Diff

save project

parent 8337023a
Show whitespace changes
Inline Side-by-side
Showing with 16 additions and 3 deletions
  • my_game.py
my_game.py
View file @ 52c68a72
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])
...@@ -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()
......
This diff is collapsed. Click to expand it.
  • Write
  • Preview
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