Exemplo n.º 1
0
    def test_rect(self, rect):
        '''
        tests rect placement collisons

        Parameters
        ----------
        rect | object : rect object

        Returns
        -------
        dict: dict of values of rects that have collisions
        '''
        d = {cf.HITLEFT: (0, None), cf.HITRIGHT: (0, None), cf.HITTOP: (0, None), cf.HITBOTTOM: (0, None)}
        for r in self.rects:
            coll = ExtRect.as_rect(rect).clip(ExtRect.as_rect(r))
            if not (coll.width or coll.height):
                #No intersection
                continue
            if coll.left == rect.left and d[cf.HITLEFT][0] < coll.width and coll.width < rect.width:
                d[cf.HITLEFT] = (coll.width, r)
            if coll.right == rect.right and d[cf.HITRIGHT][0] < coll.width and coll.width < rect.width:
                d[cf.HITRIGHT] = (coll.width, r)
            if coll.top == rect.top and d[cf.HITTOP][0] < coll.height and coll.height < rect.height:
                d[cf.HITTOP] = (coll.height, r)
            if coll.bottom == rect.bottom and d[cf.HITBOTTOM][0] < coll.height and coll.height < rect.height:
                d[cf.HITBOTTOM] = (coll.height, r)

        return d
Exemplo n.º 2
0
    def debug_render(self, surf):
        '''
        attempts to draw each rect on surface object to debug

        Parameters
        ----------
        surf | object: surface object
        '''
        for r in self.rects:
            pygame.draw.rect(surf, cf.GEOMDEBUG, ExtRect.as_rect(r), 1)
Exemplo n.º 3
0
    def collide_entities(self, ents):
        '''
        checks for collison with entitites and performs appropriate action

        Parameters
        ----------
        ents | list[object]: list of entity objects
        '''
        for ent in ents:
            if ent.enttype == cf.ENT_CHARACTER:
                continue #Never collide

            coll = self.rect.clip(ExtRect.as_rect(ent.rect))
            if not (coll.width or coll.height):
                continue #Not colliding

            if ent.enttype == cf.ENT_PLATFORM:
                #As a hack, this kind of entity usually inserts its own rect into the Geometry's
                #rects (and updates it in place), so we don't have to worry about collisions.
                #See collide for more info.
                pass
            elif ent.enttype == cf.ENT_OBSTACLE:
                self.kill()
            elif ent.enttype == cf.ENT_TOKEN:
                self.get_token(ent)
            elif ent.enttype == cf.ENT_CHECKPOINT:
                self.set_checkpoint_here(ent)
            elif ent.enttype == cf.ENT_SCRIPTED:
                ent.on_char_collide(self)
            elif ent.enttype == cf.ENT_PORTAL:
                self.teleport()
            #elif ent.enttype == cf.ENT_INVERTER:
            #   self.flip()
            #elif ent.enttype in (cf.ENT_CONVEYER_A, cf.ENT_CONVEYER_B):
            #   self.conveyer()
            elif ent.enttype == cf.ENT_BREAKAWAY:
                self.breakaway(ent)
            elif ent.enttype == cf.ENT_EMPTY:
                pass