projects
/
koperkapel.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Really gain items.
[koperkapel.git]
/
koperkapel
/
roaches.py
diff --git
a/koperkapel/roaches.py
b/koperkapel/roaches.py
index 95353ee18a441bdf947bb4cf07586c41e1faa18b..b708a88b9b0219f65bee7656b924362113cca6a8 100644
(file)
--- a/
koperkapel/roaches.py
+++ b/
koperkapel/roaches.py
@@
-1,12
+1,36
@@
""" Tools for creating roach actors. """
""" Tools for creating roach actors. """
-import random
-from pgzero.clock import each_tick
from pgzero.loaders import images
from pygame.constants import BLEND_RGBA_MULT
from pgzero.loaders import images
from pygame.constants import BLEND_RGBA_MULT
-from .actors.
orientatedsurf import Orient
atedSurfActor
+from .actors.
animsurf import Anim
atedSurfActor
from .serums import roach_serum_color
from .serums import roach_serum_color
+NAMES = [
+ "roupert",
+ "roachel",
+ "roeginald",
+ "roichard",
+ "rory",
+ "roalph",
+ "roabia",
+ "roafi",
+ "roaman",
+ "roemus",
+ "roadley",
+ "roanaell",
+ "roashwan",
+ "roashid",
+ "roaphael",
+ "roenfield",
+ "roani",
+ "roaya",
+ "roaza",
+ "robekka",
+ "rogan",
+ "roiana",
+ "roberta",
+]
+
def roach_by_name(world, roach_name):
roaches = [r for r in world.roaches if r.name == roach_name]
def roach_by_name(world, roach_name):
roaches = [r for r in world.roaches if r.name == roach_name]
@@
-15,22
+39,24
@@
def roach_by_name(world, roach_name):
return roaches[0]
return roaches[0]
-class RoachActor(OrientatedSurfActor):
- def __init__(self, frames):
- self._frames = frames
- self._frame = random.randint(0, len(frames) - 1)
- self._dt = 0
- self._cycle_dt = 0.2
- each_tick(self.update)
- super().__init__(surf=frames[self._frame], angle=0)
+def next_roach_name(world):
+ roach_names = [x['name'] for x in world.roaches]
+ for cand in NAMES:
+ if cand not in roach_names:
+ return cand
+
- def update(self, dt):
- self._dt += dt
- while self._dt > self._cycle_dt:
- self._dt -= self._cycle_dt
- self._frame += 1
- self._frame %= len(self._frames)
- self.surf = self._frames[self._frame]
+def build_roach(world, name=None, health=5, **kw):
+ if name is None:
+ name = next_roach_name(world)
+ if name is None:
+ return
+ roach = {
+ "name": name,
+ "health": health,
+ }
+ roach.update(kw)
+ return roach
class WorldRoach(object):
class WorldRoach(object):
@@
-48,20
+74,27
@@
class RoachFactory:
self.suffix = suffix
self.frames = 4
self.suffix = suffix
self.frames = 4
- def assemble_frame(self, i, color, roach_data):
+ def assemble_frame(self, i, color, roach_data
, weapon=None
):
roach = images.load("roach%s/roach_%d" % (self.suffix, i + 1))
eyes = images.load("roach%s/eyes_%d" % (self.suffix, i + 1))
roach = images.load("roach%s/roach_%d" % (self.suffix, i + 1))
eyes = images.load("roach%s/eyes_%d" % (self.suffix, i + 1))
- frame = roach.copy()
- frame.fill(color, None, BLEND_RGBA_MULT)
+ if weapon is None:
+ frame = roach.copy()
+ frame.fill(color, None, BLEND_RGBA_MULT)
+ else:
+ frame = weapon.surf.copy()
+ roach = roach.copy()
+ roach.fill(color, None, BLEND_RGBA_MULT)
+ frame.blit(roach, (0, 0))
frame.blit(eyes, (0, 0))
return frame
frame.blit(eyes, (0, 0))
return frame
- def assemble(self, roach_data):
+ def assemble(self, roach_data
, weapon=None
):
color = roach_serum_color(roach_data)
color = roach_serum_color(roach_data)
+ frames = []
frames = [
frames = [
- self.assemble_frame(i, color, roach_data)
+ self.assemble_frame(i, color, roach_data
, weapon
)
for i in range(self.frames)]
for i in range(self.frames)]
- return
Roach
Actor(frames)
+ return
AnimatedSurf
Actor(frames)
default_roaches = RoachFactory("")
default_roaches = RoachFactory("")