Esempio n. 1
0
 def __init__(self, event_manager, entity_id):
     SingleListener.__init__(self, event_manager)
     self.entity_id = entity_id
     self._area = None
     self._age = 0
     # This `exists` variable is funny.  It comes in play because of how the
     # physics engine is built.  Imagine that for some reason (creature
     # walks in lava, bonus gets picked up), an entity disappears from the
     # world due to its physical interaction with the environment.  The
     # natural thing to do is to remove that entity from the world. However,
     # that will break the physics engine since the dictionaries will change
     # size during iterations.  So instead, we mark the 'dead' entity by
     # setting its `exists` variable to False.  That saves the physics
     # engine, but now we must take care that it ignores every entity that
     # does not exist.
     self.exists = True
     # Physics.
     self.body = physics.CircularBody(self.BODY_MASS, geometry.Vector(),
                                      self.SOLID, materials.MATERIAL_FLESH,
                                      self.BODY_RADIUS)
     self._walk_force = physics.ConstantForce(geometry.Vector())
     self.friction_force = physics.KineticFrictionForce(0)
     self.body.forces.add(self._walk_force)
     self.body.forces.add(self.friction_force)
     self._walk_strentgh = self.WALK_STRENGTH
     self.is_moving = False
     # Final stuff.
     self.post(events.EntityCreatedEvent(entity_id))
     LOGGER.debug("Entity %i created.", entity_id)
Esempio n. 2
0
 def __init__(self, event_manager, entity_id):
     SingleListener.__init__(self, event_manager)
     self.entity_id = entity_id
     self._area = None
     self._age = 0
     # This `exists` variable is funny.  It comes in play because of how the
     # physics engine is built.  Imagine that for some reason (creature
     # walks in lava, bonus gets picked up), an entity disappears from the
     # world due to its physical interaction with the environment.  The
     # natural thing to do is to remove that entity from the world. However,
     # that will break the physics engine since the dictionaries will change
     # size during iterations.  So instead, we mark the 'dead' entity by
     # setting its `exists` variable to False.  That saves the physics
     # engine, but now we must take care that it ignores every entity that
     # does not exist.
     self.exists = True
     # Physics.
     self.body = physics.CircularBody(self.BODY_MASS,
                                      geometry.Vector(),
                                      self.SOLID,
                                      materials.MATERIAL_FLESH,
                                      self.BODY_RADIUS)
     self._walk_force = physics.ConstantForce(geometry.Vector())
     self.friction_force = physics.KineticFrictionForce(0)
     self.body.forces.add(self._walk_force)
     self.body.forces.add(self.friction_force)
     self._walk_strentgh = self.WALK_STRENGTH
     self.is_moving = False
     # Final stuff.
     self.post(events.EntityCreatedEvent(entity_id))
     LOGGER.debug("Entity %i created.", entity_id)
Esempio n. 3
0
 def unregister(self):
     """Also unregisters its content."""
     for area in self._areas.values():
         area.unregister()
     for entity in self.entities.values():
         entity.unregister()
     SingleListener.unregister(self)
Esempio n. 4
0
 def __init__(self, event_manager, world, area_id):
     SingleListener.__init__(self, event_manager)
     self.area_id = area_id
     self.world = world
     # Only keep weak references to the entities because they are owned by
     # the World itself, not by the area.  They can move between areas, or
     # even be in no area at all.
     self.entities = weakref.WeakValueDictionary()
     # The tile map is a data structure that describes the fixed features of
     # the landscape.  By fix, I mean that these features cannot move.
     # However, one can imagine that some of these features appear,
     # disappear or change.  For example, a door can open.
     self.tile_map = tile.TileMap()
     # The entity map is here ONLY for performance purposes.  It allows a
     # relatively quick access to the entities in a region.  This helps us
     # limiting the number of entities to look for during collisions, or
     # when a creature is looking around for nearby victims.
     self.entity_map = EntityMap()
     # Useful for collision detection: entities are colliding if the
     # distance between them is smaller than the sum of their radii. Keeping
     # track of the biggest possible radius helps you delimiting the area
     # containing the entities you may be colliding with.  Nothing beyond
     # your_radius + biggest_radius can touch you.
     self._biggest_entity_radius = 0
     LOGGER.debug("Area %i created.", area_id)
Esempio n. 5
0
 def __init__(self, event_manager, world, area_id):
     SingleListener.__init__(self, event_manager)
     self.area_id = area_id
     self.world = world
     # Only keep weak references to the entities because they are owned by
     # the World itself, not by the area.  They can move between areas, or
     # even be in no area at all.
     self.entities = weakref.WeakValueDictionary()
     # The tile map is a data structure that describes the fixed features of
     # the landscape.  By fix, I mean that these features cannot move.
     # However, one can imagine that some of these features appear,
     # disappear or change.  For example, a door can open.
     self.tile_map = tile.TileMap()
     # The entity map is here ONLY for performance purposes.  It allows a
     # relatively quick access to the entities in a region.  This helps us
     # limiting the number of entities to look for during collisions, or
     # when a creature is looking around for nearby victims.
     self.entity_map = EntityMap()
     # Useful for collision detection: entities are colliding if the
     # distance between them is smaller than the sum of their radii. Keeping
     # track of the biggest possible radius helps you delimiting the area
     # containing the entities you may be colliding with.  Nothing beyond
     # your_radius + biggest_radius can touch you.
     self._biggest_entity_radius = 0
     LOGGER.debug("Area %i created.", area_id)
Esempio n. 6
0
 def unregister(self):
     """Also unregisters its content."""
     for area in self._areas.values():
         area.unregister()
     for entity in self.entities.values():
         entity.unregister()
     SingleListener.unregister(self)
Esempio n. 7
0
 def __init__(self, event_manager):
     SingleListener.__init__(self, event_manager)
     self.area = None
     self.coords = None
     self.factory = None
     self.period = None
     self._timer = 0
     self._active = True
Esempio n. 8
0
 def __init__(self, event_manager):
     SingleListener.__init__(self, event_manager)
     self.area = None
     self.coords = None
     self.factory = None
     self.period = None
     self._timer = 0
     self._active = True
Esempio n. 9
0
 def __init__(self, event_manager):
     SingleListener.__init__(self, event_manager)
     self.key_up_events = {}
     self.key_down_events = {}
     self.setup()
Esempio n. 10
0
 def __init__(self, event_manager):
     SingleListener.__init__(self, event_manager)
     self._entity_id_max = -1
     self.entities = {}
     self._area_id_max = -1
     self._areas = {}
Esempio n. 11
0
 def __init__(self, event_manager):
     SingleListener.__init__(self, event_manager)
     self._entity_id_max = -1
     self.entities = {}
     self._area_id_max = -1
     self._areas = {}