Commit 9ae0b404 by BellCodeEditor

auto save

parent 2117de2f
Showing with 7 additions and 5 deletions
import pygame import pygame
from pygame import locals from pygame import locals
import random import random
speed = 8
pygame.init() # 初始化 pygame.init() # 初始化
score = 0 score_music = pygame.music.sound('score.wav')
class Block(pygame.sprite.Sprite): # 障碍物精灵类 class Block(pygame.sprite.Sprite): # 障碍物精灵类
def __init__(self,image1,image2,image3): def __init__(self,image1,image2,image3):
super().__init__()#继承父类属性 super().__init__()#继承父类属性
...@@ -48,7 +48,7 @@ road_x = 0 ...@@ -48,7 +48,7 @@ road_x = 0
bg_x = 0 bg_x = 0
time = 0 time = 0
gamestate = True gamestate = True
score = 0
block_list =pygame.sprite.Group() # 创建精灵组 block_list =pygame.sprite.Group() # 创建精灵组
while True: while True:
...@@ -104,8 +104,9 @@ while True: ...@@ -104,8 +104,9 @@ while True:
if num > 10: if num > 10:
obstacle = Block(bush,cacti,stone) obstacle = Block(bush,cacti,stone)
block_list.add(obstacle) block_list.add(obstacle)
speed =speed +score//3
for sprite in block_list: # 遍历、展示障碍物精灵 for sprite in block_list: # 遍历、展示障碍物精灵
sprite.rect.x -= 8 #障碍物精灵向左移动(x坐标减小) sprite.rect.x -= speed #障碍物精灵向左移动(x坐标减小)
screen.blit(sprite.image, (sprite.rect.x, sprite.rect.y)) #渲染障碍物 screen.blit(sprite.image, (sprite.rect.x, sprite.rect.y)) #渲染障碍物
if sprite.rect.x <= 0-sprite.rect.width: if sprite.rect.x <= 0-sprite.rect.width:
sprite.kill()#删除精灵 sprite.kill()#删除精灵
...@@ -115,8 +116,9 @@ while True: ...@@ -115,8 +116,9 @@ while True:
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#加1分
sprite.score = 0 sprite.score = 0
score_music.play()
# 刷新画面 # 刷新画面
myfont = pygame.font.Font('STKAITI.TTF',15)#设置字体 myfont = pygame.font.Font('STKAITI.TTF',15)#设置字体
info1 = myfont.render("分数:"+str(score),True,(0,0,0))#设置语句 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