Commit 076c766d by BellCodeEditor

save project

parent 802b6353
Showing with 46 additions and 18 deletions
...@@ -42,8 +42,8 @@ hero = [pygame.image.load('hero1.png'), ...@@ -42,8 +42,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') #score_audio = pygame.mixer.Sound('score.wav')
basic_font = pygame.font.Font('STKAITI.TTV',18)
index = 0 index = 0
y=400 y=400
...@@ -58,12 +58,12 @@ old_score=score ...@@ -58,12 +58,12 @@ old_score=score
block_list=pygame.sprite.Group() 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() content=f.read()
record=json.loads(content) record=json.loads(content)
one=content["第1名"] one=record["第1名"]
two=content["第2名"] two=record["第2名"]
thr=content["第3名"] thr=record["第3名"]
while True: while True:
for event in pygame.event.get(): for event in pygame.event.get():
...@@ -75,7 +75,7 @@ while True: ...@@ -75,7 +75,7 @@ while True:
if event.key == locals.K_SPACE: if event.key == locals.K_SPACE:
jumpState = "up" jumpState = "up"
speed=8 + score//3 speed = 8 + score//3
wukong = Player(hero[index]) wukong = Player(hero[index])
if jumpState == "runing": # 跑步状态下 if jumpState == "runing": # 跑步状态下
...@@ -106,7 +106,7 @@ while True: ...@@ -106,7 +106,7 @@ while True:
bg_=0 bg_=0
screen.blit(background, (bg_x, 0)) screen.blit(background, (bg_x, 0))
# 远处背景 # 远处背景
road_x-= speed 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))
...@@ -122,14 +122,43 @@ while True: ...@@ -122,14 +122,43 @@ while True:
block_list.add(obstacle) block_list.add(obstacle)
for sprite in block_list: for sprite in block_list:
sprite.rect.x -= speed sprite.rect.x -= speed
#10.22ri screen.blit(sprint.image,(sprite.rect.x,sprite.rect.y))
if aa.rect.x <= 0-aa.rect.width: # 障碍物消失 if sprite.rect.x <= 0 - sprite.rect.width:
# 创建障碍物对象 sprite.kill()
aa=Block(bush,cacti,stone) if pygame.sprite.collide_rect(wukong,sprite):
aa.rect.x -= 8 gameover = pygame.image.load('gameover.png')
screen.blit(gameover,(400,200))
gamestate = False
screen.blit(aa.image, (aa.rect.x, aa.rect.y)) 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))
# 刷新画面 # 刷新画面
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