Commit a79b5ad3 by BellCodeEditor

auto save

parent a00f7a0d
Showing with 13 additions and 11 deletions
...@@ -7,10 +7,10 @@ pygame.init() # 初始化 ...@@ -7,10 +7,10 @@ pygame.init() # 初始化
class Block(pygame.sprite.Sprite): 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=self.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
# 创建一个窗口 # 创建一个窗口
screen = pygame.display.set_mode((1000, 600)) screen = pygame.display.set_mode((1000, 600))
FPS = pygame.time.Clock() # pygame时钟,控制游戏速度(帧数) FPS = pygame.time.Clock() # pygame时钟,控制游戏速度(帧数)
...@@ -30,14 +30,16 @@ index = 0 ...@@ -30,14 +30,16 @@ index = 0
y = 400 y = 400
jumpState = "runing" jumpState = "runing"
t = 30 t = 30
obstacle = random.choice([bush, stone, cacti])
new_road=road.get_rect() # obstacle = random.choice([bush, stone, cacti])
#new_road=road.get_rect()
new_road_x = 0 new_road_x = 0
bg=background.get_rect() #bg=background.get_rect()
bg_x = 0 bg_x = 0
# 创建障碍物对象
obstacle = Block(bush,cacti,stone)
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:
...@@ -69,9 +71,9 @@ while True: ...@@ -69,9 +71,9 @@ while True:
if index >= 5: if index >= 5:
index = 0 index = 0
# 将背景图画上去 # 将背景图画上去
obstacle = Block(bush,cacti,stone)
# 创建障碍物对象
if obstacle.rect.x <= 0-obstacle.rect.width: # 障碍物消失 if obstacle.rect.x <= 0 - obstacle.rect.width: # 障碍物消失
obstacle = Block(bush,cacti,stone) obstacle = Block(bush,cacti,stone)
obstacle.rect.x -= 8 obstacle.rect.x -= 8
......
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