Commit 37f41e7d by BellCodeEditor

save project

parent 91a78c00
Showing with 18 additions and 5 deletions
...@@ -18,6 +18,8 @@ hero = [pygame.image.load('hero1.png'), ...@@ -18,6 +18,8 @@ hero = [pygame.image.load('hero1.png'),
pygame.image.load('hero3.png'), pygame.image.load('hero3.png'),
pygame.image.load('hero4.png'), pygame.image.load('hero4.png'),
pygame.image.load('hero5.png')] pygame.image.load('hero5.png')]
ziti=pygame.font.Font("STKAITI.TTF",20)
deng=pygame.mixer.Sound("score.wav")
class Block(pygame.sprite.Sprite): class Block(pygame.sprite.Sprite):
def __init__(self,image1,image2,image3): def __init__(self,image1,image2,image3):
...@@ -46,6 +48,8 @@ bg_x = 0 ...@@ -46,6 +48,8 @@ bg_x = 0
time = 0 time = 0
start = True start = True
score=0 score=0
speed = 8
old = 0
while True: while True:
for event in pygame.event.get(): for event in pygame.event.get():
...@@ -79,13 +83,15 @@ while True: ...@@ -79,13 +83,15 @@ while True:
jumpState = "runing" jumpState = "runing"
t =30 t =30
speed = 8+score//3
# 悟空造型 # 悟空造型
# 将背景图画上去 # 将背景图画上去
bg_x -= 4 bg_x -= 4
if bg_x<=-1000: if bg_x<=-1000:
bg_x = 0 bg_x = 0
screen.blit(background, (bg_x, 0)) # 远处背景 screen.blit(background, (bg_x, 0)) # 远处背景
road_x -= 8 road_x -= speed
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)) # 路
...@@ -99,7 +105,7 @@ while True: ...@@ -99,7 +105,7 @@ while True:
obstacle = Block(bush,stone,cacti) obstacle = Block(bush,stone,cacti)
sprite_list.add(obstacle) sprite_list.add(obstacle)
for sprite in sprite_list: for sprite in sprite_list:
sprite.rect.x -= 8 sprite.rect.x -= speed
screen.blit(sprite.image,(sprite.rect.x,sprite.rect.y)) screen.blit(sprite.image,(sprite.rect.x,sprite.rect.y))
if sprite.rect.x<=0-sprite.rect.width: if sprite.rect.x<=0-sprite.rect.width:
sprite.kill() sprite.kill()
...@@ -111,7 +117,14 @@ while True: ...@@ -111,7 +117,14 @@ while True:
if sprite.rect.x+sprite.rect.width < wukong.rect.x: if sprite.rect.x+sprite.rect.width < wukong.rect.x:
score += sprite.score score += sprite.score
sprite.score = 0 sprite.score = 0
if old<score:
deng.play()
old = score
scoreziti = ziti.render("分數:"+str(score),True,(255,255,255))
screen.blit(scoreziti,(880,20))
# 刷新画面 # 刷新画面
pygame.display.update() pygame.display.update()
FPS.tick(60) FPS.tick(60)
\ No newline at end of file \ 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