Commit 40ab8c44 by BellCodeEditor

save project

parent 3bb2e58c
Showing with 15 additions and 5 deletions
......@@ -7,6 +7,7 @@ pygame.init() # 初始化
class Block(pygame.sprite.Sprite): # 障碍物精灵类
def __init__(self,image1,image2,image3):
super().__init__()
self.score = 1
# 加载障碍物的图片
self.image = random.choice([image1, image2, image3])
# 根据障碍物位图的宽高设置矩形
......@@ -40,6 +41,8 @@ hero = [pygame.image.load('hero1.png'),
pygame.image.load('hero3.png'),
pygame.image.load('hero4.png'),
pygame.image.load('hero5.png')]
sc = pygame.font.Font("STKAITI.TTF",10)
content = sc.render("Score:0",True,(255,255,255))
index = 0
y = 400
jumpState = "runing"
......@@ -48,6 +51,8 @@ road_x = 0
bg_x = 0
time = 0
gamestate = True
score = 0
speed =16
block_list =pygame.sprite.Group() # 创建精灵组
......@@ -91,22 +96,22 @@ 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)) # 道路
screen.blit(wukong.image, (150, y)) # 悟空
speed*=1.1
time += 1
if time >= 60: # 创建障碍物精灵
time = 0
num = random.randint(0,50)
if num > 20:
if num > 10:
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()
......@@ -114,7 +119,11 @@ while True:
gameover = pygame.image.load('gameover.png') # 游戏结束
screen.blit(gameover, (400, 200))
gamestate = False
if sprite.rect.x < wukong.rect.x:
score += sprite.score
sprite.score=0
content = sc.render("Score:"+str(score),True,(255,255,255))
screen.blit(content, (150, y))
# 刷新画面
pygame.display.update()
FPS.tick(60)
\ 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