Commit 31ff69d8 by BellCodeEditor

save project

parent 2e30dad2
Showing with 58 additions and 52 deletions
...@@ -42,6 +42,7 @@ time = 0 ...@@ -42,6 +42,7 @@ time = 0
t=30 t=30
# obstacle=Block(bush,cacti,stone) # obstacle=Block(bush,cacti,stone)
block_list=pygame.sprite.Group() block_list=pygame.sprite.Group()
gamestste=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:
...@@ -51,56 +52,61 @@ while True: ...@@ -51,56 +52,61 @@ while True:
if jumpState == "runing": if jumpState == "runing":
if event.key == locals.K_SPACE: if event.key == locals.K_SPACE:
jumpState = "up" jumpState = "up"
if gamestste=='True':
if jumpState == "up": # 起跳状态 if jumpState == "up": # 起跳状态
if t > 0: if t > 0:
y -= t y -= t
t -= 2 t -= 2
else: else:
jumpState = "down" jumpState = "down"
if jumpState == "down": # 降落状态 if jumpState == "down": # 降落状态
if t <= 30: if t <= 30:
y += t y += t
t += 2 t += 2
else: else:
jumpState = "runing" jumpState = "runing"
t =30 t =30
# 悟空造型
wukong = hero[index]
if jumpState == "runing": # 跑步状态下
index += 1
if index >= 5:
index = 0
# 将背景图画上去
background_x -=2
if background_x <-1000:
background_x=0
screen.blit(background, (background_x, 0)) # 远处背景
road_x -=8
if road_x <-1000:
road_x=0
screen.blit(road, (road_x, 500)) # 路
screen.blit(wukong, (150, y)) # 悟空
time+=1
if time>=60:
s=random.randint(0,100)
if s>40:
obstacle=Block(bush,stone,cacti)
block_list.add(obstacle)
time=0
for sprite in block_list:
sprite.rect.x-=8
screen.blit(sprite.image,(sprite.rect.x,sprite.rect.y))
if sprite.rect.x<0-sprite.rect.width:
sprite.kill()
if pygame.sprite.collide_rect(wukong,sprite):
gameover=pygame.image.load('gameover.png')
screen.blit(gameover,(400,200))
gamestste=False
# if obstacle.rect.x <= 0-obstacle.rect.width: # 障碍物消失
# # 创建障碍物对象
# obstacle=Block(bush,cacti,stone)
# obstacle.rect.x -= 8
# 悟空造型 # screen.blit(obstacle.image, (obstacle.rect.x, obstacle.rect.y))
wukong = hero[index] # 刷新画面
if jumpState == "runing": # 跑步状态下
index += 1
if index >= 5:
index = 0
# 将背景图画上去
background_x -=2
if background_x <-1000:
background_x=0
screen.blit(background, (background_x, 0)) # 远处背景
road_x -=8
if road_x <-1000:
road_x=0
screen.blit(road, (road_x, 500)) # 路
screen.blit(wukong, (150, y)) # 悟空
time+=1
if time>=60:
s=random.randint(0,100)
if s>40:
obstacle=Block(bush,stone,cacti)
block_list.add(obstacle)
time=0
for sprite in block_list:
sprite.rect.x-=8
screen.blit(sprite.image,(sprite.rect.x,sprite.rect.y))
if sprite.rect.x<0-sprite.rect.width:
sprite.kill()
# if obstacle.rect.x <= 0-obstacle.rect.width: # 障碍物消失
# # 创建障碍物对象
# obstacle=Block(bush,cacti,stone)
# obstacle.rect.x -= 8
pygame.display.update()
# screen.blit(obstacle.image, (obstacle.rect.x, obstacle.rect.y)) FPS.tick(60)
# 刷新画面 \ 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