Commit e421e9bb by BellCodeEditor

auto save

parent d531ec7a
Showing with 12 additions and 6 deletions
...@@ -8,7 +8,7 @@ class Block(pygame.sprite.Sprite): ...@@ -8,7 +8,7 @@ class Block(pygame.sprite.Sprite):
def __init__(self,image1,image2,image3): def __init__(self,image1,image2,image3):
super().__init__() super().__init__()
self.image = random.choice([image1,image2,image3]) self.image = random.choice([image1,image2,image3])
self.rect = image.get_rect() self.rect = self.image.get_rect()
self.rect.x = 1000 self.rect.x = 1000
self.rect.y = 500 - self.rect.height self.rect.y = 500 - self.rect.height
...@@ -35,6 +35,7 @@ road_x=0 ...@@ -35,6 +35,7 @@ road_x=0
bg_x=0 bg_x=0
obstacle = Block(bush,stone,cacti) obstacle = Block(bush,stone,cacti)
block_list=pygame.sprite.Group()
while True: while True:
for event in pygame.event.get(): for event in pygame.event.get():
...@@ -78,11 +79,16 @@ while True: ...@@ -78,11 +79,16 @@ while True:
road_x=0 road_x=0
if obstacle.rect.x <= 0-obstacle.rect.width: # 障碍物消失 if obstacle.rect.x <= 0-obstacle.rect.width: # 障碍物消失
# 创建障碍物对象 # 创建障碍物对象
obstacle =Block(bush,stone,cacti) # obstacle =Block(bush,stone,cacti)
# rect = obstacle.get_rect() # # rect = obstacle.get_rect()
# rect.x = 1000 # # rect.x = 1000
# rect.y = 500 - rect.height # # rect.y = 500 - rect.height
obstacle.rect.x -= 8 # obstacle.rect.x -= 8
obstacle=Block(bush,cacti,stone)
block_list.add(obstacle)
screen.blit(obstacle.image, (obstacle.rect.x, obstacle.rect.y)) screen.blit(obstacle.image, (obstacle.rect.x, obstacle.rect.y))
# 刷新画面 # 刷新画面
pygame.display.update() pygame.display.update()
......
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