level fix and robots
authoradrianna <adrianna.pinska@gmail.com>
Sat, 5 Mar 2016 23:54:59 +0000 (01:54 +0200)
committeradrianna <adrianna.pinska@gmail.com>
Sat, 5 Mar 2016 23:55:08 +0000 (01:55 +0200)
koperkapel/gamelib/enemy_generator.py
koperkapel/gamelib/enemy_roach.py
koperkapel/roaches.py

index d399f19f12af367492e6664c5731cb634b7202f0..d854128334b5b57d2143a667444a53447b783d3e 100644 (file)
@@ -4,7 +4,7 @@ import os
 from pgzero.actor import Actor
 from pgzero.clock import each_tick
 
-from .enemy_roach import get_enemy_roach, get_rat
+from .enemy_roach import get_enemy_roach, get_rat, get_robot
 
 class EnemyGenerator(Actor):
     """Generators are currently invisble, but we want the update hook."""
@@ -39,6 +39,10 @@ class EnemyGenerator(Actor):
             roach = get_rat(self.level)
             self._made_enemies.append(roach)
             self.level.add_enemy(roach, *self.gen_pos)
+        elif self.enemy_type == 'robot':
+            roach = get_robot(self.level)
+            self._made_enemies.append(roach)
+            self.level.add_enemy(roach, *self.gen_pos)
 
     def killed(self, enemy):
         if enemy in self._made_enemies:
index 2dd2f2bc8276cde542e7bdf7f373fef8e254983f..95805be49f2f0f0f857ef23a748d83fbdfd0322d 100644 (file)
@@ -5,7 +5,7 @@ import random
 from pgzero.clock import each_tick, unschedule
 from functools import partial
 
-from ..roaches import t32_roaches, WorldRoach, default_rats
+from ..roaches import t32_roaches, WorldRoach, default_rats, default_robots
 
 
 def get_enemy_roach(level):
@@ -34,6 +34,7 @@ def get_rat(level):
     roach.damage = 2
     roach.angle = 0
     roach.level = level
+    roach.level_layer = 'floor'  # always the case for now
     roach.move = partial(move, roach)
     roach.last_moved = 0
     roach.last_attacked= 0
@@ -42,6 +43,25 @@ def get_rat(level):
     roach.attack = partial(attack, roach)
     return roach
 
+
+def get_robot(level):
+    roach = default_robots.assemble()
+    roach.anchor = (0, 0)
+    roach.game_pos = (0, 0)
+    roach.health = 10
+    roach.damage = 5
+    roach.angle = 0
+    roach.level = level
+    roach.level_layer = 'floor'  # always the case for now
+    roach.move = partial(move, roach)
+    roach.last_moved = 0
+    roach.last_attacked= 0
+    roach.start_pos = None
+    each_tick(roach.move)
+    roach.attack = partial(attack, roach)
+    return roach
+
+
 def attack(roach, player_pos, player_layer, dt):
     """Attack the player if close enough"""
     roach.last_attacked += dt
index 4995c8a6949c8908d1c4a789b8c9b0e35f5cc8ea..866e5ca25909d24a8bcaea0c9bcce4ebf73768de 100644 (file)
@@ -112,6 +112,21 @@ class RatFactory:
         frames = [self.assemble_frame(i) for i in range(self.frames)]
         return AnimatedSurfActor(frames)
 
+
+class RobotFactory:
+    
+    def __init__(self, frames=4):
+        self.frames = 4
+
+    def assemble_frame(self, i):
+        roach = images.load(safepath("vehicle_tiles/robot_%d") % (i + 1))
+        return roach
+
+    def assemble(self):
+        frames = [self.assemble_frame(i) for i in range(self.frames)]
+        return AnimatedSurfActor(frames)
+
+
 default_roaches = RoachFactory("")
 t32_roaches = RoachFactory("_32")
 t21_roaches = RoachFactory("_21")
@@ -119,3 +134,4 @@ big_roaches = RoachFactory("_big")
 roaches_quartet = RoachFactory("_quartet")
 roaches_nonet = RoachFactory("_nonet")
 default_rats = RatFactory()
+default_robots = RobotFactory()