5 from pgzero.clock import each_tick
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))
14 roach.game_pos = (0, 0)
17 roach.move = partial(move, roach)
19 roach.start_pos = None
25 """Enemy roach move method"""
26 roach.last_moved += dt
27 if roach.last_moved > 0.5:
28 if not roach.start_pos:
29 roach.start_pos = roach.game_pos
34 dx = random.randint(-1, 1)
35 dy = random.randint(-1, 1)
36 if abs(roach.game_pos[0] + dx - roach.start_pos[0]) > 2:
38 if abs(roach.game_pos[1] + dy - roach.start_pos[1]) > 2:
40 if roach.level.can_walk(roach.game_pos[0] + dx, roach.game_pos[1] + dy, 'floor'):
41 enemy = roach.level.get_enemy(roach.game_pos[0] + dx, roach.game_pos[1] + dy)
42 if enemy and enemy is not roach:
44 roach.game_pos = (roach.game_pos[0] + dx, roach.game_pos[1] + dy)