Commit 58287e0a by BellCodeEditor

save project

parent f4eee22a
Showing with 23 additions and 6 deletions
......@@ -8,6 +8,7 @@ class Bob(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):
super().__init__()
......@@ -31,15 +32,21 @@ 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")
index = 0
y = 400
jumpState = "runing"
t = 30
t = 36
road_x = 0
bj_x = 0
obstacle_list = pygame.sprite.Group()
time = 0
gamestate = True
score = 0
basic_font = pygame.font.Font('STKAITI.TTF',20)
speed = 8
old_score = 0
while True:
for event in pygame.event.get():
if event.type == locals.QUIT:
......@@ -49,7 +56,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": # 跑步状态下
......@@ -65,20 +72,20 @@ while True:
else:
jumpState = "down"
if jumpState == "down": # 降落状态
if t <= 30:
if t <= 36:
y += t
wukong.rect.y = y
t += 2
else:
jumpState = "runing"
t =30
t = 36
# 将背景图画上去
bj_x -= 3
if bj_x <= -1000:
bj_x = 0
screen.blit(background, (bj_x, 0)) # 远处背景
road_x -= 8
road_x -= speed
if road_x <= -1000: # 路
road_x = 0
screen.blit(road , (road_x, 500))
......@@ -92,7 +99,7 @@ while True:
time = 0
for i in obstacle_list:
i.rect.x -= 8
i.rect.x -= speed
screen.blit(i.image,(i.rect.x, i.rect.y))
if i.rect.x < 0 - i.rect.width:
i.kill()
......@@ -100,6 +107,15 @@ while True:
gameover = pygame.image.load("gameover.png")
screen.blit(gameover,(400,200))
gamestate = False
else:
if i.rect.x + i.rect.width < wukong.rect.x:
score += i.score
i.score = 0
if score > old_score:
score_audio.play()
old_score = score
scoreSurf = basic_font.render("分数:"+str(score),True,(255,0,0))
screen.blit(scoreSurf,(850,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