Changeset 168:ce8d4fc3baf4


Ignore:
Timestamp:
Sep 3, 2013, 12:39:38 PM (7 years ago)
Author:
Neil Muller <drnlmuller@…>
Branch:
default
Message:

A patrolling alien

Location:
nagslang
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • nagslang/constants.py

    r107 r168  
    1414COLLISION_TYPE_SWITCH = 3
    1515COLLISION_TYPE_BOX = 4
     16COLLISION_TYPE_ENEMY = 5
    1617
    1718SWITCH_PUSHERS = [COLLISION_TYPE_PLAYER, COLLISION_TYPE_BOX]
  • nagslang/level.py

    r164 r168  
    33
    44from nagslang import game_object as go
     5from nagslang import enemies
    56from nagslang.resources import resources
    67from nagslang.yamlish import load, dump
     
    3132        self._drawables = []
    3233        self._game_objects = []
     34        self._enemies = []
    3335
    3436    def _get_data(self):
     
    4446            'polygons': self.polygons,
    4547            'game_objects': self._game_objects,
     48            'enemies': self._enemies,
    4649        }, f)
    4750
     
    5760        for game_object_dict in self._game_objects:
    5861            self._create_game_object(space, **game_object_dict)
     62        self._enemies = data.get('enemies', [])
     63        for enemy_dict in self._enemies:
     64            self._create_enemy(space, **enemy_dict)
    5965
    6066    def _create_game_object(self, space, classname, args, name=None):
     
    7076            raise TypeError(
    7177                "Expected a subclass of Puzzler or GameObject, got %s" % (
     78                    classname))
     79        if name is not None:
     80            self._glue.add_component(name, gobj)
     81
     82    def _create_enemy(self, space, classname, args, name=None):
     83        cls = getattr(enemies, classname)
     84        if issubclass(cls, go.GameObject):
     85            gobj = cls(space, *args)
     86            self._drawables.append(gobj)
     87        else:
     88            raise TypeError(
     89                "Expected a subclass of GameObject, got %s" % (
    7290                    classname))
    7391        if name is not None:
Note: See TracChangeset for help on using the changeset viewer.