From f93f237a40fb0c110d8d5f86d7757da3abe3940b Mon Sep 17 00:00:00 2001 From: BellCodeEditor <bellcode_dev@bell.ai> Date: Mon, 4 Apr 2022 11:09:44 +0800 Subject: [PATCH] save project --- SourceHanSansCN-Normal.1def9981.ttf | Bin 0 -> 8173832 bytes my_game.py | 21 ++++++++++++++++----- sans.ttf | Bin 0 -> 133088 bytes score.wav | Bin 177486 -> 0 bytes 4 files changed, 16 insertions(+), 5 deletions(-) create mode 100644 SourceHanSansCN-Normal.1def9981.ttf create mode 100644 sans.ttf diff --git a/SourceHanSansCN-Normal.1def9981.ttf b/SourceHanSansCN-Normal.1def9981.ttf new file mode 100644 index 0000000..c6cc488 Binary files /dev/null and b/SourceHanSansCN-Normal.1def9981.ttf differ diff --git a/my_game.py b/my_game.py index bf23878..c4d1a04 100644 --- a/my_game.py +++ b/my_game.py @@ -14,6 +14,7 @@ class Block(pygame.sprite.Sprite): # 障碍物精灵类 # 障碍物绘制坐标 self.rect.x = 1000 self.rect.y = 500 - self.rect.height + self.score=1 class Player(pygame.sprite.Sprite): # 悟空 def __init__(self, image): @@ -40,7 +41,8 @@ hero = [pygame.image.load('hero1.png'), pygame.image.load('hero3.png'), pygame.image.load('hero4.png'), pygame.image.load('hero5.png')] -basic_font = pygame.font.Font('STKAITI.TTF',32) +basic_font = pygame.font.Font('SourceHanSansCN-Normal.1def9981.ttf',32) +scaud = pygame.mixer.Sound('score.wav') index = 0 y = 400 jumpState = "runing" @@ -49,7 +51,8 @@ road_x = 0 bg_x = 0 time = 0 gamestate = True - +score = 0 +oldc = 0 block_list =pygame.sprite.Group() # 创建精灵组 while True: @@ -62,6 +65,7 @@ while True: if event.key == locals.K_SPACE: jumpState = "up" + speed = 8 + score // 3 # 悟空造型 wukong = Player(hero[index]) if jumpState == "runing": # 跑步状态下 @@ -92,7 +96,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 +111,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() @@ -115,7 +119,14 @@ while True: gameover = pygame.image.load('gameover.png') # 游戏结束 screen.blit(gameover, (400, 200)) gamestate = False - scoreSurf = basic_font.render("分数:"+str(score),True,(255,0,0)) + else: + if (sprite.rect.x + sprite.rect.width) < wukong.rect.x: + score += sprite.score + sprite.score = 0 + if score > oldc: + scaud.play() + oldc = score + scoreSurf = basic_font.render("分数:"+str(score),True,(random.randint(0,255),random.randint(0,255),random.randint(0,255))) screen.blit(scoreSurf,(850,20)) # 刷新画面 diff --git a/sans.ttf b/sans.ttf new file mode 100644 index 0000000..09fac2f Binary files /dev/null and b/sans.ttf differ diff --git a/score.wav b/score.wav index 7f9b293..fc3b272 100644 Binary files a/score.wav and b/score.wav differ -- libgit2 0.25.0