5 from pgzero.clock import each_tick, unschedule
6 from functools import partial
8 from ..roaches import t32_roaches, WorldRoach
11 def get_enemy_roach(level):
12 roach = t32_roaches.assemble(WorldRoach(), color=(255, 0, 0, 255))
13 roach.anchor = (-16, -16) # this should center them on the tile
14 roach.game_pos = (0, 0)
18 roach.move = partial(move, roach)
20 roach.start_pos = None
26 """Enemy roach move method"""
27 roach.last_moved += dt
28 if not roach in roach.level.enemies:
29 unschedule(roach.move)
31 if roach.last_moved > 0.5:
32 if not roach.start_pos:
33 roach.start_pos = roach.game_pos
38 dx = random.randint(-1, 1)
39 dy = random.randint(-1, 1)
40 if abs(roach.game_pos[0] + dx - roach.start_pos[0]) > 2:
42 if abs(roach.game_pos[1] + dy - roach.start_pos[1]) > 2:
44 if roach.level.can_walk(roach.game_pos[0] + dx, roach.game_pos[1] + dy, 'floor'):
45 enemy = roach.level.get_enemy(roach.game_pos[0] + dx, roach.game_pos[1] + dy)
46 if enemy and enemy is not roach:
48 roach.game_pos = (roach.game_pos[0] + dx, roach.game_pos[1] + dy)