visualisation.py 2.8KB

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