from pgzero.actor import Actor
from pgzero.clock import each_tick
-from .enemy_roach import get_enemy_roach, get_rat
+from .enemy_roach import get_enemy_roach, get_rat, get_robot
class EnemyGenerator(Actor):
"""Generators are currently invisble, but we want the update hook."""
roach = get_rat(self.level)
self._made_enemies.append(roach)
self.level.add_enemy(roach, *self.gen_pos)
+ elif self.enemy_type == 'robot':
+ roach = get_robot(self.level)
+ self._made_enemies.append(roach)
+ self.level.add_enemy(roach, *self.gen_pos)
def killed(self, enemy):
if enemy in self._made_enemies:
from pgzero.clock import each_tick, unschedule
from functools import partial
-from ..roaches import t32_roaches, WorldRoach, default_rats
+from ..roaches import t32_roaches, WorldRoach, default_rats, default_robots
def get_enemy_roach(level):
roach.damage = 2
roach.angle = 0
roach.level = level
+ roach.level_layer = 'floor' # always the case for now
roach.move = partial(move, roach)
roach.last_moved = 0
roach.last_attacked= 0
roach.attack = partial(attack, roach)
return roach
+
+def get_robot(level):
+ roach = default_robots.assemble()
+ roach.anchor = (0, 0)
+ roach.game_pos = (0, 0)
+ roach.health = 10
+ roach.damage = 5
+ roach.angle = 0
+ roach.level = level
+ roach.level_layer = 'floor' # always the case for now
+ roach.move = partial(move, roach)
+ roach.last_moved = 0
+ roach.last_attacked= 0
+ roach.start_pos = None
+ each_tick(roach.move)
+ roach.attack = partial(attack, roach)
+ return roach
+
+
def attack(roach, player_pos, player_layer, dt):
"""Attack the player if close enough"""
roach.last_attacked += dt
frames = [self.assemble_frame(i) for i in range(self.frames)]
return AnimatedSurfActor(frames)
+
+class RobotFactory:
+
+ def __init__(self, frames=4):
+ self.frames = 4
+
+ def assemble_frame(self, i):
+ roach = images.load(safepath("vehicle_tiles/robot_%d") % (i + 1))
+ return roach
+
+ def assemble(self):
+ frames = [self.assemble_frame(i) for i in range(self.frames)]
+ return AnimatedSurfActor(frames)
+
+
default_roaches = RoachFactory("")
t32_roaches = RoachFactory("_32")
t21_roaches = RoachFactory("_21")
roaches_quartet = RoachFactory("_quartet")
roaches_nonet = RoachFactory("_nonet")
default_rats = RatFactory()
+default_robots = RobotFactory()