From a3e63589d1fb98f84c7ffec01afcf17f50be974c Mon Sep 17 00:00:00 2001 From: Neil Date: Sat, 5 Mar 2016 22:59:19 +0200 Subject: [PATCH] Enemy movement is something we may eventually do --- koperkapel/gamelib/enemy_generator.py | 2 +- koperkapel/gamelib/enemy_roach.py | 20 ++++++++++++++++++-- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/koperkapel/gamelib/enemy_generator.py b/koperkapel/gamelib/enemy_generator.py index e8d0108..eaf85d7 100644 --- a/koperkapel/gamelib/enemy_generator.py +++ b/koperkapel/gamelib/enemy_generator.py @@ -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) diff --git a/koperkapel/gamelib/enemy_roach.py b/koperkapel/gamelib/enemy_roach.py index e36b176..91b404b 100644 --- a/koperkapel/gamelib/enemy_roach.py +++ b/koperkapel/gamelib/enemy_roach.py @@ -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 -- 2.34.1