Source

pygame-tutorial / 16-enemies.py

Diff from to

16-enemies.py

     direction = 1
     def update(self, dt, game):
         self.rect.x += self.direction * 100 * dt
-        for cell in game.tilemap.layers_by_name['triggers'].collide(self.rect, 'reverse'):
+        for cell in game.tilemap.layers['triggers'].collide(self.rect, 'reverse'):
             if self.direction > 0:
                 self.rect.right = cell.left
             else:
 
         new = self.rect
         self.resting = False
-        for cell in game.tilemap.layers_by_name['triggers'].collide(new, 'blockers'):
+        for cell in game.tilemap.layers['triggers'].collide(new, 'blockers'):
             blockers = cell.tile.properties['blockers']
             if 'l' in blockers and last.right <= cell.left and new.right > cell.left:
                 new.right = cell.left
         self.tilemap = tmx.load('map.tmx', screen.get_size())
 
         self.sprites = tmx.SpriteLayer()
-        start_cell = self.tilemap.layers_by_name['triggers'].find(player='')[0]
+        start_cell = self.tilemap.layers['triggers'].find('player')[0]
         self.player = Player('player.png', (start_cell.px, start_cell.py))
         self.sprites.add(self.player)
         self.tilemap.layers.append(self.sprites)
 
         self.enemies = tmx.SpriteLayer()
-        for enemy in self.tilemap.layers_by_name['triggers'].find(enemy=''):
+        for enemy in self.tilemap.layers['triggers'].find('enemy'):
             self.enemies.add(Enemy('enemy.png', (enemy.px, enemy.py)))
         self.tilemap.layers.append(self.enemies)