Commit b14a780d by BellCodeEditor

save project

parent 3c84f352
Showing with 33 additions and 27 deletions
...@@ -32,6 +32,7 @@ hero = [pygame.image.load('hero1.png'), ...@@ -32,6 +32,7 @@ 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')]
lose=pygame.image.load('gameover.png')
lu_x=0 lu_x=0
shan_x=0 shan_x=0
index = 0 index = 0
...@@ -40,6 +41,7 @@ jumpState = "runing" ...@@ -40,6 +41,7 @@ jumpState = "runing"
t = 30 t = 30
time=0 time=0
s_list=pygame.sprite.Group() s_list=pygame.sprite.Group()
game_state=True
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:
...@@ -54,7 +56,7 @@ while True: ...@@ -54,7 +56,7 @@ while True:
index += 1 index += 1
if index >= 5: if index >= 5:
index = 0 index = 0
screen.blit(wukong.image, (150, wukong.rect.y))
if jumpState == "up": # 起跳状态 if jumpState == "up": # 起跳状态
if t > 0: if t > 0:
...@@ -75,29 +77,33 @@ while True: ...@@ -75,29 +77,33 @@ while True:
# 悟空造型 # 悟空造型
# 将背景图画上去 # 将背景图画上去
shan_x -=2 if game_state:
if shan_x <-1000: shan_x -=2
shan_x=0 if shan_x <-1000:
screen.blit(background, (shan_x, 0)) # 远处背景 shan_x=0
lu_x -=8 screen.blit(background, (shan_x, 0)) # 远处背景
if lu_x <-1000: lu_x -=8
lu_x=0 if lu_x <-1000:
screen.blit(road, (lu_x, 500)) # 路 lu_x=0
# 悟空 screen.blit(road, (lu_x, 500)) # 路
# 悟空
screen.blit(wukong.image, (150, wukong.rect.y))
time+=1 time+=1
if time>60: if time>60:
time=0 time=0
num=random.randint(0,50) num=random.randint(0,50)
if num>15: if num>15:
aa=Block(bush,cacti,stone) aa=Block(bush,cacti,stone)
s_list.add(aa) s_list.add(aa)
for i in s_list: for i in s_list:
if i.rect.x <= 0-i.rect.width: # 障碍物消失 if i.rect.x <= 0-i.rect.width: # 障碍物消失
i.kill() i.kill()
i.rect.x -= 8 i.rect.x -= 8
screen.blit(i.image, (i.rect.x, i.rect.y)) screen.blit(i.image, (i.rect.x, i.rect.y))
# 刷新画面 if pygame.sprite.collide_rect(wukong,i):
pygame.display.update() screen.blit(lose, (400, 300))
FPS.tick(60) game_state=False
\ No newline at end of file # 刷新画面
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