Browse Source

Add surface draw system

Bastien Sevajol 9 years ago
parent
commit
b2c31a9995

+ 13 - 15
intelligine/display/Pygame.py View File

@@ -1,9 +1,8 @@
1 1
 from intelligine.core.exceptions import NoPheromone
2 2
 from xyzworld.display.Pygame import Pygame as XyzPygame
3 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
4
+from intelligine.cst import PHEROMON_DIRECTION, PHEROMON_DIR_HOME, PHEROMON_DIR_EXPLO, PHEROMON_POSITIONS
5
+from intelligine.display.pygame.visualisation import SURFACE_PHEROMONE_EXPLORATION, SURFACE_PHEROMONE_HOME
7 6
 
8 7
 
9 8
 class Pygame(XyzPygame):
@@ -18,23 +17,22 @@ class Pygame(XyzPygame):
18 17
             self._display_pheromones(context.metas.list.get(PHEROMON_POSITIONS, PHEROMON_POSITIONS, allow_empty=True), context)
19 18
 
20 19
     def _display_pheromones(self, pheromones_positions, context):
21
-        # TODO: Code de test bordelique !
20
+        pheromone_exploration_surface = self._object_visualizer.get_surface(SURFACE_PHEROMONE_EXPLORATION)
21
+        pheromone_home_surface = self._object_visualizer.get_surface(SURFACE_PHEROMONE_HOME)
22
+
22 23
         for point in pheromones_positions:
23
-            flavour = context.pheromones().get_flavour(point)
24
+            point_flavour = context.pheromones().get_flavour(point)
24 25
             try:
25
-                flavour.get_pheromone(category=PHEROMON_DIRECTION, type=PHEROMON_DIR_HOME)
26
-                pheromon = PheromonHome(object(), context)
27
-                pheromon.set_direction(11) # TODO: plus de direction avec ces nlles pheromones
28
-                self._draw_objects_with_decal(point, [pheromon])
26
+                point_flavour.get_pheromone(category=PHEROMON_DIRECTION, type=PHEROMON_DIR_HOME)
27
+                self.draw_surface(point, pheromone_home_surface)
29 28
             except NoPheromone:
30
-                pass
29
+                pass # No pheromone here
30
+
31 31
             try:
32
-                flavour.get_pheromone(category=PHEROMON_DIRECTION, type=PHEROMON_DIR_EXPLO)
33
-                pheromon = PheromonExploration(object(), context)
34
-                pheromon.set_direction(11) # TODO: plus de direction avec ces nlles pheromones
35
-                self._draw_objects_with_decal(point, [pheromon])
32
+                point_flavour.get_pheromone(category=PHEROMON_DIRECTION, type=PHEROMON_DIR_EXPLO)
33
+                self.draw_surface(point, pheromone_exploration_surface)
36 34
             except NoPheromone:
37
-                pass
35
+                pass # No pheromone here
38 36
 
39 37
     def _key_pressed(self, key):
40 38
         if key == pygame.K_p:

+ 14 - 22
intelligine/display/pygame/visualisation.py View File

@@ -12,6 +12,9 @@ from intelligine.synergy.object.ant.Egg import Egg
12 12
 from os import getcwd
13 13
 from xyzworld.cst import PREVIOUS_DIRECTION
14 14
 
15
+SURFACE_PHEROMONE_HOME = 'pheromone_home'
16
+SURFACE_PHEROMONE_EXPLORATION = 'pheromone_exploration'
17
+
15 18
 # TODO: Analyser les procedes ici pour proposer des outils dans le framework
16 19
 
17 20
 ant = PygameImage.from_filepath(getcwd()+'/intelligine/display/pygame/image/ant.png')
@@ -32,27 +35,14 @@ eggc3 = PygameImage.from_filepath(getcwd()+'/intelligine/display/pygame/image/eg
32 35
 eggc4 = PygameImage.from_filepath(getcwd()+'/intelligine/display/pygame/image/egg_c4.png')
33 36
 eggc5 = PygameImage.from_filepath(getcwd()+'/intelligine/display/pygame/image/egg_c5.png')
34 37
 eggc7 = PygameImage.from_filepath(getcwd()+'/intelligine/display/pygame/image/egg_c7.png')
35
-
36
-
37
-from intelligine.synergy.object.ant.PheromonExploration import PheromonExploration
38
-from intelligine.synergy.object.ant.PheromonHome import PheromonHome
39 38
 phee = PygameImage.from_filepath(getcwd()+'/intelligine/display/pygame/image/phee.png')
40 39
 pheh = PygameImage.from_filepath(getcwd()+'/intelligine/display/pygame/image/pheh.png')
41
-dir_phee = DirectionnedImage(phee)
42
-dir_pheh = DirectionnedImage(pheh)
43
-
44 40
 
45 41
 directions_ant = DirectionnedImage(ant)
46 42
 directions_red_ant = DirectionnedImage(red_ant)
47 43
 directions_blue_ant = DirectionnedImage(blue_ant)
48 44
 directions_green_ant = DirectionnedImage(green_ant)
49 45
 
50
-def phee_direction(phee, context):
51
-    return dir_phee.get_for_direction(phee.get_direction())
52
-
53
-def pheh_direction(pheh, context):
54
-    return dir_pheh.get_for_direction(pheh.get_direction())
55
-
56 46
 def bug_direction(bug, context):
57 47
     if bug.get_life_points() <= 0:
58 48
         return dead_ant
@@ -111,6 +101,16 @@ visualisation = {
111 101
     'callbacks': {
112 102
         'position': for_position
113 103
     },
104
+    'surfaces': {
105
+        SURFACE_PHEROMONE_EXPLORATION: {
106
+            'default': phee,
107
+            'callbacks': []
108
+        },
109
+        SURFACE_PHEROMONE_HOME: {
110
+            'default': pheh,
111
+            'callbacks': []
112
+        },
113
+    },
114 114
     'objects': {
115 115
         RedAnt: {
116 116
             'default': red_ant,
@@ -143,14 +143,6 @@ visualisation = {
143 143
         },
144 144
         Hole: {
145 145
             'default': hole
146
-        },
147
-        PheromonExploration: {
148
-            'default': phee,
149
-            'callbacks': [phee_direction]
150
-        },
151
-        PheromonHome: {
152
-            'default': pheh,
153
-            'callbacks': [pheh_direction]
154
-        },
146
+        }
155 147
     }
156 148
 }

+ 0 - 15
intelligine/synergy/object/ant/Pheromon.py View File

@@ -1,15 +0,0 @@
1
-from xyzworld.SynergyObject import SynergyObject as XyzSynergyObject
2
-
3
-
4
-# TODO: ne doit plus exister. Il est la pour le display uniquement. (pheromones ne sont pas des entites)
5
-class Pheromon(XyzSynergyObject):
6
-
7
-    def __init__(self, collection, context):
8
-        super().__init__(collection, context)
9
-        self._direction = None
10
-
11
-    def set_direction(self, direction):
12
-        self._direction = direction
13
-
14
-    def get_direction(self):
15
-        return self._direction

+ 0 - 6
intelligine/synergy/object/ant/PheromonExploration.py View File

@@ -1,6 +0,0 @@
1
-from intelligine.synergy.object.ant.Pheromon import Pheromon
2
-
3
-
4
-# TODO: ne doit plus exister. Il est la pour le display uniquement. (pheromones ne sont pas des entites)
5
-class PheromonExploration(Pheromon):
6
-    pass

+ 0 - 6
intelligine/synergy/object/ant/PheromonHome.py View File

@@ -1,6 +0,0 @@
1
-from intelligine.synergy.object.ant.Pheromon import Pheromon
2
-
3
-
4
-# TODO: ne doit plus exister. Il est la pour le display uniquement. (pheromones ne sont pas des entites)
5
-class PheromonHome(Pheromon):
6
-    pass