本文整理汇总了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()))
示例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)
示例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)