Commit 58cfbd11 by BellCodeEditor

save project

parent f0333353
Showing with 15 additions and 3 deletions
...@@ -14,6 +14,7 @@ class Block(pygame.sprite.Sprite): ...@@ -14,6 +14,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.sco=1
class Player(pygame.sprite.Sprite): class Player(pygame.sprite.Sprite):
def __init__(self,image): def __init__(self,image):
super().__init__() super().__init__()
...@@ -39,6 +40,8 @@ hero = [pygame.image.load('hero1.png'), ...@@ -39,6 +40,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')]
score_audio=pygame.mixer.Sound('score.wav')
basic_font=pygame.font.Font('STKAITI.TTF',18)
index = 0 index = 0
y = 400 y = 400
jumpState = "runing" jumpState = "runing"
...@@ -47,6 +50,8 @@ time=0 ...@@ -47,6 +50,8 @@ time=0
bg_x = 0 bg_x = 0
road_x = 0 road_x = 0
a=True a=True
score=0
block_list=pygame.sprite.Group() block_list=pygame.sprite.Group()
# 创建障碍物 # 创建障碍物
#obstacle = Block(bush,cacti,stone) #obstacle = Block(bush,cacti,stone)
...@@ -98,19 +103,25 @@ while True: ...@@ -98,19 +103,25 @@ while True:
if time>=60: if time>=60:
time=0 time=0
num=random.randint(0,100) num=random.randint(0,100)
if num >40: if num >20:
obstacle=Block(bush,cacti,stone) obstacle=Block(bush,cacti,stone)
block_list.add(obstacle) block_list.add(obstacle)
for sprite in block_list: for sprite in block_list:
sprite.rect.x -=8 sprite.rect.x -=8
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()
if pygame.sprite.collide_rect(wukong,sprite): if pygame.sprite.collide_rect(wukong,sprite):
gameover=pygame.image.load('gameover.png') gameover=pygame.image.load('gameover.png')
screen.blit(gameover,(400,200)) screen.blit(gameover,(400,200))
a=False a=False
else:
if sprite.rect.x+sprite.rect.width<wukong.rect.x:
score + = sprite.score
sprite.score=0
# print(score)
scoreSurf=basic_foot.render("番薯:"+str(score),True,(255,255,255))
score.blit(scoreSurf,(880,90))
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