Пример #1
0
 def get_closest_entity(self, fromLocation, targetClass, range=1000, validityTest=None):
     closestDist = range
     closestEntity = None
     for ent in self.entities.itervalues():
         if isinstance(ent, targetClass) and Vector2.get_distance(ent.location, fromLocation) < closestDist:
             if not validityTest or validityTest(ent):
                 closestDist = Vector2.get_distance(ent.location, fromLocation)
                 closestEntity = ent
     return closestEntity
Пример #2
0
 def get_closest_entity(self,
                        fromLocation,
                        targetClass,
                        range=1000,
                        validityTest=None):
     closestDist = range
     closestEntity = None
     for ent in self.entities.itervalues():
         if isinstance(ent, targetClass) and Vector2.get_distance(
                 ent.location, fromLocation) < closestDist:
             if not validityTest or validityTest(ent):
                 closestDist = Vector2.get_distance(ent.location,
                                                    fromLocation)
                 closestEntity = ent
     return closestEntity
Пример #3
0
 def switchVehicle(self, vehicle):
     self.speed = 0.0
     if self.vehicle == vehicle:
         self.vehicle.move(STOP)
         self.vehicle = None
         self.location = vehicle.location + Vector2(-20,0)    
     elif self.vehicle == None and Vector2.get_distance(self.location, vehicle.location) <= 50:
         self.vehicle = vehicle
         self.vehicle.start()
Пример #4
0
    def render(self, surface):
        display_x = min(
            self.dimension[0] - self.display_size[0],
            max(0, self.focussed_entity.location.x - self.display_size[0] / 2))
        display_y = min(
            self.dimension[1] - self.display_size[1],
            max(0, self.focussed_entity.location.y - self.display_size[1] / 2))
        surface.blit(
            self.background, (0, 0),
            (display_x, display_y, self.display_size[0], self.display_size[1]))

        for entity in self.entities.itervalues():
            if Vector2.get_distance(self.focussed_entity.location,
                                    entity.location) <= self.maximum_expansion:
                entity.render(surface, (display_x, display_y))

        if self.minimapVisible:
            minimapSize = (200, 100)
            minimapOffset = (10, 490)
            pygame.draw.rect(surface, (0, 0, 0),
                             pygame.Rect(minimapOffset, minimapSize))
            pygame.draw.rect(
                surface, (255, 255, 255),
                pygame.Rect((minimapOffset[0] - 1, minimapOffset[1] - 1),
                            (minimapSize[0] + 2, minimapSize[1] + 2)), 1)

            for entity in self.active_entities.itervalues():
                # render entity point on minimap
                x = minimapOffset[0] + int(
                    (minimapSize[0] * entity.location.x) / self.dimension[0])
                y = minimapOffset[1] + int(
                    (minimapSize[1] * entity.location.y) / self.dimension[1])
                if entity.name == 'player' and not entity.vehicle:
                    color = (0, 0, 255)
                    pygame.draw.circle(surface, color, (x, y), 3)
                elif entity.name == 'cat':
                    color = entity.hungerColour
                    pygame.draw.rect(surface, color, pygame.Rect((x, y),
                                                                 (2, 2)))
                elif entity.name == 'car':
                    color = (200, 200, 200)
                    pygame.draw.circle(surface, color, (x, y), 3)
Пример #5
0
    def render(self, surface):
        display_x = min(
            self.dimension[0] - self.display_size[0], max(0, self.focussed_entity.location.x - self.display_size[0] / 2)
        )
        display_y = min(
            self.dimension[1] - self.display_size[1], max(0, self.focussed_entity.location.y - self.display_size[1] / 2)
        )
        surface.blit(self.background, (0, 0), (display_x, display_y, self.display_size[0], self.display_size[1]))

        for entity in self.entities.itervalues():
            if Vector2.get_distance(self.focussed_entity.location, entity.location) <= self.maximum_expansion:
                entity.render(surface, (display_x, display_y))

        if self.minimapVisible:
            minimapSize = (200, 100)
            minimapOffset = (10, 490)
            pygame.draw.rect(surface, (0, 0, 0), pygame.Rect(minimapOffset, minimapSize))
            pygame.draw.rect(
                surface,
                (255, 255, 255),
                pygame.Rect((minimapOffset[0] - 1, minimapOffset[1] - 1), (minimapSize[0] + 2, minimapSize[1] + 2)),
                1,
            )

            for entity in self.active_entities.itervalues():
                # render entity point on minimap
                x = minimapOffset[0] + int((minimapSize[0] * entity.location.x) / self.dimension[0])
                y = minimapOffset[1] + int((minimapSize[1] * entity.location.y) / self.dimension[1])
                if entity.name == "player" and not entity.vehicle:
                    color = (0, 0, 255)
                    pygame.draw.circle(surface, color, (x, y), 3)
                elif entity.name == "cat":
                    color = entity.hungerColour
                    pygame.draw.rect(surface, color, pygame.Rect((x, y), (2, 2)))
                elif entity.name == "car":
                    color = (200, 200, 200)
                    pygame.draw.circle(surface, color, (x, y), 3)
Пример #6
0
 def check_conditions(self):
     if self.cat.pot is not None and Vector2.get_distance(self.cat.location, self.cat.destination) < 10:
         return "eating"
     return None