Enemy movement is something we may eventually do
authorNeil <neil@dip.sun.ac.za>
Sat, 5 Mar 2016 20:59:19 +0000 (22:59 +0200)
committerNeil <neil@dip.sun.ac.za>
Sat, 5 Mar 2016 21:18:39 +0000 (23:18 +0200)
koperkapel/gamelib/enemy_generator.py
koperkapel/gamelib/enemy_roach.py

index e8d01082f3aebaf5d35dc0519f05249650016faf..eaf85d76eb633c9194ef8a08e7842b86979ffe6e 100644 (file)
@@ -32,7 +32,7 @@ class EnemyGenerator(Actor):
 
     def _make_enemy(self):
         if self.enemy_type == 'roach':
-            roach = get_enemy_roach()
+            roach = get_enemy_roach(self.level)
             self._made_enemies.append(roach)
             self.level.add_enemy(roach, *self.gen_pos)
 
index e36b1765802c4e953f022cdd50a6984824b7122d..91b404b12bbdea431c1161298edda1a6f9e88d16 100644 (file)
@@ -1,12 +1,28 @@
 # Roach utilities
 
+import random
+
+from pgzero.clock import each_tick
+from functools import partial
+
 from ..roaches import t32_roaches, WorldRoach
 
 
-def get_enemy_roach():
-    # red
+def get_enemy_roach(level):
     roach = t32_roaches.assemble(WorldRoach(), color=(255, 0, 0, 255))
     roach.anchor = (0, 0)
     roach.game_pos = (0, 0)
     roach.health = 5
+    roach.level = level
+    roach.move = partial(move, roach)
+    roach.last_moved = 0
+    each_tick(roach.move)
     return roach
+
+
+def move(roach, dt):
+    """Enemy roach move method"""
+    roach.last_moved += dt
+    if roach.last_moved > 0.5:
+        print('Moving')
+        roach.last_moved = 0