Commit 6aeecaf9 by BellCodeEditor

save project

parent 351f4967
File added
File added
......@@ -7,14 +7,14 @@ pygame.init() # 初始化
class Block(pygame.sprite.Sprite): # 障碍物精灵类
def __init__(self,image1,image2,image3):
super().__init__()
# 加载障碍物的图片
# 加载障碍物的图片
self.image = random.choice([image1, image2, image3])
# 根据障碍物位图的宽高设置矩形
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__()
......@@ -30,8 +30,8 @@ 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') # 路
background = pygame.image.load('IKUN.webp') # 背景
road = pygame.image.load('kunkun.webp') # 路
stone = pygame.image.load('stone.png') # 石头
cacti = pygame.image.load('cacti.png') # 仙人掌
bush = pygame.image.load('bush.png') # 灌木丛
......@@ -40,7 +40,8 @@ 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',32)
score_audio=pygame.mixer.Sound('score.wav')
basic_font = pygame.font.Font('iconfont.53820998.ttf',32)
index = 0
y = 400
jumpState = "runing"
......@@ -50,6 +51,7 @@ bg_x = 0
time = 0
gamestate = True
score=0
old_score=score
block_list =pygame.sprite.Group() # 创建精灵组
while True:
......@@ -74,25 +76,25 @@ while True:
if t > 0:
y -= t
wukong.rect.y = y
t -= 20
t -= 1
else:
jumpState = "down"
if jumpState == "down": # 降落状态
if t <= 30:
y += t
wukong.rect.y = y
t += 20
t += 1
else:
jumpState = "runing"
t =30
1
# 将背景图画上去
bg_x -= 1
bg_x -= 100
if bg_x<=-1000:
bg_x = 0
screen.blit(background, (bg_x, 0)) # 远景
road_x -= 8
road_x -= 100
if road_x<=-1000:
road_x = 0
screen.blit(road, (road_x, 500)) # 道路
......@@ -117,10 +119,13 @@ while True:
gamestate = False
else:
if (sprite.rect.x+sprite.rect.width)<wukong.rect.x:
score+=sprite.score
score += sprite.score
sprite.score=0
#scoreSurf = basic_font.render("分数:"+str(score),True,(255,0,0))
# screen.blit(scoreSurf,(850,20))
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()
......
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