Pygame.py 2.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. from intelligine.core.exceptions import NoPheromone
  2. from xyzworld.display.Pygame import Pygame as XyzPygame
  3. import pygame
  4. from intelligine.cst import PHEROMON_INFOS, PHEROMON_DIRECTION, PHEROMON_DIR_HOME, PHEROMON_DIR_EXPLO, PHEROMON_POSITIONS
  5. from intelligine.synergy.object.ant.PheromonExploration import PheromonExploration
  6. from intelligine.synergy.object.ant.PheromonHome import PheromonHome
  7. class Pygame(XyzPygame):
  8. def __init__(self, config, context):
  9. super().__init__(config, context)
  10. self._is_display_pheromones = False
  11. def receive(self, synergy_object_manager, context):
  12. super().receive(synergy_object_manager, context)
  13. if self._is_display_pheromones:
  14. self._display_pheromones(context.metas.list.get(PHEROMON_POSITIONS, PHEROMON_POSITIONS, allow_empty=True), context)
  15. def _display_pheromones(self, pheromones_positions, context):
  16. # TODO: Code de test bordelique !
  17. for point in pheromones_positions:
  18. flavour = context.pheromones().get_flavour(point)
  19. try:
  20. flavour.get_pheromone(category=PHEROMON_DIRECTION, type=PHEROMON_DIR_HOME)
  21. pheromon = PheromonHome(object(), context)
  22. pheromon.set_direction(11) # TODO: plus de direction avec ces nlles pheromones
  23. self._draw_objects_with_decal(point, [pheromon])
  24. except NoPheromone:
  25. pass
  26. try:
  27. flavour.get_pheromone(category=PHEROMON_DIRECTION, type=PHEROMON_DIR_EXPLO)
  28. pheromon = PheromonExploration(object(), context)
  29. pheromon.set_direction(11) # TODO: plus de direction avec ces nlles pheromones
  30. self._draw_objects_with_decal(point, [pheromon])
  31. except NoPheromone:
  32. pass
  33. def _key_pressed(self, key):
  34. if key == pygame.K_p:
  35. if self._is_display_pheromones:
  36. self._is_display_pheromones = False
  37. else:
  38. self._is_display_pheromones = True