1 """ Add enemies to the level as required """
4 from pgzero.actor import Actor
5 from pgzero.clock import each_tick
7 from .enemy_roach import get_enemy_roach, get_rat
9 class EnemyGenerator(Actor):
10 """Generators are currently invisble, but we want the update hook."""
12 def __init__(self, info, level):
13 self.gen_pos = info['pos']
15 self.enemy_type = info['type']
16 self.rate = info['rate']
17 self.max_enemies = info['max']
18 self._time_since_last_update = 0
20 each_tick(self.update)
21 self._made_enemies = []
22 super().__init__(os.path.join('weapons', 'blank'))
27 self._time_since_last_update += dt
28 if self._time_since_last_update > self.rate:
29 if len(self._made_enemies) < self.max_enemies:
31 self._time_since_last_update = 0
33 def _make_enemy(self):
34 if self.enemy_type == 'roach':
35 roach = get_enemy_roach(self.level)
36 self._made_enemies.append(roach)
37 self.level.add_enemy(roach, *self.gen_pos)
38 elif self.enemy_type == 'rat':
39 roach = get_rat(self.level)
40 self._made_enemies.append(roach)
41 self.level.add_enemy(roach, *self.gen_pos)
43 def killed(self, enemy):
44 if enemy in self._made_enemies:
45 self._made_enemies.remove(enemy)
46 # Delay next respawn so we don't flood the player with enemies
47 self._time_since_last_update = 0