Commit 63255ade by BellCodeEditor

save project

parent 9ae0b404
Showing with 10 additions and 4 deletions
......@@ -3,7 +3,7 @@ from pygame import locals
import random
speed = 8
pygame.init() # 初始化
score_music = pygame.music.sound('score.wav')
score_music = pygame.mixer.Sound('score.wav')
class Block(pygame.sprite.Sprite): # 障碍物精灵类
def __init__(self,image1,image2,image3):
super().__init__()#继承父类属性
......@@ -50,7 +50,7 @@ time = 0
gamestate = True
score = 0
block_list =pygame.sprite.Group() # 创建精灵组
old_score = 0
while True:
for event in pygame.event.get():
if event.type == locals.QUIT:# 接收到退出事件后退出程序
......@@ -100,11 +100,13 @@ while True:
time += 1
if time >= 60: # 每隔一秒创建障碍物精灵
time = 0
speed =speed +score //3
print(speed)
num = random.randint(0,50)
if num > 10:
obstacle = Block(bush,cacti,stone)
block_list.add(obstacle)
speed =speed +score//3
for sprite in block_list: # 遍历、展示障碍物精灵
sprite.rect.x -= speed #障碍物精灵向左移动(x坐标减小)
screen.blit(sprite.image, (sprite.rect.x, sprite.rect.y)) #渲染障碍物
......@@ -116,9 +118,13 @@ while True:
gamestate = False
else:
if sprite.rect.x+sprite.rect.width<wukong.rect.x:
score += sprite.score#加1分
sprite.score = 0
score_music.play()
if score>old_score:
score_music.play()
old_score = score
# 刷新画面
myfont = pygame.font.Font('STKAITI.TTF',15)#设置字体
info1 = myfont.render("分数:"+str(score),True,(0,0,0))#设置语句
......
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