Commit 46ce0fb9 by BellCodeEditor

save project

parent 3bb2e58c
Showing with 12 additions and 2 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')]
basic_font = pygame.font.Font('STKAITI.TTF', 18)
score=0
index = 0
y = 400
jumpState = "runing"
......@@ -73,14 +76,14 @@ while True:
if t > 0:
y -= t
wukong.rect.y = y
t -= 2
t -= 1.75
else:
jumpState = "down"
if jumpState == "down": # 降落状态
if t <= 30:
y += t
wukong.rect.y = y
t += 2
t += 1.75
else:
jumpState = "runing"
t =30
......@@ -114,6 +117,13 @@ while True:
gameover = pygame.image.load('gameover.png') # 游戏结束
screen.blit(gameover, (400, 200))
gamestate = False
else:
if (sprite.rect.x + sprite.rect.width) < wukong.rect.x:
score += sprite.score
sprite.score = 0
scoreSurf = basic_font.render("分数:"+str(score), True, (255, 255, 255))
screen.blit(scoreSurf, (880,20))
# 刷新画面
pygame.display.update()
......
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