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


Python Display.render方法代码示例

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


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

示例1: Game

# 需要导入模块: from display import Display [as 别名]
# 或者: from display.Display import render [as 别名]
class Game():
    def __init__(self):
        self.win = win
        self.update = False
        self.conn = conn
        self.disp = Display(win, self)
        self.inp = inp
        self.running = False
        self.worlds = {}

        self.var = Varlist()
        
        self.msg = []
        self.players = {}

        # self.get = self.varlist.getval

    def getLevel(self, pos):
        return self.worlds[pos.w].levels[pos.l]

    def getCurrentLevel(self):
        return self.getLevel(self.player.pos)

    def quit(self):
        self.conn.disconnect()
        sys.exit()

    def setup(self):
        Var('console_prefix', '>>', varlist=self.var)
        Var('chat_keeptime', 3, varlist=self.var)
        Var('hide_players', 0, varlist=self.var)
        Var('hide_ents', 0, varlist=self.var)

    def getCurrentWorld(self):
        return self.worlds[self.player.pos.w]

    def move(self, new):
        if checkMove(self.player, new, self.getCurrentLevel().map):
            self.player.pos = new
            self.conn.write({'action':'ACTION', 'type':'MOVE', 'pos':new.dump()})  
            self.disp.updaterender = True

    def updatePos(self, cid, loc):
        self.players[cid].pos = loc
        self.disp.updaterender = True

    def updateEntPos(self, eid, loc):
        self.getLevel(loc).ents[eid].pos = loc
        self.disp.updaterender = True

    def addMsg(self, msg):
        self.msg.append({'content':msg, 'type':'con', 'time':None})
        self.disp.updaterender = True

    def addChat(self, msg):
        self.msg.append({'content':msg[1], 'type':'msg', 'id':msg[0], 'time':None})
        self.disp.updaterender = True

    def addPlayer(self, plyr):
        self.players[plyr.id] = plyr
        self.disp.updaterender = True

    def rmvPlayer(self, plyr):
        del self.players[plyr]
        self.disp.updaterender = True

    def addEnt(self, data):
        if data['type'] == 'player':
            self.players[data['data']['id']] = Player(data=data['data'])
        elif data['type'] == 'mob':
            m = MobHolder(data=data['data'])
            #self.getLevel(Location(mob_types[data['data']['type']])
        self.disp.updaterender = True

    def startScreen(self):
        g = self.disp.getCenterPos('Server IP: ')
        ip = self.win.input("Server IP: ", g[0], g[1], fgcolor=BLUE)
        g = self.disp.getCenterPos('Username: ')
        name = self.win.input('Username: ', g[0], g[1], fgcolor=BLUE)
        self.conn.connect(game=self, ip=ip, name=name)

    def checkChat(self):
        ret = False
        for x, i in enumerate(self.msg):
            if i['time'] == None: i['time'] = time.time()
            elif time.time()-i['time'] >= self.var.get('chat_keeptime'):
                self.msg.pop(x)
                self.update = True
                ret = True
        return ret

    def _specloop(self):
        self.disp.render()
        if len(self.conn.Q):
            self.conn.parse(self.conn.Q.popleft()[0])

    def startLoop(self):
        self.setup()
        thread.start_new_thread(self.conn.loop, ())
        self.running = True
#.........这里部分代码省略.........
开发者ID:b1naryth1ef,项目名称:Bunneh,代码行数:103,代码来源:main.py


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