Commit 622c39eb by BellCodeEditor

save project

parent 2efe68b4
Showing with 41 additions and 13 deletions
File added
import pygame
import random
from pygame import locals
import json
class Block(pygame.sprite.Sprite):
def __init__(self,image1,image2,image3):
......@@ -9,6 +10,7 @@ class Block(pygame.sprite.Sprite):
self.rect=self.image.get_rect()
self.rect.x=1000
self.rect.y=500-self.rect.height
self.sceor= 1
class Player(pygame.sprite.Sprite):
def __init__(self,image):
......@@ -34,22 +36,33 @@ hero =[pygame.image.load('hero1.png'),
pygame.image.load('hero3.png'),
pygame.image.load('hero4.png'),
pygame.image.load('hero5.png')]
b=pygame.font.Font('STKAITI.TTF',18)
a=pygame.mixer.Sound('score.wav')
index = 0
jf=0
old_sceor=0
sceor=0
gamestat=True
speed=8
road_x=0
time=0
background_x=0
t=35
t=36
jumpstat='running'
y=400
obstacle=Block(stone,apple,cacti)
Block_list=pygame.sprite.Group()
with open('record.txt','r',encoding='utf-8') as f:
content=f.read()
recoud=json.loads(content)
one=recoud['第1名']
two=recoud['第2名']
three=recoud['第3名']
while True:
speed=8+sceor//3
wukong=Player(hero[index])
if jumpstat == 'running':
index+=1
......@@ -65,7 +78,7 @@ while True:
exit()
if gamestat==True:
road_x-=8
road_x-=speed
if road_x<=-1000:#小路移动
road_x=0
......@@ -81,13 +94,13 @@ while True:
jumpstat='jumpdown'
if jumpstat=='jumpdown':
if t<=35:
if t<=36:
y+=t
wukong.rect.y=y
t+=2
else:
jumpstat='running'
t=35
t=36
# 将背景图画上去
screen.blit(background, (background_x, 0))
......@@ -103,7 +116,7 @@ while True:
Block_list.add(obstacle)
for sprite in Block_list:
sprite.rect.x-=8
sprite.rect.x-=speed
screen.blit(sprite.image,(sprite.rect.x,sprite.rect.y))
if sprite.rect.x<0-sprite.rect.width:
sprite.kill()
......@@ -112,9 +125,24 @@ while True:
screen.blit(gameover,(400,150))
gamestat=False
else:
if
screen.blit(obstacle.image,(obstacle.rect.x,obstacle.rect.y))
if sprite.rect.x+sprite.rect.width<wukong.rect.x:
sceor+=sprite.sceor
sprite.sceor=0
old_sceor=sceor
if sceor>old_sceor:
a.Play()
old_sceor=sceor
score=b.render('分数'+str(sceor),True,(0,0,0))
screen.blit(score,(880,20))
score1=b.render('第一名'+str(one),True,(0,0,0))
score2=b.render('第二名'+str(two),True,(0,0,0))
score3=b.render('第三名'+str(three),True,(0,0,0))
screen.blit(score1,(880,40))
screen.blit(score2,(880,60))
screen.blit(score3,(880,80))
# 刷新画面
pygame.display.update()
FPS.tick(60)
\ No newline at end of file
FPS.tick(90)
\ 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