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


Python Rect.x方法代码示例

本文整理汇总了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
开发者ID:CyboticCatfish,项目名称:code404-server,代码行数:20,代码来源:image.py

示例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)
开发者ID:nojan1,项目名称:closeQuarters,代码行数:46,代码来源:levelgen.py


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