visualisation.py 3.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. from xyworld.display.object.pygame.PygameImage import PygameImage
  2. from xyworld.display.object.pygame.DirectionnedImage import DirectionnedImage
  3. from intelligine.synergy.object.Bug import Bug
  4. from intelligine.synergy.object.ant.Ant import Ant
  5. from intelligine.sandbox.colored.BlueAnt import BlueAnt
  6. from intelligine.sandbox.colored.RedAnt import RedAnt
  7. from intelligine.sandbox.colored.GreenAnt import GreenAnt
  8. from intelligine.synergy.object.Rock import Rock
  9. from os import getcwd
  10. from synergine.metas import metas
  11. from intelligine.cst import PREVIOUS_DIRECTION
  12. # TODO: Analyser les procedes ici pour proposer des outils dans le framework
  13. ant = PygameImage.from_filepath(getcwd()+'/intelligine/display/pygame/image/ant.png')
  14. dead_ant = PygameImage.from_filepath(getcwd()+'/intelligine/display/pygame/image/dead_ant.png')
  15. red_ant = PygameImage.from_filepath(getcwd()+'/intelligine/display/pygame/image/red_ant.png')
  16. green_ant = PygameImage.from_filepath(getcwd()+'/intelligine/display/pygame/image/green_ant.png')
  17. blue_ant = PygameImage.from_filepath(getcwd()+'/intelligine/display/pygame/image/blue_ant.png')
  18. dead_red_ant = PygameImage.from_filepath(getcwd()+'/intelligine/display/pygame/image/dead_red_ant.png')
  19. dead_green_ant = PygameImage.from_filepath(getcwd()+'/intelligine/display/pygame/image/dead_green_ant.png')
  20. dead_blue_ant = PygameImage.from_filepath(getcwd()+'/intelligine/display/pygame/image/dead_blue_ant.png')
  21. bug = PygameImage.from_filepath(getcwd()+'/intelligine/display/pygame/image/ant.png')
  22. rock = PygameImage.from_filepath(getcwd()+'/intelligine/display/pygame/image/rock.png')
  23. directions_ant = DirectionnedImage(ant)
  24. directions_red_ant = DirectionnedImage(red_ant)
  25. directions_blue_ant = DirectionnedImage(blue_ant)
  26. directions_green_ant = DirectionnedImage(green_ant)
  27. def bug_direction(bug):
  28. if bug.get_life_points() <= 0:
  29. return dead_ant
  30. try:
  31. previous_direction = metas.value.get(PREVIOUS_DIRECTION, bug.get_id())
  32. except KeyError:
  33. previous_direction = 14
  34. return directions_ant.get_for_direction(previous_direction)
  35. def red_ant_direction(bug):
  36. if bug.get_life_points() <= 0:
  37. return dead_red_ant
  38. try:
  39. previous_direction = metas.value.get(PREVIOUS_DIRECTION, bug.get_id())
  40. except KeyError:
  41. previous_direction = 14
  42. return directions_red_ant.get_for_direction(previous_direction)
  43. def blue_ant_direction(bug):
  44. if bug.get_life_points() <= 0:
  45. return dead_blue_ant
  46. try:
  47. previous_direction = metas.value.get(PREVIOUS_DIRECTION, bug.get_id())
  48. except KeyError:
  49. previous_direction = 14
  50. return directions_blue_ant.get_for_direction(previous_direction)
  51. def green_ant_direction(bug):
  52. if bug.get_life_points() <= 0:
  53. return dead_green_ant
  54. try:
  55. previous_direction = metas.value.get(PREVIOUS_DIRECTION, bug.get_id())
  56. except KeyError:
  57. previous_direction = 14
  58. return directions_green_ant.get_for_direction(previous_direction)
  59. visualisation = {
  60. 'window': {},
  61. 'objects': {
  62. RedAnt: {
  63. 'default': red_ant,
  64. 'callbacks': [red_ant_direction]
  65. },
  66. BlueAnt: {
  67. 'default': blue_ant,
  68. 'callbacks': [blue_ant_direction]
  69. },
  70. GreenAnt: {
  71. 'default': green_ant,
  72. 'callbacks': [green_ant_direction]
  73. },
  74. Ant: {
  75. 'default': ant,
  76. 'callbacks': [bug_direction]
  77. },
  78. Bug: {
  79. 'default': bug,
  80. 'callbacks': [bug_direction]
  81. },
  82. Rock: {
  83. 'default': rock
  84. }
  85. }
  86. }