Exemple #1
0
  def draw(self, color=None, width=0):
    if self.initialized:
      if color is None:
        color = self.color
      pygame.draw.polygon(
        pygame.display.get_surface(),
        color,
        transform_points_for_pygame(self.vertices),
        width
      )

      # Label the hexagons according to their address id.
      label_font = pygame.font.SysFont("monospace", 12)
      label = label_font.render(
        str(self.id),
        True,
        [255-c for c in self.color]
      )
      x = float(self.northwest_vertex[0])
      y = float(self.northwest_vertex[1])
      p = (x+13, y-13)
      label_top_left_corner = transform_points_for_pygame([p])[0]
      pygame.display.get_surface().blit(
        label,
        label_top_left_corner
      )
Exemple #2
0
 def draw_vertices(self, color=None):
   if self.initialized:
     if color is None:
       color = self.color
     map(
       lambda p: pygame.draw.circle(pygame.display.get_surface(), color, p, 4),
       transform_points_for_pygame(self.vertices)
     )
Exemple #3
0
 def update(self):
   x, y = self.coords[0]
   center = (
     x + self.movement_offset*self.offset[0],
     y + self.movement_offset*self.offset[1]
   )
   self.rect.center = transform_points_for_pygame([center])[0]
   self._set_coords(center)
   self.offset = (0,0)
Exemple #4
0
  def __init__(self, char, center, cells):
    pygame.sprite.Sprite.__init__(self)
    Point.__init__(self, center)
    self.mobility = 1
    # This is the unique name/address of the phone.
    self.id = char

    # These are all of the PCS cells in which this phone can be within.
    self.cells = cells

    # This is the geographic cell in which the phone is within. The center of
    #  this cell has a base station with which this phone can connect with
    #  to make calls, register its location, etc.
    self.num_writes = 0
    self.num_reads = 0
    self.PCS_cell = None
    for h in self.cells:
      if h.contains(self):
        self.PCS_cell = h

    # These member variables are required for this Phone class to be a
    #  sprite.
    self.image = pygame.image.load(
      os.path.join(ABS_PATH, "phone.png")
    ).convert_alpha()
    self.rect = self.image.get_rect()
    self.rect.center = transform_points_for_pygame([center])[0]

    # If the phone is moved, the offset vector will be updated. It is a
    #  direction vector.
    self.offset = (0,0)

    # The label is drawn on top of the sprite.
    label_font = pygame.font.SysFont("monospace", 15)
    self.label = label_font.render(char, True, (255, 255, 255))
    self.draw_text()