From 11ff8390096b6205f4f7aaa38a8922775fabd1d4 Mon Sep 17 00:00:00 2001 From: adrianna Date: Sun, 6 Mar 2016 01:49:38 +0200 Subject: [PATCH] this is totally a real rat --- koperkapel/gamelib/enemy_generator.py | 6 +++++- koperkapel/gamelib/enemy_roach.py | 21 +++++++++++++++++++-- koperkapel/roaches.py | 14 ++++++++++++++ 3 files changed, 38 insertions(+), 3 deletions(-) diff --git a/koperkapel/gamelib/enemy_generator.py b/koperkapel/gamelib/enemy_generator.py index b5a1dd4..d399f19 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 +from .enemy_roach import get_enemy_roach, get_rat class EnemyGenerator(Actor): """Generators are currently invisble, but we want the update hook.""" @@ -35,6 +35,10 @@ class EnemyGenerator(Actor): roach = get_enemy_roach(self.level) self._made_enemies.append(roach) self.level.add_enemy(roach, *self.gen_pos) + elif self.enemy_type == 'rat': + roach = get_rat(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 b09c3aa..2dd2f2b 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 +from ..roaches import t32_roaches, WorldRoach, default_rats def get_enemy_roach(level): @@ -13,6 +13,7 @@ def get_enemy_roach(level): roach.anchor = (-16, -16) # this should center them on the tile roach.game_pos = (0, 0) roach.health = 5 + roach.damage = 1 roach.angle = 0 roach.level = level roach.level_layer = 'floor' # always the case for now @@ -25,6 +26,22 @@ def get_enemy_roach(level): return roach +def get_rat(level): + roach = default_rats.assemble() + roach.anchor = (0, 0) + roach.game_pos = (0, 0) + roach.health = 10 + roach.damage = 2 + roach.angle = 0 + roach.level = level + 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 @@ -46,7 +63,7 @@ def attack(roach, player_pos, player_layer, dt): else: roach.angle = 270 # Do 1 damage - return 1 + return roach.damage def move(roach, dt): """Enemy roach move method""" diff --git a/koperkapel/roaches.py b/koperkapel/roaches.py index 1d77563..4995c8a 100644 --- a/koperkapel/roaches.py +++ b/koperkapel/roaches.py @@ -99,9 +99,23 @@ class RoachFactory: return AnimatedSurfActor(frames) +class RatFactory: + + def __init__(self, frames=4): + self.frames = 4 + + def assemble_frame(self, i): + roach = images.load(safepath("rat/rat_%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") big_roaches = RoachFactory("_big") roaches_quartet = RoachFactory("_quartet") roaches_nonet = RoachFactory("_nonet") +default_rats = RatFactory() -- 2.34.1