Pygame.py 2.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. ######
  16. # refact
  17. point_pheromones_infos = context.metas.value.get(PHEROMON_INFOS, point, allow_empty=True,
  18. empty_value={})
  19. # TODO: Tout ca dans un get_pheromone_info(PHEROMON_DIRECTION, PHEROMON_DIR_EXPLO, direction)
  20. #point_pheromones_infos={}
  21. if PHEROMON_DIRECTION not in point_pheromones_infos:
  22. point_pheromones_infos[PHEROMON_DIRECTION] = {}
  23. direction_pheromone = point_pheromones_infos[PHEROMON_DIRECTION]
  24. if PHEROMON_DIR_EXPLO not in direction_pheromone:
  25. direction_pheromone[PHEROMON_DIR_EXPLO] = {}
  26. exploration_info = direction_pheromone[PHEROMON_DIR_EXPLO]
  27. ########
  28. for direction in exploration_info:
  29. intensity = exploration_info[direction]
  30. # TODO: ne pas avoir a creer d'objet, voir comment dans display
  31. pheromon = Pheromon(object(), context)
  32. pheromon.set_direction(direction)
  33. self._draw_objects_with_decal(point, [pheromon])
  34. def _key_pressed(self, key):
  35. if key == pygame.K_p:
  36. if self._is_display_pheromones:
  37. self._is_display_pheromones = False
  38. else:
  39. self._is_display_pheromones = True