当前位置: 首页>>代码示例>>Python>>正文


Python Rect.collidelistall方法代码示例

本文整理汇总了Python中pygame.Rect.collidelistall方法的典型用法代码示例。如果您正苦于以下问题:Python Rect.collidelistall方法的具体用法?Python Rect.collidelistall怎么用?Python Rect.collidelistall使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pygame.Rect的用法示例。


在下文中一共展示了Rect.collidelistall方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: grow_rect

# 需要导入模块: from pygame import Rect [as 别名]
# 或者: from pygame.Rect import collidelistall [as 别名]
    def grow_rect(self, rect, growth, rects, direction):
        """Tries to grow a rectangle in the specified direction

        Returns whether the growth succeeded"""
        changed = False
        if growth[direction]:
            left, top, width, height = rect.x, rect.y, rect.w, rect.h
            if direction == LEFT:
                left -= 1
                width += 1
            elif direction == RIGHT:
                width += 1
            elif direction == DOWN:
                height += 1
            elif direction == UP:
                top -= 1
                height += 1
            new = Rect(left, top, width, height)
            if not (set(util.points_in(new)) - self.space) and len(new.collidelistall(rects)) == 1:
                rect.left = left
                rect.width = width
                rect.top = top
                rect.height = height
                changed = True
                #if rect.width >= 8 and rect.height >= 8 and random.randrange(5) == 0:
                #    growth[direction] = False
            else:
                growth[direction] = False

        return changed
开发者ID:Ragzouken,项目名称:agutaywusyg,代码行数:32,代码来源:castle.py

示例2: grow_rect

# 需要导入模块: from pygame import Rect [as 别名]
# 或者: from pygame.Rect import collidelistall [as 别名]
    def grow_rect(self, i, rect, growth, adjacency, rects, direction):
        """Tries to grow a rectangle in the specified direction

        Returns whether the growth succeeded"""
        if rect.w > 100 or rect.h > 100:
            growth[direction] = False
            return False
        if growth[direction]:
            left, top, width, height = rect.x, rect.y, rect.w, rect.h
            if direction == LEFT:
                left -= 1
                width += 1
                if height > 1:
                    collision = Rect(rect.x, rect.y+1, 1, rect.h-2)
                else:
                    collision = Rect(rect.x, rect.y, 1, 1)
            elif direction == RIGHT:
                width += 1
                if height > 1:
                    collision = Rect(rect.right-1, rect.y+1, 1, rect.h-2)
                else:
                    collision = Rect(rect.right-1, rect.y, 1, 1)
            elif direction == DOWN:
                height += 1
                if width > 1:
                    collision = Rect(rect.x+1, rect.bottom-1, rect.w-2, 1)
                else:
                    collision = Rect(rect.x, rect.bottom-1, 1, 1)
            elif direction == UP:
                top -= 1
                height += 1
                if width > 1:
                    collision = Rect(rect.x+1, rect.y, rect.w-2, 1)
                else:
                    collision = Rect(rect.x, rect.y, 1, 1)
            building_collisions = collision.collidelistall(rects)
            try:
                building_collisions.remove(i)
            except ValueError:
                pass
            if not (set(Generator.get_rect(collision)) - self.space) and len(building_collisions) == 0:
                rect.left = left
                rect.width = width
                rect.top = top
                rect.height = height
                #if rect.width >= 8 and rect.height >= 8 and random.randrange(5) == 0:
                #    growth[direction] = False
                return True
            else:
                growth[direction] = False
                if building_collisions:
                    care_about = [j for j in building_collisions if j < len(self.points)]
                    # If we collided with a building, make a note.
                    adjacency[i] += care_about
                    for j in care_about:
                        adjacency[j].append(i)

        return False
开发者ID:fish-face,项目名称:agutaywusyg,代码行数:60,代码来源:castle.py

示例3: test_collidelistall

# 需要导入模块: from pygame import Rect [as 别名]
# 或者: from pygame.Rect import collidelistall [as 别名]
    def test_collidelistall(self):

        # __doc__ (as of 2008-08-02) for pygame.rect.Rect.collidelistall:

        # Rect.collidelistall(list): return indices
        # test if all rectangles in a list intersect
        #
        # Returns a list of all the indices that contain rectangles that
        # collide with the Rect. If no intersecting rectangles are found, an
        # empty list is returned.

        r = Rect(1, 1, 10, 10)

        l = [Rect(1, 1, 10, 10), Rect(5, 5, 10, 10), Rect(15, 15, 1, 1), Rect(2, 2, 1, 1)]
        self.assertEqual(r.collidelistall(l), [0, 1, 3])

        f = [Rect(50, 50, 1, 1), Rect(20, 20, 5, 5)]
        self.assertFalse(r.collidelistall(f))
开发者ID:G2ProjectUAV,项目名称:Project-UAV,代码行数:20,代码来源:rect_test.py

示例4: grow_room

# 需要导入模块: from pygame import Rect [as 别名]
# 或者: from pygame.Rect import collidelistall [as 别名]
    def grow_room(self, room, growing, max_size, pad_v=0, pad_h=0, space=None):
        """Tries to grow a room in the specified direction

        Returns whether the growth succeeded"""
        space = space if space is not None else self.interior_space
        for d, grow in enumerate(growing):
            if not grow:
                continue
            if (((d == LEFT or d == RIGHT) and room.w > max_size) or
                    ((d == UP or d == DOWN) and room.h > max_size)):
                growing[d] = False
                continue
            left, top, width, height = room.x, room.y, room.w, room.h
            if d == LEFT:
                left -= 1
                width += 1
                if room.w <= 1:
                    collision = None
                else:
                    collision = Rect(room.x - pad_h, room.y + 1 - pad_v,
                                     1 + pad_h, max(1, room.h + 2 * pad_v - 2))
            elif d == RIGHT:
                width += 1
                if room.w <= 1:
                    collision = None
                else:
                    collision = Rect(room.right - 1 - pad_h, room.y + 1,
                                     1 + pad_h, max(1, room.h + 2 * pad_v - 2))
            elif d == DOWN:
                height += 1
                if room.h <= 1:
                    collision = None
                else:
                    collision = Rect(room.x + 1 - pad_h, room.bottom - 1,
                                     max(1, room.w - 2 + 2 * pad_h), 1 + pad_v)
            elif d == UP:
                top -= 1
                height += 1
                if room.h <= 1:
                    collision = None
                else:
                    collision = Rect(room.x + 1 - pad_h, room.y - pad_v,
                                     max(1, room.w - 2 + 2 * pad_h), 1 + pad_v)
            if collision is not None:
                building_collisions = collision.collidelistall([r.rect for r in self.shapes if isinstance(r, Room)])
            else:
                building_collisions = []
            if not (set(Generator.get_rect(collision)) - space) and len(building_collisions) == 0:
                room.left = left
                room.width = width
                room.top = top
                room.height = height
            else:
                print room.rect, collision, d, building_collisions, (set(Generator.get_rect(collision)) - space)
                growing[d] = False
开发者ID:fish-face,项目名称:agutaywusyg,代码行数:57,代码来源:fortress.py


注:本文中的pygame.Rect.collidelistall方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。