Commit 0df98701 by BellCodeEditor

save project

parent 3c679eea
Showing with 26 additions and 10 deletions
import pygame
from pygame import locals
import random
import json
pygame.init() # 初始化
class Block(pygame.sprite.Sprite): # 障碍物精灵类
......@@ -28,7 +28,7 @@ class Player(pygame.sprite.Sprite): # 悟空
# 创建一个窗口
screen = pygame.display.set_mode((1000, 600))
FPS = pygame.time.Clock() # pygame时钟,控制游戏速度(帧数)
pygame.display.set_caption("悟空酷跑")
pygame.display.set_caption("SB酷跑")
# 载入图片
background = pygame.image.load('bg.png') # 背景
road = pygame.image.load('road.png') # 路
......@@ -50,8 +50,15 @@ bg_x = 0
time = 0
gamestate = True
score=0
score_old=0
block_list =pygame.sprite.Group() # 创建精灵组
speed=9.9999999999999999999999999999999999999999999999999999999999999999999999999999
with open('record.txt','r',encoding='utf-8') as f:
ab=f.read()
cd=json.loads(ab)
one=cd["第1名"]
two=cd["第2名"]
three=cd["第3名"]
while True:
for event in pygame.event.get():
if event.type == locals.QUIT:
......@@ -61,7 +68,7 @@ while True:
if jumpState == "runing":
if event.key == locals.K_SPACE:
jumpState = "up"
speed=9.9999999999999999999999999999999999999999999999999999999999999999999999999999+score//3
# 悟空造型
wukong = Player(hero[index])
if jumpState == "runing": # 跑步状态下
......@@ -92,7 +99,7 @@ while True:
bg_x = 0
screen.blit(background, (bg_x, 0)) # 远景
road_x -= 8
road_x -= speed
if road_x<=-1000:
road_x = 0
screen.blit(road, (road_x, 500)) # 道路
......@@ -107,7 +114,7 @@ while True:
obstacle = Block(bush,cacti,stone)
block_list.add(obstacle)
for sprite in block_list: # 遍历、展示障碍物精灵
sprite.rect.x -= 8
sprite.rect.x -= speed
screen.blit(sprite.image, (sprite.rect.x, sprite.rect.y))
if sprite.rect.x <= 0-sprite.rect.width:
sprite.kill()
......@@ -119,9 +126,17 @@ while True:
score+=sprite.score
sprite.score=0
print(score)
# scoreSurf = basic_font.render("分数:"+str(score),True,(255,0,0))
if score_old<score:
score_audio.play()
score_old=score
# scoreSurf = basic_font.render("分数:"+str(score),True,(255,255,255))
# screen.blit(scoreSurf,(850,20))
# scoreSurf = basic_font.render("第1名:"+str(one),True,(255,255,255))
# screen.blit(scoreSurf,(850,50))
# scoreSurf = basic_font.render("第2名:"+str(two),True,(255,255,255))
# screen.blit(scoreSurf,(850,80))
# scoreSurf = basic_font.render("第3名:"+str(three),True,(255,255,255))
screen.blit(scoreSurf,(850,110))
# 刷新画面
pygame.display.update()
FPS.tick(60)
\ No newline at end of file
{"第1名": 0, "第2名": 0, "第3名": 0}
\ No newline at end of file
{"第1名": 4613, "第2名": 1314, "第3名": 520}
\ 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