Pygame.py 2.5KB

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