Enemy roaches are orientable
[koperkapel.git] / koperkapel / gamelib / enemy_roach.py
index 2645efa8778cca7dd1939465bfa341d1eea58eb0..2a8438241f3bdc8ac3fa0380a57b28bc1b6e6834 100644 (file)
@@ -2,7 +2,7 @@
 
 import random
 
-from pgzero.clock import each_tick
+from pgzero.clock import each_tick, unschedule
 from functools import partial
 
 from ..roaches import t32_roaches, WorldRoach
@@ -10,9 +10,10 @@ from ..roaches import t32_roaches, WorldRoach
 
 def get_enemy_roach(level):
     roach = t32_roaches.assemble(WorldRoach(), color=(255, 0, 0, 255))
-    roach.anchor = (0, 0)
+    roach.anchor = (-16, -16)  # this should center them on the tile
     roach.game_pos = (0, 0)
     roach.health = 5
+    roach.angle = 0
     roach.level = level
     roach.move = partial(move, roach)
     roach.last_moved = 0
@@ -24,6 +25,9 @@ def get_enemy_roach(level):
 def move(roach, dt):
     """Enemy roach move method"""
     roach.last_moved += dt
+    if not roach in roach.level.enemies:
+        unschedule(roach.move)
+        return
     if roach.last_moved > 0.5:
         if not roach.start_pos:
             roach.start_pos = roach.game_pos
@@ -42,4 +46,12 @@ def move(roach, dt):
                 if enemy and enemy is not roach:
                     continue
                 roach.game_pos = (roach.game_pos[0] + dx, roach.game_pos[1] + dy)
+                if dy == 1:
+                    roach.angle = 180
+                elif dy == -1:
+                    roach.angle = 0
+                elif dx == 1:
+                    roach.angle = 270
+                else:
+                    roach.angle = 90
                 break