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


Python Cell.owner方法代码示例

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


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

示例1: parse_updates

# 需要导入模块: from cell import Cell [as 别名]
# 或者: from cell.Cell import owner [as 别名]
    def parse_updates(self):
        b = self.buffer
        current_time = time.time()
        while True:
            id = b.read_int()

            if id == 0:
                break

            x = b.read_short()
            y = b.read_short()
            size = b.read_short()

            red = b.read_byte()
            green = b.read_byte()
            blue = b.read_byte()

            color = (red, green, blue)

            byte = b.read_byte()

            virus = (byte & 1)
            agitated = (byte & 16)  # what is this?

            # skipping bytes, no idea what the purpose is
            if (byte & 2):
                b.skip(4)
            elif (byte & 4):
                b.skip(8)
            elif (byte & 8):
                b.skip(16)

            # read name
            name = b.read_string()
            
            # if cell is not known globally:
            #   create global instance
            # if cell in self.ids:
            #   set owner to self

            # check if this cell is known globally
            if self.game.has_cell(id):
                # known globally

                # update global cell
                cell = self.game.get_cell(id)
                #print(str(current_time - cell.last_update))

                t = current_time - cell.last_update

                if (t > 0.0):

                  vx = (float(x) - float(cell.x))/t
                  vy = (float(y) - float(cell.y))/t

                  cell.vx = (vx + cell.vx)/2.0
                  cell.vy = (vy + cell.vy)/2.0

                  v = math.sqrt(cell.vx*cell.vx + cell.vy*cell.vy)
                  max_velocity = 800

                  if v > max_velocity:
                    cell.vx *= (max_velocity/v)
                    cell.vy *= (max_velocity/v)
                    cell.x = x
                    cell.y = y
                  else:
                    cell.x += cell.vx*t
                    cell.y += cell.vy*t

                  cell.interpolated_x = cell.x
                  cell.interpolated_y = cell.y
                  cell.last_update = current_time
                
                cell.size = size
                cell.color = color
                cell.virus = virus
                cell.agitated = agitated
                cell.timestamp = self.game.timestamp
            else:
                # not known globally
                
                # create new global cell
                cell = Cell(id, x, y, size, color, virus, agitated, name)
                cell.watchers.append(self)
                cell.timestamp = self.game.timestamp

                # set owner if it is ours
                if self.has_id(id):
                    cell.owner = self
                
                # add cell to global cells
                self.game.add_cell(cell)
开发者ID:Raeon,项目名称:pygar,代码行数:95,代码来源:bot.py

示例2: parse_updates

# 需要导入模块: from cell import Cell [as 别名]
# 或者: from cell.Cell import owner [as 别名]
    def parse_updates(self):
        b = self.buffer
        while True:
            id = b.read_int()

            if id == 0:
                break

            x = b.read_short()
            y = b.read_short()
            size = b.read_short()

            red = b.read_byte()
            green = b.read_byte()
            blue = b.read_byte()

            color = (red, green, blue)

            byte = b.read_byte()

            virus = (byte & 1)
            agitated = (byte & 16)  # what is this?

            # skipping bytes, no idea what the purpose is
            if (byte & 2):
                b.skip(4)
            elif (byte & 4):
                b.skip(8)
            elif (byte & 8):
                b.skip(16)

            # read name
            name = b.read_string()
            
            # if cell is not known globally:
            #   create global instance
            # if cell in self.ids:
            #   set owner to self

            # check if this cell is known globally
            if self.game.has_cell(id):
                # known globally

                # update global cell
                cell = self.game.get_cell(id)
                cell.x = x
                cell.y = y
                cell.size = size
                cell.color = color
                cell.virus = virus
                cell.agitated = agitated
                cell.timestamp = self.game.timestamp
            else:
                # not known globally
                
                # create new global cell
                cell = Cell(id, x, y, size, color, virus, agitated, name)
                cell.watchers.append(self)
                cell.timestamp = self.game.timestamp

                # set owner if it is ours
                if self.has_id(id):
                    cell.owner = self
                
                # add cell to global cells
                self.game.add_cell(cell)
开发者ID:GeoffreyFrogeye,项目名称:pygar,代码行数:68,代码来源:bot.py


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