Pygame.py 2.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. for direction in exploration_info:
  22. intensity = exploration_info[direction]
  23. # TODO: ne pas avoir a creer d'objet, voir comment dans display
  24. pheromon = PheromonHome(object(), context)
  25. pheromon.set_direction(direction)
  26. self._draw_objects_with_decal(point, [pheromon])
  27. exploration_info = context.pheromones().get_info(point,
  28. [PHEROMON_DIRECTION,
  29. PHEROMON_DIR_EXPLO],
  30. allow_empty=True,
  31. empty_value={})
  32. for direction in exploration_info:
  33. intensity = exploration_info[direction]
  34. # TODO: ne pas avoir a creer d'objet, voir comment dans display
  35. pheromon = PheromonExploration(object(), context)
  36. pheromon.set_direction(direction)
  37. self._draw_objects_with_decal(point, [pheromon])
  38. def _key_pressed(self, key):
  39. if key == pygame.K_p:
  40. if self._is_display_pheromones:
  41. self._is_display_pheromones = False
  42. else:
  43. self._is_display_pheromones = True