Commit 58287e0a by BellCodeEditor

save project

parent f4eee22a
Showing with 23 additions and 6 deletions
...@@ -8,6 +8,7 @@ class Bob(pygame.sprite.Sprite): ...@@ -8,6 +8,7 @@ class Bob(pygame.sprite.Sprite):
self.rect = self.image.get_rect() self.rect = self.image.get_rect()
self.rect.x = 1000 self.rect.x = 1000
self.rect.y = 500 - self.rect.height self.rect.y = 500 - self.rect.height
self.score = 1
class Player(pygame.sprite.Sprite): class Player(pygame.sprite.Sprite):
def __init__(self,image): def __init__(self,image):
super().__init__() super().__init__()
...@@ -31,15 +32,21 @@ hero = [pygame.image.load('hero1.png'), ...@@ -31,15 +32,21 @@ 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")
index = 0 index = 0
y = 400 y = 400
jumpState = "runing" jumpState = "runing"
t = 30 t = 36
road_x = 0 road_x = 0
bj_x = 0 bj_x = 0
obstacle_list = pygame.sprite.Group() obstacle_list = pygame.sprite.Group()
time = 0 time = 0
gamestate = True gamestate = True
score = 0
basic_font = pygame.font.Font('STKAITI.TTF',20)
speed = 8
old_score = 0
while True: while True:
for event in pygame.event.get(): for event in pygame.event.get():
if event.type == locals.QUIT: if event.type == locals.QUIT:
...@@ -49,7 +56,7 @@ while True: ...@@ -49,7 +56,7 @@ while True:
if jumpState == "runing": if jumpState == "runing":
if event.key == locals.K_SPACE: if event.key == locals.K_SPACE:
jumpState = "up" jumpState = "up"
speed = 8 + (score//3)
# 悟空造型 # 悟空造型
wukong =Player(hero[index]) wukong =Player(hero[index])
if jumpState == "runing": # 跑步状态下 if jumpState == "runing": # 跑步状态下
...@@ -65,20 +72,20 @@ while True: ...@@ -65,20 +72,20 @@ while True:
else: else:
jumpState = "down" jumpState = "down"
if jumpState == "down": # 降落状态 if jumpState == "down": # 降落状态
if t <= 30: if t <= 36:
y += t y += t
wukong.rect.y = y wukong.rect.y = y
t += 2 t += 2
else: else:
jumpState = "runing" jumpState = "runing"
t =30 t = 36
# 将背景图画上去 # 将背景图画上去
bj_x -= 3 bj_x -= 3
if bj_x <= -1000: if bj_x <= -1000:
bj_x = 0 bj_x = 0
screen.blit(background, (bj_x, 0)) # 远处背景 screen.blit(background, (bj_x, 0)) # 远处背景
road_x -= 8 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))
...@@ -92,7 +99,7 @@ while True: ...@@ -92,7 +99,7 @@ while True:
time = 0 time = 0
for i in obstacle_list: for i in obstacle_list:
i.rect.x -= 8 i.rect.x -= speed
screen.blit(i.image,(i.rect.x, i.rect.y)) screen.blit(i.image,(i.rect.x, i.rect.y))
if i.rect.x < 0 - i.rect.width: if i.rect.x < 0 - i.rect.width:
i.kill() i.kill()
...@@ -100,6 +107,15 @@ while True: ...@@ -100,6 +107,15 @@ while True:
gameover = pygame.image.load("gameover.png") gameover = pygame.image.load("gameover.png")
screen.blit(gameover,(400,200)) screen.blit(gameover,(400,200))
gamestate = False 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() 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