Commit 0245f4e3 by BellCodeEditor

auto save

parent 1f6e57ef
Showing with 17 additions and 0 deletions
...@@ -6,6 +6,8 @@ pygame.init() # 初始化 ...@@ -6,6 +6,8 @@ pygame.init() # 初始化
screen = pygame.display.set_mode((1000, 600)) screen = pygame.display.set_mode((1000, 600))
FPS = pygame.time.Clock() # pygame时钟,控制游戏速度(帧数) FPS = pygame.time.Clock() # pygame时钟,控制游戏速度(帧数)
pygame.display.set_caption('悟空酷跑') pygame.display.set_caption('悟空酷跑')
class Block(pygame.sprite.Sprite):
# 载入图片 # 载入图片
background = pygame.image.load('bg.png') # 背景 background = pygame.image.load('bg.png') # 背景
road = pygame.image.load('road.png') # 路 road = pygame.image.load('road.png') # 路
...@@ -23,10 +25,13 @@ jumpState = 'runing' ...@@ -23,10 +25,13 @@ jumpState = 'runing'
y = 400 y = 400
bg_x = 0 bg_x = 0
road_x = 0 road_x = 0
time = 0
obstable = random.choice([apple,stone,cacti]) obstable = random.choice([apple,stone,cacti])
rect = obstable.get_rect() rect = obstable.get_rect()
rect.x = 1000 rect.x = 1000
rect.y = 500 - rect.height rect.y = 500 - rect.height
block_list = pygame.sprite.Group()
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:
...@@ -68,6 +73,18 @@ while True: ...@@ -68,6 +73,18 @@ while True:
screen.blit(background, (bg_x, 0)) screen.blit(background, (bg_x, 0))
screen.blit(road, (road_x, 500)) screen.blit(road, (road_x, 500))
screen.blit(wukong, (150,y)) screen.blit(wukong, (150,y))
time += 1
if time >= 60:
r = random.randint(0,100)
if r > 40:
obstable = Block(bush,cacti,stone)
block_list.add(obstable)
time = 0
for prop in block_list:
prop.rect.x -= 8
screen.blit(prop.image,(prop.rect.x,prop.rect.y))
if prop.rect.x < 0 - prop.rect.width:
prop.kill()
if rect.x <= 0-rect.width: if rect.x <= 0-rect.width:
obstable = random.choice([apple,stone,cacti]) obstable = random.choice([apple,stone,cacti])
rect = obstable.get_rect() rect = obstable.get_rect()
......
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