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


Python Sprite.get_size方法代码示例

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


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

示例1: Menu

# 需要导入模块: from sprite import Sprite [as 别名]
# 或者: from sprite.Sprite import get_size [as 别名]
class Menu(object):
    _entries = {
        0:"",
        1:"",
        2:""
    }

    def paint(self):
        rect2 = pygame.Rect(self._window_size[0]/2 - 190, self._window_size[1]/2 - 110, 400, 200)
        pygame.draw.rect(self._screen, (0,150,150), rect2, 0)
        rect = pygame.Rect(self._window_size[0]/2 - 200, self._window_size[1]/2 - 100, 400, 200)
        pygame.draw.rect(self._screen, (150,150,150), rect, 0)
        for key,item in self._entries_sprite_dict.iteritems():
            item.draw(self._screen)
        self._arrow_image_left.draw(self._screen)
        self._arrow_image_right.draw(self._screen)

        pygame.display.update()

    def __init__(self, screen, window_size, title, background, option, **kwargs):
        self._screen = screen
        self._title = title
        self._background = background
        self._entries_sprite_dict = {}
        self._window_size = window_size
        self._arrow_positions = {}
        self._arrow_image_left = Sprite("./media/menu_arrow.png")
        self._arrow_image_right = Sprite(pygame.transform.rotate(self._arrow_image_left.get_image(), 180))
        self._arrow_image_size = self._arrow_image_left.get_size()
        self._option = option

        self.__add_text = (kwargs["add_text"],None)
        entry_size_y = 20
        start_y = window_size[1]/2 - len(self._entries) * (entry_size_y/2)
        i = 0
        item_nr = 0

        for key, item in self._entries.iteritems():
            if not item == " ":
                sprite = Sprite.from_text(item)
                size=sprite.get_size()
                sprite.move_to(window_size[0]/2 - size[0]/2, start_y + i * entry_size_y)
                self._entries_sprite_dict.update({item_nr:sprite})
                self._arrow_positions.update({item_nr:[pygame.Rect(sprite.get_pos()[0] - 110, sprite.get_pos()[1] +
                                                                  size[1]/2 - 6, 104, 12),
                                                       pygame.Rect(sprite.get_pos()[0] + size[0] + 6, sprite.get_pos()[1] +
                                                                   size[1]/2 - 6, 104, 12)]})
                self._arrow_image_left.set_rect(self._arrow_positions[0][0])
                self._arrow_image_right.set_rect(self._arrow_positions[0][1])
                item_nr += 1
            i += 1

    def show(self):
        option = self._option
        max_option = max(self._entries.keys())

        exit = False

        self._arrow_image_left.set_rect(self._arrow_positions[option][0])
        self._arrow_image_right.set_rect(self._arrow_positions[option][1])

        while not exit:

            for event in pygame.event.get():
                if event.type == pygame.QUIT: sys.exit()

                if event.type is pygame.KEYDOWN:
                    key = pygame.key.name(event.key)

                    if key == "down":
                        if not option == max_option - 1:
                            option += 1
                        else:
                            option = 0

                    if key == "up":
                        if not option == 0:
                            option -= 1
                        else:
                            option = max_option -1

                    self._arrow_image_left.set_rect(self._arrow_positions[option][0])
                    self._arrow_image_right.set_rect(self._arrow_positions[option][1])

                    if key == "escape":
                        option = -1
                        exit = True

                    if key == "return":
                        exit = True
            self.paint()

        return option
开发者ID:hendrikbraunwspsweden,项目名称:destroyer,代码行数:95,代码来源:menus.py


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