From: Neil Date: Sat, 5 Mar 2016 20:59:19 +0000 (+0200) Subject: Enemy movement is something we may eventually do X-Git-Url: https://git.ctpug.org.za/?a=commitdiff_plain;h=a3e63589d1fb98f84c7ffec01afcf17f50be974c;p=koperkapel.git Enemy movement is something we may eventually do --- 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