Commit f7c37e16 by BellCodeEditor

save project

parent e4cc1c41
Showing with 36 additions and 22 deletions
......@@ -15,7 +15,7 @@ screen = pygame.display.set_mode((1000, 600))
FPS = pygame.time.Clock() # pygame时钟,控制游戏速度(帧数)
pygame.display.set_caption("悟空酷跑")
# 载入图片
backgruond = pygame.image.load('bg.png') # 背景
background = pygame.image.load('bg.png') # 背景
road = pygame.image.load('road.png') # 路
stone = pygame.image.load('stone.png') # 石头
cacti = pygame.image.load('cacti.png') # 仙人掌
......@@ -31,11 +31,14 @@ y = 400
jumpState = "runing"
t = 30
road_x = 0
backgruond_x = 0
ob = random.choice([bush,stone,cacti])
rect = ob.get_rect()
rect.x = 1000
rect.y = 500-rect.height
background_x = 0
time = 0
block_list = pygame.sprite.Group()
# obstacle = Block(bush,stone,cacti)
# ob = random.choice([bush,stone,cacti])
# rect = ob.get_rect()
# rect.x = 1000
# rect.y = 500-rect.height
while True:
for event in pygame.event.get():
......@@ -68,20 +71,31 @@ while True:
if index >= 5:
index = 0
# 将背景图画上去
backgruond_x -= 1
if backgruond_x < 1000:
backgruond_x = 0
screen.blit(backgruond,(backgruond_x,0))
road.x -= 8
if road.x <= -1000:
road.x = 0
if ob.rect.x <= 0-ob.rect.width:
ob = Block(bush,stone,casti)
ob.rect.x -= 8
screen.blit(ob.image,(ob.rect.x,ob.rect.y))
screen.blit(road,(road_x,500))
background_x -= 1
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))
# if obstacle.rect.x <= 0-obstacle.rect.width:
# obstacle= Block(bush,stone,cacti)
# obstacle.rect.x -=8
# screen.blit(obstacle.image,(obstacle.rect.x,obstacle.rect.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()
# 刷新画面
pygame.display.update()
FPS.tick(60)
\ No newline at end of file
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