Mercurial > mamba
changeset 130:9bef49d6db86
Ugly yucky half-done tile orientation magic.
author | Jeremy Thurgood <firxen@gmail.com> |
---|---|
date | Sun, 11 Sep 2011 22:19:59 +0200 |
parents | c533b7c9cbe8 |
children | 513037749086 |
files | data/levels/dev.txt mamba/level.py mamba/mutators.py mamba/sprites.py |
diffstat | 4 files changed, 51 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/data/levels/dev.txt Sun Sep 11 22:11:15 2011 +0200 +++ b/data/levels/dev.txt Sun Sep 11 22:19:59 2011 +0200 @@ -9,8 +9,8 @@ X......................................X X......................................X X......................................X -X......................................X -X......................................X +X.....l................................X +X......r...............................X X......................................X X......................................X X......................................X
--- a/mamba/level.py Sun Sep 11 22:11:15 2011 +0200 +++ b/mamba/level.py Sun Sep 11 22:19:59 2011 +0200 @@ -30,6 +30,8 @@ '>': mktile(EntrySprite, direction=Snake.RIGHT), 'E': mktile(ExitSprite), '~': mktile(PuddleSprite), + 'l': mktile(PuddleSprite, variant=(1, 1, 0, 0)), + 'r': mktile(PuddleSprite, variant=(1, 0, 1, 0)), } THING_MAP = {
--- a/mamba/mutators.py Sun Sep 11 22:11:15 2011 +0200 +++ b/mamba/mutators.py Sun Sep 11 22:19:59 2011 +0200 @@ -36,6 +36,8 @@ BL = Mutator(rotate, -90) TR = Mutator(rotate, 90) BR = Mutator(rotate, 180) +HORIZ = NULL +VERT = Mutator(rotate, 90) # overlays
--- a/mamba/sprites.py Sun Sep 11 22:11:15 2011 +0200 +++ b/mamba/sprites.py Sun Sep 11 22:19:59 2011 +0200 @@ -2,6 +2,7 @@ from mamba.data import load_image from mamba.constants import TILE_SIZE +from mamba import mutators def tile_sizify(pos): @@ -13,13 +14,21 @@ class BaseSprite(Sprite): tileset = 'common' - def __init__(self, tile_char=None, tileset=None, image_name=None): + variant_suffix_0 = '' + variant_suffix_1 = '' + variant_suffix_2o = '' + variant_suffix_2a = '' + variant_suffix_3 = '' + variant_suffix_4 = '' + + def __init__(self, tile_char=None, tileset=None, image_name=None, + mutators=()): super(BaseSprite, self).__init__() self.tile_char = tile_char if tileset is not None: self.tileset = tileset if image_name is not None: - self.image = self.load_image(image_name) + self.image = self.load_image(image_name, mutators=mutators) def load_image(self, image_name, mutators=()): return load_image('tiles/%s/%s.png' % (self.tileset, image_name), @@ -29,6 +38,30 @@ self.tile_pos = tile_pos self.rect = self.image.get_rect().move(tile_sizify(tile_pos)) + def get_tile_variant_modifiers(self, image_name, top, bottom, left, right): + variant_str = ''.join('X' if d else '.' + for d in [top, bottom, left, right]) + variant_suffix, mutator = { + '....': (self.variant_suffix_0, mutators.NULL), + 'X...': (self.variant_suffix_1, mutators.UP), + '.X..': (self.variant_suffix_1, mutators.DOWN), + '..X.': (self.variant_suffix_1, mutators.LEFT), + '...X': (self.variant_suffix_1, mutators.RIGHT), + 'XX..': (self.variant_suffix_2o, mutators.VERT), + '..XX': (self.variant_suffix_2o, mutators.HORIZ), + 'X.X.': (self.variant_suffix_2a, mutators.TL), + 'X..X': (self.variant_suffix_2a, mutators.TR), + '.XX.': (self.variant_suffix_2a, mutators.BL), + '.X.X': (self.variant_suffix_2a, mutators.BR), + '.XXX': (self.variant_suffix_3, mutators.UP), + 'X.XX': (self.variant_suffix_3, mutators.DOWN), + 'XX.X': (self.variant_suffix_3, mutators.LEFT), + 'XXX.': (self.variant_suffix_3, mutators.RIGHT), + 'XXXX': (self.variant_suffix_4, mutators.NULL), + }[variant_str] + + return (image_name + variant_suffix, (mutator,)) + class TileSprite(BaseSprite): def __init__(self, tileset, **kw): @@ -67,3 +100,13 @@ class PuddleSprite(SingleImageTileSprite): image_name = 'puddle' + + variant_suffix_0 = '-island' + variant_suffix_1 = '-r' + variant_suffix_2a = '-tl' + + def __init__(self, variant=(0, 0, 0, 0), **kw): + super(PuddleSprite, self).__init__(**kw) + image_name, mutators = self.get_tile_variant_modifiers(self.image_name, + *variant) + self.image = self.load_image(image_name, mutators)