Commit 076c766d by BellCodeEditor

save project

parent 802b6353
Showing with 44 additions and 15 deletions
......@@ -42,8 +42,8 @@ hero = [pygame.image.load('hero1.png'),
pygame.image.load('hero3.png'),
pygame.image.load('hero4.png'),
pygame.image.load('hero5.png')]
score_audio = pygame.mixer.Sound('score.wav')
basic_font = pygame.font.Font('STKAITI.TTV',18)
#score_audio = pygame.mixer.Sound('score.wav')
index = 0
y=400
......@@ -58,12 +58,12 @@ old_score=score
block_list=pygame.sprite.Group()
with open('score.txt','r',encoding='utf-8') as f:
with open('record.txt','r',encoding='utf-8') as f:
content=f.read()
record=json.loads(content)
one=content["第1名"]
two=content["第2名"]
thr=content["第3名"]
one=record["第1名"]
two=record["第2名"]
thr=record["第3名"]
while True:
for event in pygame.event.get():
......@@ -75,7 +75,7 @@ while True:
if event.key == locals.K_SPACE:
jumpState = "up"
speed=8 + score//3
speed = 8 + score//3
wukong = Player(hero[index])
if jumpState == "runing": # 跑步状态下
......@@ -106,7 +106,7 @@ while True:
bg_=0
screen.blit(background, (bg_x, 0))
# 远处背景
road_x-= speed
road_x -= speed
if road_x<-1000:
road_x=0
screen.blit(road, (road_x, 500))
......@@ -122,14 +122,43 @@ while True:
block_list.add(obstacle)
for sprite in block_list:
sprite.rect.x -= speed
#10.22ri
if aa.rect.x <= 0-aa.rect.width: # 障碍物消失
# 创建障碍物对象
aa=Block(bush,cacti,stone)
aa.rect.x -= 8
screen.blit(sprint.image,(sprite.rect.x,sprite.rect.y))
if sprite.rect.x <= 0 - sprite.rect.width:
sprite.kill()
if pygame.sprite.collide_rect(wukong,sprite):
gameover = pygame.image.load('gameover.png')
screen.blit(gameover,(400,200))
gamestate = False
if score>three:
if score>one:
record["第1名"]=score
record["第2名"]=one
record["第3名"]=two
elif score > two:
record["第2名"]=score
record["第3名"]=two
else:
record["第3名"]=score
record = json.dumps(record,ensure_ascii=False)
with open("record.txt","w",encoding='utf-8') as f:
f.write(record)
else:
if sprite.rect.x + sprite.rect.width < wukong.rect.x:
score += sprite.score
sprint.score = 0
if score > old_score:
score_audio.play()
old_score=score
scoreSurf = basic_font.render("分数:"+str(score),True,(255,255,255))
screen.blit(scoreSurf,(880,20))
scoreSurf = basic_font.render("第1名:"+str(one),True,(255,255,255))
screen.blit(scoreSurf,(880,50))
scoreSurf = basic_font.render("第2名:"+str(two),True,(255,255,255))
screen.blit(scoreSurf,(880,80))
scoreSurf = basic_font.render("第3名:"+str(three),True,(255,255,255))
screen.blit(scoreSurf,(880,110))
screen.blit(aa.image, (aa.rect.x, aa.rect.y))
# 刷新画面
pygame.display.update()
FPS.tick(60)
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