Commit ede7d8e4 by BellCodeEditor

auto save

parent 3bb2e58c
Showing with 21 additions and 11 deletions
...@@ -9,6 +9,7 @@ class Block(pygame.sprite.Sprite): # 障碍物精灵类 ...@@ -9,6 +9,7 @@ class Block(pygame.sprite.Sprite): # 障碍物精灵类
super().__init__() super().__init__()
# 加载障碍物的图片 # 加载障碍物的图片
self.image = random.choice([image1, image2, image3]) self.image = random.choice([image1, image2, image3])
self.score = 20
# 根据障碍物位图的宽高设置矩形 # 根据障碍物位图的宽高设置矩形
self.rect = self.image.get_rect() self.rect = self.image.get_rect()
# 障碍物绘制坐标 # 障碍物绘制坐标
...@@ -42,28 +43,30 @@ hero = [pygame.image.load('hero1.png'), ...@@ -42,28 +43,30 @@ hero = [pygame.image.load('hero1.png'),
pygame.image.load('hero5.png')] pygame.image.load('hero5.png')]
index = 0 index = 0
y = 400 y = 400
jumpState = "runing" jumpState = "running"
t = 30 t = 30
road_x = 0 road_x = 0
bg_x = 0 background_x = 0
time = 0 time = 0
score = 0
gamestate = True gamestate = True
block_list =pygame.sprite.Group() # 创建精灵组 block_list =pygame.sprite.Group() # 创建精灵组
basic_font = pygame.font.Font('STKAITI.TTF',13)
while True: while True:
for event in pygame.event.get(): for event in pygame.event.get():
if event.type == locals.QUIT: if event.type == locals.QUIT:
# 接收到退出事件后退出程序 # 接收到退出事件后退出程序
exit() exit()
if event.type == locals.KEYDOWN: if event.type == locals.KEYDOWN:
if jumpState == "runing": if jumpState == "running":
if event.key == locals.K_SPACE: if event.key == locals.K_SPACE:
jumpState = "up" jumpState = "up"
# 悟空造型 # 悟空造型
wukong = Player(hero[index]) wukong = Player(hero[index])
if jumpState == "runing": # 跑步状态下 if jumpState == "running": # 跑步状态下
index += 1 index += 1
if index >= 5: if index >= 5:
index = 0 index = 0
...@@ -82,21 +85,21 @@ while True: ...@@ -82,21 +85,21 @@ while True:
wukong.rect.y = y wukong.rect.y = y
t += 2 t += 2
else: else:
jumpState = "runing" jumpState = "running"
t =30 t =30
# 将背景图画上去 # 将背景图画上去
bg_x -= 1 background_x -= 1
if bg_x<=-1000: if background_x<=-1000:
bg_x = 0 background_x = 0
screen.blit(background, (bg_x, 0)) # 远景 screen.blit(background,(background_x, 0)) # 远景
road_x -= 8 road_x -= 8
if road_x<=-1000: if road_x<=-1000:
road_x = 0 road_x = 0
screen.blit(road, (road_x, 500)) # 道路 screen.blit(road,(road_x, 500)) # 道路
screen.blit(wukong.image, (150, y)) # 悟空 screen.blit(wukong.image,(150, y)) # 悟空
time += 1 time += 1
if time >= 60: # 创建障碍物精灵 if time >= 60: # 创建障碍物精灵
...@@ -114,6 +117,13 @@ while True: ...@@ -114,6 +117,13 @@ while True:
gameover = pygame.image.load('gameover.png') # 游戏结束 gameover = pygame.image.load('gameover.png') # 游戏结束
screen.blit(gameover, (400, 200)) screen.blit(gameover, (400, 200))
gamestate = False 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() 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