Commit 6aeecaf9 by BellCodeEditor

save project

parent 351f4967
File added
File added
...@@ -14,7 +14,7 @@ class Block(pygame.sprite.Sprite): # 障碍物精灵类 ...@@ -14,7 +14,7 @@ class Block(pygame.sprite.Sprite): # 障碍物精灵类
# 障碍物绘制坐标 # 障碍物绘制坐标
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__()
...@@ -30,8 +30,8 @@ screen = pygame.display.set_mode((1000, 600)) ...@@ -30,8 +30,8 @@ screen = pygame.display.set_mode((1000, 600))
FPS = pygame.time.Clock() # pygame时钟,控制游戏速度(帧数) FPS = pygame.time.Clock() # pygame时钟,控制游戏速度(帧数)
pygame.display.set_caption("悟空酷跑") pygame.display.set_caption("悟空酷跑")
# 载入图片 # 载入图片
background = pygame.image.load('bg.png') # 背景 background = pygame.image.load('IKUN.webp') # 背景
road = pygame.image.load('road.png') # 路 road = pygame.image.load('kunkun.webp') # 路
stone = pygame.image.load('stone.png') # 石头 stone = pygame.image.load('stone.png') # 石头
cacti = pygame.image.load('cacti.png') # 仙人掌 cacti = pygame.image.load('cacti.png') # 仙人掌
bush = pygame.image.load('bush.png') # 灌木丛 bush = pygame.image.load('bush.png') # 灌木丛
...@@ -40,7 +40,8 @@ hero = [pygame.image.load('hero1.png'), ...@@ -40,7 +40,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')]
#basic_font = pygame.font.Font('STKAITI.TTF',32) score_audio=pygame.mixer.Sound('score.wav')
basic_font = pygame.font.Font('iconfont.53820998.ttf',32)
index = 0 index = 0
y = 400 y = 400
jumpState = "runing" jumpState = "runing"
...@@ -50,6 +51,7 @@ bg_x = 0 ...@@ -50,6 +51,7 @@ bg_x = 0
time = 0 time = 0
gamestate = True gamestate = True
score=0 score=0
old_score=score
block_list =pygame.sprite.Group() # 创建精灵组 block_list =pygame.sprite.Group() # 创建精灵组
while True: while True:
...@@ -74,25 +76,25 @@ while True: ...@@ -74,25 +76,25 @@ while True:
if t > 0: if t > 0:
y -= t y -= t
wukong.rect.y = y wukong.rect.y = y
t -= 20 t -= 1
else: else:
jumpState = "down" jumpState = "down"
if jumpState == "down": # 降落状态 if jumpState == "down": # 降落状态
if t <= 30: if t <= 30:
y += t y += t
wukong.rect.y = y wukong.rect.y = y
t += 20 t += 1
else: else:
jumpState = "runing" jumpState = "runing"
t =30 t =30
1
# 将背景图画上去 # 将背景图画上去
bg_x -= 1 bg_x -= 100
if bg_x<=-1000: if bg_x<=-1000:
bg_x = 0 bg_x = 0
screen.blit(background, (bg_x, 0)) # 远景 screen.blit(background, (bg_x, 0)) # 远景
road_x -= 8 road_x -= 100
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)) # 道路
...@@ -117,10 +119,13 @@ while True: ...@@ -117,10 +119,13 @@ while True:
gamestate = False gamestate = False
else: else:
if (sprite.rect.x+sprite.rect.width)<wukong.rect.x: if (sprite.rect.x+sprite.rect.width)<wukong.rect.x:
score+=sprite.score score += sprite.score
sprite.score=0 sprite.score=0
#scoreSurf = basic_font.render("分数:"+str(score),True,(255,0,0)) if score>old_score:
# screen.blit(scoreSurf,(850,20)) 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()
......
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