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


Python Rect.collidelist方法代码示例

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


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

示例1: draw

# 需要导入模块: from pygame import Rect [as 别名]
# 或者: from pygame.Rect import collidelist [as 别名]
 def draw(self, screen, work_rects=None):
     """Draw the map to the screen"""
     if work_rects is None:
         work_rects = [Rect(0,0,screen.get_width(),screen.get_height())]
     extra_things = collections.defaultdict(list)
     for (k,v) in self.map_to_draw.objects.items():
         extra_things[k].extend(v)
     extra_things[self.map_coords(pygame.mouse.get_pos(), screen)].append(self.mouse_cursor)
     for i in range(self.map_to_draw.w):
         for j in range(self.map_to_draw.h):
             view_x =  32*i-32*j
             view_y =  16*i+16*j
             x, y = view_x - self.view_x + screen.get_width()//2, view_y-self.view_y + screen.get_height()//2
             t = self.map_to_draw.terrain((i,j))
             s = t.sprite
             s_pos = Rect(x-32,y+16-s.get_height(),s.get_width(),s.get_height())
             if s_pos.collidelist(work_rects)>=0:
                 screen.blit(s, s_pos)
                 if (i,j) in extra_things:
                     for t in extra_things[(i,j)]:
                         if isinstance(t, pygame.Surface):
                             s = t
                         else:
                             s = t.sprite
                         screen.blit(s,(x-32,y+16-s.get_height()))
开发者ID:jjvv,项目名称:gearhead-prime,代码行数:27,代码来源:sdlmap.py

示例2: test_collidelist

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

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

          # Rect.collidelist(list): return index
          # test if one rectangle in a list intersects
          # 
          # Test whether the rectangle collides with any in a sequence of
          # rectangles. The index of the first collision found is returned. If
          # no collisions are found an index of -1 is returned.

        r = Rect(1, 1, 10, 10)
        l = [Rect(50, 50, 1, 1), Rect(5, 5, 10, 10), Rect(15, 15, 1, 1)]

        self.assertEqual(r.collidelist(l), 1)

        f = [Rect(50, 50, 1, 1), (100, 100, 4, 4)]
        self.assertEqual(r.collidelist(f), -1)
开发者ID:CTPUG,项目名称:pygame_cffi,代码行数:20,代码来源:rect_test.py

示例3: Explode

# 需要导入模块: from pygame import Rect [as 别名]
# 或者: from pygame.Rect import collidelist [as 别名]
 def Explode(self):
     global Players
     # Determine if we have to remove any tile within our range.
     BRects = [ Rect(self.x + 32, self.y, 32, 32), Rect(self.x - 32, self.y, 32, 32),
                Rect(self.x, self.y + 32, 32, 32), Rect(self.x, self.y - 32, 32, 32)]
     for Tile in Map :
         if Tile.Breakable == False :
            continue
         TRect = Rect(Tile.x, Tile.y, 32, 32)
         if TRect.collidelist(BRects) != -1 :
             RandomPowerUp = Globals.PowerupType(random.choice(list(Globals.PowerupType)))
             if(  not(RandomPowerUp == Globals.PowerupType.PW_NONE) ) :
                 Map.append(MapObject(Tile.x,Tile.y,RandomPowerUp))
             Map.remove(Tile)
     self.AdjustOwnerBombCount()
     for player in Players :
         PRect = Rect(player.x, player.y, 32, 32)
         if PRect.collidelist(BRects) != -1 or (player.x == self.x and player.y == self.y):
             # Player died.
             # Find the owner
             #if self.OwnerID == player.ID :
                 #print("Player suicided.")
             #else :
                 #print("Client ID ", self.OwnerID, " killed ", player.ID)
                 #if self.OwnerID == NetInterface.ID :
                  #   GetMainPlayer().NumKills += 1
              #    print("YAY KILLED!")
              if player.ID == GetMainPlayer().ID :
                  continue
              if not(player.Used) :
                  continue
              player.Used = False
              print("Player died");
              GetMainPlayer().NumKills += 1
              NetInterface.PackAndWriteOp(Globals.NetworkOP.OP_DIED, 
                                          player.ID.to_bytes(8,'little'),player.Address)
开发者ID:AdrianoDiDio,项目名称:PyBomberman,代码行数:38,代码来源:PyBomberman.py


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