Changeset 28:94d5ebaa912f


Ignore:
Timestamp:
Apr 3, 2011, 4:41:52 PM (9 years ago)
Author:
Simon Cross <hodgestar@…>
Branch:
default
Message:

Example for global sprite importing.

Files:
3 edited

Legend:

Unmodified
Added
Removed
  • data/levels/level1.json

    r26 r28  
    2020    "enemies": [
    2121        {"type": "Dummy", "pos": [2, 2], "direction": "left" }
     22    ],
     23    "sprites": [
     24        {"type": "enemies.Dummy", "pos": [2, 2], "direction": "left" }
    2225    ]
    2326}
  • skaapsteker/level.py

    r25 r28  
    55import data
    66from sprites import enemies
     7from sprites.base import find_sprite
    78
    89
     
    4344        self.build_tiles()
    4445        self.setup_enemies()
     46        self.setup_sprites()
    4547
    4648
     
    6567            self.enemies.append(enemies.get_enemy(enemy))
    6668
     69    def setup_sprites(self):
     70        self.sprites = []
     71        for sprite_desc in self.level_data['sprites']:
     72            self.sprites.append(find_sprite(sprite_desc))
     73        print self.sprites
    6774
    6875    def tile_pos(self, x, y):
  • skaapsteker/sprites/base.py

    r25 r28  
    3535    mobile = False
    3636    gravitates = False
     37
     38
     39def find_sprite(descr):
     40    """Create a sprite object from a dictionary describing it."""
     41    descr = descr.copy()
     42    stype = descr.pop("type")
     43    mod_name, cls_name = stype.rsplit(".", 1)
     44    mod_name = ".".join(["skaapsteker.sprites", mod_name])
     45    mod =  __import__(mod_name, fromlist=[cls_name])
     46    cls = getattr(mod, cls_name)
     47    return cls(**descr)
Note: See TracChangeset for help on using the changeset viewer.