|
|
@@ -1,8 +1,10 @@
|
|
1
|
1
|
from intelligine.core.exceptions import NoPheromone
|
|
2
|
2
|
from synergine_xyz.display.Pygame import Pygame as XyzPygame
|
|
3
|
3
|
import pygame
|
|
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
|
|
|
4
|
+from intelligine.cst import PHEROMON_DIRECTION, PHEROMON_DIR_HOME, PHEROMON_DIR_EXPLO, PHEROMON_POSITIONS, POINTS_SMELL, \
|
|
|
5
|
+ POINT_SMELL, SMELL_EGG, SMELL_FOOD
|
|
|
6
|
+from intelligine.display.pygame.visualisation import SURFACE_PHEROMONE_EXPLORATION, SURFACE_PHEROMONE_HOME, \
|
|
|
7
|
+ SURFACE_SMELL_EGG, SURFACE_SMELL_FOOD
|
|
6
|
8
|
|
|
7
|
9
|
|
|
8
|
10
|
class Pygame(XyzPygame):
|
|
|
@@ -10,15 +12,23 @@ class Pygame(XyzPygame):
|
|
10
|
12
|
def __init__(self, config, context, synergy_manager):
|
|
11
|
13
|
super().__init__(config, context, synergy_manager)
|
|
12
|
14
|
self._is_display_pheromones = False
|
|
|
15
|
+ self._is_display_smells = False
|
|
13
|
16
|
|
|
14
|
17
|
def receive(self, actions_done):
|
|
15
|
18
|
super().receive(actions_done)
|
|
|
19
|
+
|
|
16
|
20
|
if self._is_display_pheromones:
|
|
17
|
21
|
pheromones_positions = self._context.metas.list.get(PHEROMON_POSITIONS,
|
|
18
|
22
|
PHEROMON_POSITIONS,
|
|
19
|
23
|
allow_empty=True)
|
|
20
|
24
|
self._display_pheromones(pheromones_positions, self._context)
|
|
21
|
25
|
|
|
|
26
|
+ if self._is_display_smells:
|
|
|
27
|
+ smell_positions = self._context.metas.list.get(POINTS_SMELL,
|
|
|
28
|
+ POINTS_SMELL,
|
|
|
29
|
+ allow_empty=True)
|
|
|
30
|
+ self._display_smells(smell_positions, self._context)
|
|
|
31
|
+
|
|
22
|
32
|
def _display_pheromones(self, pheromones_positions, context):
|
|
23
|
33
|
pheromone_exploration_surface = self._object_visualizer.get_surface(SURFACE_PHEROMONE_EXPLORATION)
|
|
24
|
34
|
pheromone_home_surface = self._object_visualizer.get_surface(SURFACE_PHEROMONE_HOME)
|
|
|
@@ -37,9 +47,17 @@ class Pygame(XyzPygame):
|
|
37
|
47
|
except NoPheromone:
|
|
38
|
48
|
pass # No pheromone here
|
|
39
|
49
|
|
|
|
50
|
+ def _display_smells(self, smell_positions, context):
|
|
|
51
|
+ smell_egg_surface = self._object_visualizer.get_surface(SURFACE_SMELL_EGG)
|
|
|
52
|
+ smell_food_surface = self._object_visualizer.get_surface(SURFACE_SMELL_FOOD)
|
|
|
53
|
+
|
|
|
54
|
+ for point in smell_positions:
|
|
|
55
|
+ point_flavour = context.metas.value.get(POINT_SMELL, point, allow_empty=True, empty_value={})
|
|
|
56
|
+ if SMELL_EGG in point_flavour:
|
|
|
57
|
+ self.draw_surface(point, smell_egg_surface)
|
|
|
58
|
+ if SMELL_FOOD in point_flavour:
|
|
|
59
|
+ self.draw_surface(point, smell_food_surface)
|
|
|
60
|
+
|
|
40
|
61
|
def _key_pressed(self, key):
|
|
41
|
|
- if key == pygame.K_p:
|
|
42
|
|
- if self._is_display_pheromones:
|
|
43
|
|
- self._is_display_pheromones = False
|
|
44
|
|
- else:
|
|
45
|
|
- self._is_display_pheromones = True
|
|
|
62
|
+ self._is_display_pheromones = key == pygame.K_p
|
|
|
63
|
+ self._is_display_smells = key == pygame.K_s
|