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


Python Vector.toIntArr方法代码示例

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


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

示例1: __init__

# 需要导入模块: from vector import Vector [as 别名]
# 或者: from vector.Vector import toIntArr [as 别名]
class Motive:
  def __init__(self, pos, direction, t):
    self.pos = Vector(pos)
    self.direction = direction
    self.type = t
    self.speed = random()
    self.age = pygame.time.get_ticks()
    self.ttl = 15000 + 5000 * random()

    self.color = (255, 255, 255)

    size = 1
    if self.type == MotiveType.Pedestrian:
      self.size = int(size)
    if self.type == MotiveType.Car:
      self.size = [int(size*2 + random()), int(size*2 + random() * 2)]

  def update(self, dt, checkForCollision):
    newPos = self.pos + self.direction * self.speed

    if checkForCollision(newPos):
      self.direction = choice([self.direction.getLeftPerpendicular(), self.direction.getRightPerpendicular()])
    else:
      self.pos = newPos


  def draw(self, screen):
    if self.type == MotiveType.Pedestrian:
      pygame.draw.circle(screen, self.color, self.pos.toIntArr(), self.size)
    if self.type == MotiveType.Car:
      pygame.draw.rect(screen, self.color, self.pos.toIntArr() + self.size)
开发者ID:fablab-ka,项目名称:cityscape,代码行数:33,代码来源:sandbox.py

示例2: __init__

# 需要导入模块: from vector import Vector [as 别名]
# 或者: from vector.Vector import toIntArr [as 别名]
class Motive:
  def __init__(self, start, target, targetId, t):
    self.pos = Vector(start)
    self.start = start
    self.target = target
    self.targetId = targetId
    self.type = t
    self.speed = random()
    self.age = pygame.time.get_ticks()
    self.ttl = 15000 + 5000 * random()

    self.arrivedAtTarget = False
    self.minTargetDistance = 10
    self.color = (255, 0, 0)

    size = 1
    if self.type == MotiveType.Pedestrian:
      self.size = int(size)
    if self.type == MotiveType.Car:
      self.size = [int(size + random() * 2), int(size + random() * 2)]

  def update(self, dt):
    direction = (self.target - self.start).getNormalized()
    variation = 0
    if random() > 0.5:
      variation = direction.getLeftPerpendicular()
    else:
      variation = direction.getRightPerpendicular()

    direction = (direction * (random() * 10) + variation * random()).getNormalized()

    self.pos += direction * self.speed

    self.arrivedAtTarget = (self.target - self.pos).getLengthSqr() < self.minTargetDistance

  def draw(self, screen):
    if self.type == MotiveType.Pedestrian:
      pygame.draw.circle(screen, self.color, self.pos.toIntArr(), self.size)
    if self.type == MotiveType.Car:
      pygame.draw.rect(screen, self.color, self.pos.toIntArr() + self.size)
开发者ID:fablab-ka,项目名称:cityscape,代码行数:42,代码来源:simulator.py

示例3: isSet

# 需要导入模块: from vector import Vector [as 别名]
# 或者: from vector.Vector import toIntArr [as 别名]
  def isSet(self, pos):
    if not self.mapData:
      print "no mapData yet"
      return True

    if not isinstance(pos, Vector):
      pos = Vector(pos)

    if pos.x < 0 or pos.y < 0:
      return True
    if pos.x >= self.screenDim[0] or pos.y >= self.screenDim[1]:
      return True

    px = self.mapData.get_at(pos.toIntArr())
    return (px.r + px.g + px.b) < 600
开发者ID:fablab-ka,项目名称:cityscape,代码行数:17,代码来源:blobmanager.py


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