From: adrianna Date: Sat, 5 Mar 2016 23:54:59 +0000 (+0200) Subject: level fix and robots X-Git-Url: https://git.ctpug.org.za/?a=commitdiff_plain;h=cd69d9169187053686ecbe74d93b6f08a20c826c;p=koperkapel.git level fix and robots --- diff --git a/koperkapel/gamelib/enemy_generator.py b/koperkapel/gamelib/enemy_generator.py index d399f19..d854128 100644 --- a/koperkapel/gamelib/enemy_generator.py +++ b/koperkapel/gamelib/enemy_generator.py @@ -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: diff --git a/koperkapel/gamelib/enemy_roach.py b/koperkapel/gamelib/enemy_roach.py index 2dd2f2b..95805be 100644 --- a/koperkapel/gamelib/enemy_roach.py +++ b/koperkapel/gamelib/enemy_roach.py @@ -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 diff --git a/koperkapel/roaches.py b/koperkapel/roaches.py index 4995c8a..866e5ca 100644 --- a/koperkapel/roaches.py +++ b/koperkapel/roaches.py @@ -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()