game.py 文件源码

python
阅读 20 收藏 0 点赞 0 评论 0

项目:Qaf 作者: jonathanabennett 项目源码 文件源码
def draw_screen(self):
        """This function will handle all screen renders. It takes a list of
        things and a grid (with is a list of lists of tiles. It will draw them
        all on the screen. The next step will be splitting out messaging and
        finally Character sheet display."""
        x_offset = floor((self.width - 20) / 2)
        minX = self.player.x - x_offset
        maxX = self.player.x + x_offset - 1
        if minX < 0: minX = 0
        if maxX > self.current_level.width: maxX = self.current_level.width
        if maxX - minX < self.width - 20:
            if minX == 0: maxX = self.width-20
            else: minX = maxX - (self.width - 20)

        y_offset = floor((self.height - 10) / 2)
        minY = self.player.y - y_offset
        maxY = self.player.y + y_offset - 1
        if minY < 0: minY = 0
        if maxY > self.current_level.height: maxY = self.current_level.height
        if maxY - minY < self.height - 10:
            if minY == 0: maxY = self.height-10
            else: minY = maxY - (self.height-10)

        log.info("minX = %s, maxX = %s, minY = %s, maxY = %s" % (minX, maxX,
                                                                 minY, maxY))

        grid,things = self.current_level.full_render(minX,maxX,minY,maxY)

        for y in range(len(grid)):
            for x in range(len(grid[y])):
                wall = grid[y][x].blocked
                if wall:
                    try:
                        self.map_view.addch(y, x," ",
                                            curses.color_pair(self.color_palette["dark_wall"]))
                    except curses.error: pass
                else:
                    try:
                        self.map_view.addch(y,x," ",
                                            curses.color_pair(self.color_palette["dark_floor"]))
                    except curses.error: pass

        for thing in things:
            if thing.ai_comp:
                self.draw_thing(thing,minX,minY)
        self.draw_thing(self.player,minX,minY)

        self.msg_handler.update_messages()
        self.char_sheet.update_sheet()

        self.map_view.noutrefresh()
        curses.doupdate()
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号