Commit 6598252a by BellCodeEditor

save project

parent 936f2083
Showing with 19 additions and 14 deletions
...@@ -14,6 +14,7 @@ class Block(pygame.sprite.Sprite): ...@@ -14,6 +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):
...@@ -38,11 +39,14 @@ hero = [pygame.image.load('hero1.png'), ...@@ -38,11 +39,14 @@ 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')]
my_font=pygame.font.Font("STKAITI.TTF",25)
index = 0 index = 0
y = 400 y = 400
jumpState = "runing" jumpState = "runing"
t = 30 t = 34
score=0
bg_x = 0 bg_x = 0
road_x = 0 road_x = 0
time = 0 time = 0
...@@ -77,13 +81,13 @@ while True: ...@@ -77,13 +81,13 @@ while True:
else: else:
jumpState = "down" jumpState = "down"
if jumpState == "down": # 降落状态 if jumpState == "down": # 降落状态
if t <= 30: if t <= 34:
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 =34
# 将背景图画上去 # 将背景图画上去
...@@ -97,17 +101,10 @@ while True: ...@@ -97,17 +101,10 @@ while True:
screen.blit(road, (road_x, 500)) screen.blit(road, (road_x, 500))
screen.blit(wukong.image, (150, y)) # 悟空 screen.blit(wukong.image, (150, y)) # 悟空
# 绘制障碍物
# if obstacle.rect.x <= 0-obstacle.rect.width:
# obstacle = Block(bush,cacti,stone)
# obstacle.rect.x -= 8
# obstacle.draw()
# +++++++++++++++++++++++++++++++++++++++
# 创建障碍物对象
time += 1 time += 1
if time >= 60: if time >= 60:
r = random.randint(0, 100) r = random.randint(0, 50)
if r > 40: if r > 20:
obstacle = Block(bush,cacti,stone) obstacle = Block(bush,cacti,stone)
block_list.add(obstacle) block_list.add(obstacle)
time = 0 time = 0
...@@ -121,7 +118,14 @@ while True: ...@@ -121,7 +118,14 @@ 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
# print(len(block_list)) else:
if sprite.rect.x<wukong.rect.x-sprite.rect.width:
score+=sprite.score
sprite.score=0
info="Score "+ str(score)
text=my_font.render(info,True,(0,0,0))
screen.blit(text,(850,70))
# 刷新画面 # 刷新画面
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