Commit 5027204c by BellCodeEditor

save project

parent 2bd96689
Showing with 18 additions and 2 deletions
...@@ -22,6 +22,7 @@ class Block(pygame.sprite.Sprite): ...@@ -22,6 +22,7 @@ class Block(pygame.sprite.Sprite):
self.rect.x = 1000 self.rect.x = 1000
self.rect.y = 500 - self.rect.height self.rect.y = 500 - self.rect.height
self.score = 1 self.score = 1
self.success = 0
class WuKong(pygame.sprite.Sprite): class WuKong(pygame.sprite.Sprite):
def __init__(self,wukong_img): def __init__(self,wukong_img):
self.image = wukong_img self.image = wukong_img
...@@ -35,6 +36,10 @@ list_group = pygame.sprite.Group() ...@@ -35,6 +36,10 @@ list_group = pygame.sprite.Group()
# 逻辑:绘制图画时,不断切换悟空图片 # 逻辑:绘制图画时,不断切换悟空图片
hero = [pygame.image.load('hero1.png'),pygame.image.load('hero2.png'),pygame.image.load('hero3.png') hero = [pygame.image.load('hero1.png'),pygame.image.load('hero2.png'),pygame.image.load('hero3.png')
,pygame.image.load('hero4.png'),pygame.image.load('hero5.png')] #加载悟空图片 ,pygame.image.load('hero4.png'),pygame.image.load('hero5.png')] #加载悟空图片
score_bgm = pygame.mixer.Sound('score.wav')
index = 0 index = 0
jumpStatus = 'running' jumpStatus = 'running'
...@@ -48,6 +53,11 @@ score = 0 ...@@ -48,6 +53,11 @@ score = 0
gameState = 1 gameState = 1
speed = 8 #路和障碍物移动速度
time = 0 time = 0
while True: while True:
score_font = pygame.font.Font('STKAITI.TTF',30) score_font = pygame.font.Font('STKAITI.TTF',30)
...@@ -82,8 +92,10 @@ while True: ...@@ -82,8 +92,10 @@ while True:
if index == 5: if index == 5:
index = 0 index = 0
speed = 8 + score//3
background_x -= 5 background_x -= 5
road_x -= 8 road_x -= speed
# 将背景图画上去 # 将背景图画上去
screen.blit(background, (background_x, 0)) screen.blit(background, (background_x, 0))
screen.blit(road, (road_x, 500)) screen.blit(road, (road_x, 500))
...@@ -97,7 +109,7 @@ while True: ...@@ -97,7 +109,7 @@ while True:
obstacle = Block(stone,cacti,apple) obstacle = Block(stone,cacti,apple)
list_group.add(obstacle) list_group.add(obstacle)
for temp in list_group: for temp in list_group:
temp.rect.x -= 8 temp.rect.x -= speed
screen.blit(temp.image, (temp.rect.x, temp.rect.y)) screen.blit(temp.image, (temp.rect.x, temp.rect.y))
if(pygame.sprite.collide_rect(wukong,temp)): if(pygame.sprite.collide_rect(wukong,temp)):
screen.blit(gameover, (350, 200)) screen.blit(gameover, (350, 200))
...@@ -107,6 +119,9 @@ while True: ...@@ -107,6 +119,9 @@ while True:
if temp.rect.x + temp.rect.width < wukong.rect.x: if temp.rect.x + temp.rect.width < wukong.rect.x:
score += temp.score score += temp.score
temp.score = 0 temp.score = 0
if temp.success == 0:
score_bgm.play()
temp.success = 1
# 刷新画面 # 刷新画面
pygame.display.update() pygame.display.update()
FPS.tick(60) 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