Ejemplo n.º 1
0
    def draw(self, camera):

        entities_to_draw = sorted(engine.get().entity_manager.get_in_area(self.tag, rectangle.from_entity(camera.entity), precise=False),
                                  key=lambda entity: rectangle.from_entity(entity).bottom)

        for entity in entities_to_draw:
            entity.handle('draw', camera)
Ejemplo n.º 2
0
    def draw(self, camera):
        world = engine.get().box2d_world

        query = DrawQueryCallback(camera)

        rect = rectangle.from_entity(camera.entity).bounding_rect()

        aabb = Box2D.b2AABB(lowerBound=Box2D.b2Vec2(rect.bottom_left),upperBound=Box2D.b2Vec2(rect.top_right))

        world.QueryAABB(query, aabb)
Ejemplo n.º 3
0
 def remove(self, entity):
     try:
         for square in self.reverse_map[entity] | self._get_grid_squares(rectangle.from_entity(entity)):
             if square in self.map:
                 self.map[square].discard(entity)
                 if len(self.map[square]) == 0:
                     del self.map[square]
             
         del self.reverse_map[entity]
     except AttributeError:
         pass
Ejemplo n.º 4
0
    def draw(self, camera):
        r = rectangle.from_entity(camera.entity).bounding_rect()

        min_grid_x = int(r.left / self.size)
        max_grid_x = int(r.right / self.size + 1)
        min_grid_y = int(r.bottom / self.size)
        max_grid_y = int(r.top / self.size + 1)

        for x in range(min_grid_x, max_grid_x):
            camera.draw_line(self.colour,(x*self.size, r.top), (x*self.size, r.bottom))

        for y in range(min_grid_y, max_grid_y):
            camera.draw_line(self.colour, (r.left, y*self.size), (r.right, y*self.size))
Ejemplo n.º 5
0
    def get(self, rect, precise=True):
        possible_intersections = set()
        for square in self._get_grid_squares(rect):
            if square in self.map:
                possible_intersections.update(self.map[square])
        
        if precise:
            intersections = set()
            for entity in possible_intersections:
                if self._rects_intersect(rect, rectangle.from_entity(entity)):
                    intersections.add(entity)
            return intersections

        return possible_intersections
Ejemplo n.º 6
0
 def add(self, entity):
     try:
         r = rectangle.from_entity(entity)
         if r is None:
             return
         grid_squares = self._get_grid_squares(r)
         for square in grid_squares:
             if not square in self.map:
                 self.map[square] = weakref.WeakSet()
                 
             self.map[square].add(entity)
             
         self.reverse_map[entity] = grid_squares
     except AttributeError:
         pass
Ejemplo n.º 7
0
 def update(self, entity):
     old_squares = self.reverse_map[entity]
     new_squares = self._get_grid_squares(rectangle.from_entity(entity))
     
     for square in old_squares - new_squares:
         self.map[square].discard(entity)
         if len(self.map[square]) == 0:
             del self.map[square]
             
     for square in new_squares - old_squares:
         if square in self.map:
             self.map[square].add(entity)
         else:
             self.map[square] = {entity}
             
     self.reverse_map[entity] = new_squares  
Ejemplo n.º 8
0
 def draw(self, camera):
     for entity in engine.get().entity_manager.get_in_area(self.tag, rectangle.from_entity(camera.entity)):
         entity.handle('draw', camera)
 def handle_draw(self, entity, camera):
     camera.draw_image(rectangle.from_entity(entity), engine.get().resource_manager.get('image', entity.image))
 def handle_draw(self, entity, camera):
     camera.draw_rect(entity.colour, rectangle.from_entity(entity))
     camera.draw_rect(entity.colour, rectangle.from_entity(entity).bounding_rect())