Commit e599c725 by BellCodeEditor

save project

parent 9a51a33f
Showing with 22 additions and 3 deletions
......@@ -11,6 +11,7 @@ class Block(pygame.sprite.Sprite):
self.rect=self.image.get_rect()
self.rect.x=1000
self.rect.y=500-self.rect.height
self.score=1
# 创建一个窗口
class Player(pygame.sprite.Sprite):
def __init__(self,image):
......@@ -19,13 +20,14 @@ class Player(pygame.sprite.Sprite):
self.rect=self.image.get_rect()
self.rect.x=150
self.rect.y=400
self.rect.width=40
# 创建一个窗口
self.rect.width=1
# 创建一个窗口
screen = pygame.display.set_mode((1000, 600))
FPS = pygame.time.Clock() # pygame时钟,控制游戏速度(帧数)
pygame.display.set_caption("智障跑酷")
# 载入图片
background = pygame.image.load('bg.png') # 背景
road = pygame.image.load('road.png') # 路
stone = pygame.image.load('stone.png') # 石头
......@@ -36,10 +38,13 @@ hero = [pygame.image.load('hero1.png'),
pygame.image.load('hero3.png'),
pygame.image.load('hero4.png'),
pygame.image.load('hero5.png')]
basic_font=pygame.font.Font('STKAITI.TTF',18)
score_audio=pygame.mixer.Sound("score.wav")
index = 0
y = 400
jumpState = "runing"
t = 30
score=0
Block_list=pygame.sprite.Group()
......@@ -47,6 +52,8 @@ gt=True
road_x=0
bg_x=0
time=0
speed=8
old_score=0
while True:
for event in pygame.event.get():
if event.type == locals.QUIT:
......@@ -56,6 +63,7 @@ while True:
if jumpState == "runing":
if event.key == locals.K_SPACE:
jumpState = "up"
speed=8+score//3
# 悟空造型
wukong = Player(hero[index])
if jumpState == "runing": # 跑步状态下
......@@ -105,7 +113,7 @@ while True:
obstacle =Block(bush,stone,cacti)
Block_list.add(obstacle)
for prop in Block_list:
prop.rect.x-=8
prop.rect.x-=speed
screen.blit(prop.image, (prop.rect.x,prop.rect.y))
if prop.rect.x<0-prop.rect.width:
prop.kill()
......@@ -113,6 +121,16 @@ while True:
go=pygame.image.load("gameover.png")
screen.blit(go,(400,200))
gt=False
else:
if (prop.rect.x+prop.rect.width)<wukong.rect.x:
score+=prop.score
prop.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))
# 刷新画面
pygame.display.update()
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