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


Python Graphics.toolimg方法代码示例

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


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

示例1: renderhud

# 需要导入模块: from graphics import Graphics [as 别名]
# 或者: from graphics.Graphics import toolimg [as 别名]
    def renderhud(inventory, inventoryqty, inventoryselected, inventoryopen, windowsize, fps, playerhealth):    #Creates the heads up display surface
        '''Creates and returns HUD'''
        #in: list of 40xint, int 0-9 , bool, tuple of 2 int
        #out: Surface object
        invsurf = pygame.Surface(windowsize, pygame.SRCALPHA, 32)
        text = pygame.font.Font(None, 15).render("FPS:" + str(fps)[0:4], 1, (84, 101, 112))
        invsurf.blit(text, (20,10)) 
        
        slotsize = (40,40)
        slotcolor = (42,42,160)
        slotnumcolor = (220, 220, 220)
        slotnumcolorselected = (40, 200, 40)
        slotnumsize = 16
        slotalpha = 180
        slotoffset = (8,8)
        slotoffset0 = (20, 20)
        
        #inventory
        if not inventoryopen:
            for slot in range(10):
                    slotimg = pygame.Surface(slotsize)
                    slotimg.fill(slotcolor)
#                    if inventory[slot] < 256:
                    slotimg.blit(Graphics.toolimg(inventory[slot]), (0,0))
                    slotimg.set_alpha(slotalpha)
                    slotimg.blit(pygame.font.Font(None, slotnumsize).render(str((slot +1)if slot < 9 else 0), 1, slotnumcolor if not slot == inventoryselected else slotnumcolorselected), (2,2))
                    slotimg.blit(pygame.font.Font(None, slotnumsize).render(str(inventoryqty[slot]), 1, slotnumcolor if not slot == inventoryselected else slotnumcolorselected), (2,28))
                    invsurf.blit(slotimg, (slot * (slotsize[0] + slotoffset[0]) + slotoffset0[0], slotoffset0[1]))

        elif inventoryopen:
            for row in range(4):
                for slot in range(10):
                    slotimg = pygame.Surface(slotsize)
                    slotimg.fill(slotcolor)
                    slotimg.blit(Graphics.toolimg(inventory[slot + 10*row]), (0,0))
                    slotimg.set_alpha(slotalpha)
                    if row ==0:
                        slotimg.blit(pygame.font.Font(None, slotnumsize).render(str(slot +1), 1, slotnumcolor if not slot == inventoryselected else slotnumcolorselected), (2,2))
                    slotimg.blit(pygame.font.Font(None, slotnumsize).render(str(inventoryqty[slot +10*row]), 1, slotnumcolor if not slot == inventoryselected else slotnumcolorselected), (2,28))
                    invsurf.blit(slotimg, (slot * (slotsize[0] + slotoffset[0]) + slotoffset0[0], row * (slotsize[1] + slotoffset[1]) + slotoffset0[1]))
        
        #health hearts
        for i in range(playerhealth[1] / 20):
            if playerhealth[0] / 20:
                playerhealth[0] -=20
                invsurf.blit(Graphics.hearts[0], (windowsize[0] - 46, 20 + 32 *i))
            elif playerhealth[0] / 10:
                playerhealth[0] -=10
                invsurf.blit(Graphics.hearts[1], (windowsize[0] - 46, 20 + 32 *i))
            else:
                invsurf.blit(Graphics.hearts[2], (windowsize[0] - 46, 20 + 32 *i))
                
        return invsurf
开发者ID:FlyOHolic,项目名称:PyBlox,代码行数:55,代码来源:game.py


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