Esempio n. 1
0
 def removeAt(self, pos):
   for blob in self.blobs:
     dist = Vector.distanceSqr(blob.pos, pos)
     print dist, blob.radius ** 2
     if dist < blob.radius ** 2:
       self.blobs.remove(blob)
       self.blobDict.pop(blob.id, None)
       break
Esempio n. 2
0
  def findCloseBlobs(self, blob, radius):
    result = []

    radiusSqr = radius * radius
    for otherBlob in self.blobs:
      if otherBlob.id == blob.id:
        continue

      if Vector.distanceSqr(blob.pos, otherBlob.pos) < radiusSqr:
        result.append(otherBlob)

    return result
Esempio n. 3
0
  def validate(self, blob, debug=False):
    result = True
    pos = blob.pos
    if self.isSet(pos):
      if debug:
        print "isset fail"
      result = False
    else:
      radius = blob.radius
      sqrRadius = radius**2
      for x in range(-radius, radius):
        for y in range(-radius, radius):
          if x*x + y*y <= sqrRadius:
            cPos = pos + [x, y]
            if self.isSet(cPos):
              if debug:
                print "wall collision fail"
              result = False
              break

        if not result:
          break

      for otherBlob in self.blobs:
        if otherBlob.id == blob.id:
          continue

        distance = Vector.distanceSqr(otherBlob.pos, blob.pos)
        if distance < (otherBlob.radius + blob.radius) ** 2:
          if debug:
            print "blob collision fail"
          result = False
          break


    return result