本文整理汇总了Python中pygame.Rect.x方法的典型用法代码示例。如果您正苦于以下问题:Python Rect.x方法的具体用法?Python Rect.x怎么用?Python Rect.x使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pygame.Rect
的用法示例。
在下文中一共展示了Rect.x方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: crop_center
# 需要导入模块: from pygame import Rect [as 别名]
# 或者: from pygame.Rect import x [as 别名]
def crop_center(image, size):
rect = Rect((0, 0), size)
res_surf = Surface(size, SRCALPHA, 32)
blit_pos = [0, 0]
if image.get_width() > rect.width:
blit_pos[0] = (-image.get_width()+rect.width) // 2
else:
rect.x = (image.get_width()-rect.width) // 2
if image.get_height() > rect.height:
blit_pos[1] = (-image.get_height()+rect.height) // 2
else:
rect.y = (image.get_height()-rect.height) // 2
print(rect)
print(blit_pos)
res_surf.blit(crop(image, rect), blit_pos)
return res_surf
示例2: makeRooms
# 需要导入模块: from pygame import Rect [as 别名]
# 或者: from pygame.Rect import x [as 别名]
def makeRooms(self):
numRooms = random.randint(NUMROOMSMIN, NUMROOMSMAX)
for roomID in range(numRooms):
attempts = 0
room = Rect(0,0,0,0)
room.width = random.randint(ROOMMIN, ROOMMAX)
room.height = random.randint(ROOMMIN, ROOMMAX)
posFound = False
while not posFound:
if attempts == MAXROOMALLOCATTEMPTS:
#print("Could not resolve room placement for room %i, bailing" % (roomID+1))
break
room.x = random.randint(2, WORLDSIZE[0] - 1)
room.y = random.randint(5, WORLDSIZE[1] - 1)
if (room.x + room.width) >= (WORLDSIZE[0] - 1) or (room.y + room.height) >= (WORLDSIZE[1] - 4):
attempts += 1
continue
posFound = True
for r,w in self.roomInfo:
if r.inflate(2*ROOMSPACING, 2*ROOMSPACING).colliderect(room):
posFound = False
attempts += 1
break
if not posFound:
continue
#Place waypoint
wpX = random.randint(room.x + 1 + int(CORTHICKNESS / 2), room.x + room.width - 1 - int(CORTHICKNESS / 2))
wpY = random.randint(room.y + 1 + int(CORTHICKNESS / 2), room.y + room.height - 1 - int(CORTHICKNESS / 2) )
self.roomInfo.append( (room, (wpX, wpY)) )
for x in range(room.x, room.x + room.width):
for y in range(room.y, room.y + room.height):
self.mapGrid[x][y] = "#"
#Sort rooms in order of Y coordinates
self.roomInfo.sort(key=lambda r: r[0].y)