def update(self, dt):
self.mcnay.update()
self.background.update()
# Loop through and update obstacles. Replace obstacles which went off the screen.
for obstacle in self.obstacles:
obstacle.update()
if obstacle.x < self.mcnay.x and not obstacle.marked:
obstacle.marked = True
self.score += 1
self.new_obstacle(remove=False)
if len(self.obstacles) == 0:
self.new_obstacle(remove=False)
elif self.obstacles[0].x < 0:
self.remove_obstacle()
# If obstacles is emply
# See if the player collides with any obstacles
for obstacle in self.obstacles:
if self.mcnay.collide_widget(Widget(pos=(obstacle.x, obstacle.gap_top + 20), size=(obstacle.width, obstacle.height - obstacle.gap_top))):
# This will be replaced later on
sys.exit()
if self.mcnay.collide_widget(Widget(pos=(obstacle.x, 0), size=(obstacle.width, obstacle.gap_top - obstacle.gap_size))):
# This will also be replaced
sys.exit()
评论列表
文章目录