Pygame.py 1.7KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. from xyzworld.display.Pygame import Pygame as XyzPygame
  2. import pygame
  3. from intelligine.cst import PHEROMON_INFOS, PHEROMON_DIRECTION, PHEROMON_DIR_EXPLO, PHEROMON_POSITIONS
  4. from intelligine.synergy.object.ant.Pheromon import Pheromon
  5. class Pygame(XyzPygame):
  6. def __init__(self, config, context):
  7. super().__init__(config, context)
  8. self._is_display_pheromones = False
  9. def receive(self, synergy_object_manager, context):
  10. super().receive(synergy_object_manager, context)
  11. if self._is_display_pheromones:
  12. self._display_pheromones(context.metas.list.get(PHEROMON_POSITIONS, PHEROMON_POSITIONS, allow_empty=True), context)
  13. def _display_pheromones(self, pheromones_positions, context):
  14. for point in pheromones_positions:
  15. exploration_info = context.pheromones().get_info(point,
  16. [PHEROMON_DIRECTION,
  17. PHEROMON_DIR_EXPLO],
  18. allow_empty=True,
  19. empty_value={})
  20. for direction in exploration_info:
  21. intensity = exploration_info[direction]
  22. # TODO: ne pas avoir a creer d'objet, voir comment dans display
  23. pheromon = Pheromon(object(), context)
  24. pheromon.set_direction(direction)
  25. self._draw_objects_with_decal(point, [pheromon])
  26. def _key_pressed(self, key):
  27. if key == pygame.K_p:
  28. if self._is_display_pheromones:
  29. self._is_display_pheromones = False
  30. else:
  31. self._is_display_pheromones = True