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


Python Surface.get_rect方法代码示例

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


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

示例1: __init__

# 需要导入模块: from pygame.surface import Surface [as 别名]
# 或者: from pygame.surface.Surface import get_rect [as 别名]
class GameUI:
    def __init__(self, mainchar):
        self.bg = Surface((600, 1600))
        self.statusbar = Surface((200, 600))
        self.mainchar = mainchar
        self.widget = []
        self.create_bg()
    
    def create_bg(self):
        rbg = self.bg.get_rect()
        bgimg = media.load_image('bg.png').convert()
        rbgimg = bgimg.get_rect()
        columns = int(rbg.width / rbgimg.width) + 1
        rows = int(rbg.height / rbgimg.height) + 1
        
        for y in xrange(rows):
            for x in xrange(columns):
                if x == 0 and y > 0:
                    rbgimg = rbgimg.move([-(columns -1 ) * rbgimg.width, rbgimg.height])
                if x > 0:
                    rbgimg = rbgimg.move([rbgimg.width, 0])
                self.bg.blit(bgimg, rbgimg)
                        
    def update(self):
        r = pygame.rect.Rect(0, 0, 200, 100)
        
        for w in self.widget:
            w.update()
            self.statusbar.blit(w.image, r)
            r = r.move((0, 100))
开发者ID:benoxoft,项目名称:pitfairyhunter,代码行数:32,代码来源:ui.py

示例2: LoadingScene

# 需要导入模块: from pygame.surface import Surface [as 别名]
# 或者: from pygame.surface.Surface import get_rect [as 别名]
class LoadingScene(AbstractScene):
    """
    @type image: SurfaceType
    @type rect: pygame.rect.RectType
    """

    image = None
    rect = None

    def __init__(self, manager):
        """
        @type manager: slg.application.manager.Manager
        """
        super().__init__(manager)
        self.group = GameSceneGroup(self)
        image = pygame.image.load(os.path.join(GUI_DIR, 'loading_screen.jpg'))
        self.image = Surface(self._manager.get_display().get_size())
        self.rect = pygame.rect.Rect(self.image.get_rect())
        image_size = image.get_size()
        surface_size = self.image.get_size()
        x = int((image_size[0] - surface_size[0]) / 2)
        y = int((image_size[1] - surface_size[1]) / 2)
        if x < 0 and y < 0:
            image = pygame.transform.scale(image, surface_size)
            x, y = 0, 0
        elif x <= 0 <= y:
            image = pygame.transform.scale(image, (surface_size[0], image_size[1]))
            x = 0
        elif y <= 0 <= x:
            image = pygame.transform.scale(image, (image_size[0], surface_size[1]))
            y = 0
        styles = {'font': 'alger', 'font_size': 40, 'align': [TextWidget.CENTER, TextWidget.CENTER]}
        text = TextWidget(**styles)
        text.set_text("""Loading...
Please wait""")
        self.image.blit(image, (-x, -y))
        text.draw(self.image)

    def handle_events(self, events):
        self.group.handle_events(events)
        for e in events:
            if e.type == KEYDOWN:
                self.handle_keypress(e.key, pygame.key.get_mods())

    def handle_keypress(self, key, modificated):
        if key == K_SPACE and self._manager.state < GAME_STATE_LOADING:
            ChangeState(int(not bool(self._manager.state))).post()

        if key == K_m and modificated and pygame.KMOD_CTRL:
            Selector(self._manager.get_display(), self.group)
            ChangeState(GAME_STATE_PAUSED).post()

    def draw(self):
        display_surface = self._manager.get_display()
        display_surface.blit(self.image, (0, 0))
        self.group.update(display_surface)
        self.group.draw(display_surface)
开发者ID:ImmRanneft,项目名称:pygame_example,代码行数:59,代码来源:loadingscene.py

示例3: PointerPoint

# 需要导入模块: from pygame.surface import Surface [as 别名]
# 或者: from pygame.surface.Surface import get_rect [as 别名]
class PointerPoint(pygame.sprite.Sprite):
    """moves a clenched fist on the screen, following the mouse"""
    def __init__(self):
        pygame.sprite.Sprite.__init__(self) #call Sprite initializer
        self.image = Surface((1, 1))
        self.rect = self.image.get_rect()

    def update(self):
        "move the fist based on the mouse position"
        pos = pygame.mouse.get_pos()
        self.rect.midtop = pos
开发者ID:ElleryAree,项目名称:OneWayTrip,代码行数:13,代码来源:MainFrame.py

示例4: __init__

# 需要导入模块: from pygame.surface import Surface [as 别名]
# 或者: from pygame.surface.Surface import get_rect [as 别名]
    def __init__(self,surface : Surface, dimension:Rect = None ):
        if dimension == None:
            dimension = surface.get_rect()

        self.surface = surface
        self.dimension = dimension

        self.__IDCounter = 0

        self.actors = []
        self.bullets = []
        self.power_ups = []

        self.Timer = Timer()

        self.Timer.subscribe(self.Simulate)
        self.Timer.subscribe(self.Paint)
开发者ID:zannabianca1997,项目名称:total_shoot_out,代码行数:19,代码来源:Arena.py

示例5: getEndGameSplash

# 需要导入模块: from pygame.surface import Surface [as 别名]
# 或者: from pygame.surface.Surface import get_rect [as 别名]
def getEndGameSplash(winnerName=None, winnerColor=None):
    """If winningName and winnerColor are both None,
       display a tie game screen.
    """

    screen = Display.get_surface()
    splashGroup = SpriteGroup()
    if winnerName != None and winnerColor != None:
        # Create winning bomberman image
        fatalityRect = Rect((0, 0, 500, 500))
        fatalityRect.centerx = screen.get_rect().centerx
        fatalityRect.centery = screen.get_rect().centery
        fatalityAnimation = WorldlessWidget(Surface((500, 500)), fatalityRect)
        fatalImage = pygame.image.load("images/fatality.png").convert()
        fatalImage.set_colorkey(LAVENDER)
        bmanColor = Surface((fatalImage.get_width(), fatalImage.get_height()))
        bmanColor.fill(winnerColor)
        bmanColor.blit(fatalImage, bmanColor.get_rect())
        winnerFrames = createFrames(bmanColor)
        fatalityAnimation.startAnimation(winnerFrames, 0, 12)
        splashGroup.add(fatalityAnimation)

        # Create text for winning player
        winnerText = TextBar(winnerName + " Wins!", (0, 0, 200, 50), 50)
        imgWidth = winnerText.image.get_width()
        winnerText.rect.left = (screen.get_size()[X] - imgWidth) / 2
        splashGroup.add(winnerText)
    else:
        tieText = TextBar("TIE GAME!", (0, 20, 250, 50), 35)
        imgWidth = tieText.image.get_width()
        tieText.rect.left = (screen.get_size()[X] - imgWidth) / 2
        splashGroup.add(tieText)

    escMessage = TextBar("Press Escape to exit.", (0, 60, 250, 50), 25)
    imgWidth = escMessage.image.get_width()
    escMessage.rect.left = (screen.get_size()[X] - imgWidth) / 2
    splashGroup.add(escMessage)

    pressKeyText = TextBar(
        "Press a key or button when ready. Next round will start when everyone is ready.", (0, 90, 250, 50), 25
    )
    imgWidth = pressKeyText.image.get_width()
    pressKeyText.rect.left = (screen.get_size()[X] - imgWidth) / 2
    splashGroup.add(pressKeyText)

    return splashGroup
开发者ID:bry,项目名称:pybomber2,代码行数:48,代码来源:splashes.py

示例6: render

# 需要导入模块: from pygame.surface import Surface [as 别名]
# 或者: from pygame.surface.Surface import get_rect [as 别名]
    def render(self):
        """
        generate an image suitable to represnt this monster.
        return Rect(pos[0] - radius, pos[1] - radius, radius * 2, radius * 2)
        
        the image will be used in battle screens
        """

        d = self.mDNA.d
        color = (200,200,200)

        scratch = Surface((150, 150))
        s = Surface((150,150))
        s.lock()

        body_rect = body(s, d, (40,40))

        #draw.rect(s, color, body_rect, 2)

        if d["limbNum"] > 0:

            # draw one limb to see how big it is
            limb_rect = limb(scratch, d, (0, 0))

            t = d["limbLocation"]
            if t == 0:
                x, y = body_rect.bottomleft
                y -= body_rect.height / 4
            else:
                x, y = body_rect.midleft

            dx = body_rect.width / d["limbNum"]
            for i in range(0, d["limbNum"]):
                limb_rect = limb(s, d, (x, y))
                x += dx

        t = d["headLocation"]
        if t == 0:
            x, y = body_rect.midleft
        elif t == 1:
            x, y = body_rect.topleft
            y -= body_rect.height / 4
        else:
            x, y = body_rect.topleft

        head_rect = head(s, d, (x, y))
        x, y = head_rect.center
        y = y + head_rect.height / 6
        mouth_rect = mouth(s, d, (x, y))

        t = d["eyeLocation"]
        if t == 0:
            x, y = head_rect.center
            y -= head_rect.height / 4
        else:
            x, y = head_rect.topleft

        for i in range(0, d["eyeNum"]):
            eye = MonsterEye(d)
            eye.rect.center = (x, y)
            eye.render()
            self.parts.append(eye)
            x += (d["eyeSkill"] + 1) * 5

        s.unlock()

        # draw the parts onto the monster
        [ s.blit(part.image, part.rect) for part in self.parts ]

        self.image = s
        self.rect = s.get_rect()
开发者ID:MacLeek,项目名称:mh,代码行数:73,代码来源:mob.py

示例7: __init__

# 需要导入模块: from pygame.surface import Surface [as 别名]
# 或者: from pygame.surface.Surface import get_rect [as 别名]
class GameUI:
    def __init__(self, mainchar):
        self.bg = Surface((800, 600))
        self.mainchar = mainchar
        self.layer = self.create_layer()
        self.top = self.create_top()
        self.bottom = self.create_bottom()
        self.scroll = 0
        self.scroll_top = 0
        
    def create_layer(self):
        bgimg = media.load_image('bg.png').convert()
        rbgimg = bgimg.get_rect()
        rows = int(600 / rbgimg.height) + 2
        
        layer = Surface((rbgimg.width, 600))
        for y in xrange(rows):
            layer.blit(bgimg, rbgimg)
            rbgimg = rbgimg.move([0, rbgimg.height])
        return layer
    
    def create_top(self):
        bgimg = media.load_image('tile_wall.png').convert()
        rbgimg = bgimg.get_rect()
        self.top_size = rbgimg.width
        cols = int(1000 / rbgimg.width)
        
        top = Surface((1000, rbgimg.height))
        for x in xrange(cols):
            top.blit(bgimg, rbgimg)
            rbgimg = rbgimg.move([rbgimg.width, 0])
        return top
    
    def create_bottom(self):
        bgimg = media.load_image('tile_wall.png').convert()
        bgimg = pygame.transform.flip(bgimg, False, True)
        rbgimg = bgimg.get_rect()
        cols = int(1000 / rbgimg.width)
        
        top = Surface((1000, rbgimg.height))
        for x in xrange(cols):
            top.blit(bgimg, rbgimg)
            rbgimg = rbgimg.move([rbgimg.width, 0])
        return top
    
    def update(self, tick):
        self.scroll += tick / 6
        self.scroll_top += tick / 6
        
        rlayer = self.layer.get_rect()
        rlayer = rlayer.move((-self.scroll, -18))
        columns = int(800 / rlayer.width) + 2
        for x in xrange(columns):
            self.bg.blit(self.layer, rlayer)
            rlayer = rlayer.move((rlayer.width, 0))
        if self.scroll > rlayer.width:
            self.scroll -= rlayer.width
        
        rtop = self.top.get_rect()
        rbottom = self.bottom.get_rect()
        
        rtop = rtop.move((-self.scroll_top, 6))
        rbottom = rbottom.move((-self.scroll_top, self.bg.get_rect().height - rbottom.height - 6))
        self.bg.blit(self.top, rtop)
        self.bg.blit(self.bottom, rbottom)
            
        if self.scroll_top > self.top_size:
            self.scroll_top -= self.top_size
开发者ID:benoxoft,项目名称:mti880handcopter,代码行数:70,代码来源:ui.py


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