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)
17 roach.move = partial(move, roach)
19 roach.start_pos = None
25 """Enemy roach move method"""
26 roach.last_moved += dt
27 if not roach in roach.level.enemies:
28 unschedule(roach.move)
30 if roach.last_moved > 0.5:
31 if not roach.start_pos:
32 roach.start_pos = roach.game_pos
37 dx = random.randint(-1, 1)
38 dy = random.randint(-1, 1)
39 if abs(roach.game_pos[0] + dx - roach.start_pos[0]) > 2:
41 if abs(roach.game_pos[1] + dy - roach.start_pos[1]) > 2:
43 if roach.level.can_walk(roach.game_pos[0] + dx, roach.game_pos[1] + dy, 'floor'):
44 enemy = roach.level.get_enemy(roach.game_pos[0] + dx, roach.game_pos[1] + dy)
45 if enemy and enemy is not roach:
47 roach.game_pos = (roach.game_pos[0] + dx, roach.game_pos[1] + dy)