Bastien Sevajol 7 年之前
父節點
當前提交
34efd06395

+ 0 - 1
sandbox/tiledstrategy/gui/base.py 查看文件

25
             if x % 2:
25
             if x % 2:
26
                 man.do(Animate(ANIMATION_WALK, 10, 4))
26
                 man.do(Animate(ANIMATION_WALK, 10, 4))
27
             else:
27
             else:
28
-                # TODO: Problème de zone selectable, elle reste a la taille de image debout.
29
                 man.do(Animate(ANIMATION_CRAWL, 20, 4))
28
                 man.do(Animate(ANIMATION_CRAWL, 20, 4))

+ 11 - 5
synergine2_cocos2d/actor.py 查看文件

7
 from cocos import collision_model
7
 from cocos import collision_model
8
 from cocos import euclid
8
 from cocos import euclid
9
 from synergine2_cocos2d.animation import AnimatedInterface
9
 from synergine2_cocos2d.animation import AnimatedInterface
10
+from synergine2_cocos2d.layer import LayerManager
10
 
11
 
11
 
12
 
12
 class Actor(AnimatedInterface, cocos.sprite.Sprite):
13
 class Actor(AnimatedInterface, cocos.sprite.Sprite):
34
             anchor,
35
             anchor,
35
             **kwargs
36
             **kwargs
36
         )
37
         )
37
-        self.cshape = collision_model.AARectShape(
38
-            euclid.Vector2(0.0, 0.0),
39
-            self.width,
40
-            self.height,
41
-        )
38
+        self.cshape = None  # type: collision_model.AARectShape
39
+        self.update_cshape()
42
         self.build_animation_images()
40
         self.build_animation_images()
43
         self.current_image = image
41
         self.current_image = image
42
+        self.need_update_cshape = False
43
+
44
+    def update_cshape(self) -> None:
45
+        self.cshape = collision_model.AARectShape(
46
+            euclid.Vector2(self.position[0], self.position[1]),
47
+            self.width // 2,
48
+            self.height // 2,
49
+        )
44
 
50
 
45
     def update_position(self, new_position: euclid.Vector2) -> None:
51
     def update_position(self, new_position: euclid.Vector2) -> None:
46
         self.position = new_position
52
         self.position = new_position

+ 13 - 0
synergine2_cocos2d/animation.py 查看文件

39
         self.current_step = 0  # typ: int
39
         self.current_step = 0  # typ: int
40
         self.target = typing.cast(AnimatedInterface, self.target)
40
         self.target = typing.cast(AnimatedInterface, self.target)
41
         self.direction = direction
41
         self.direction = direction
42
+        self.reshape = False
42
 
43
 
43
     def __reversed__(self):
44
     def __reversed__(self):
44
         return self.__class__(
45
         return self.__class__(
48
             self.direction * -1,
49
             self.direction * -1,
49
         )
50
         )
50
 
51
 
52
+    def set_need_to_reshape(self) -> None:
53
+        # TODO: Maybe inanimate_image is not the more appropriate image to refer ?
54
+        inanimate_image = self.target.get_inanimate_image()
55
+        for position, animation_image in enumerate(self.animation_images):
56
+            if animation_image.width != inanimate_image.width or animation_image.height != inanimate_image.height:
57
+                self.reshape = True
58
+                return
59
+
51
     def start(self):
60
     def start(self):
52
         super().start()
61
         super().start()
53
         self.animation_images = self.target.get_images_for_animation(self.animation_name)
62
         self.animation_images = self.target.get_images_for_animation(self.animation_name)
54
         self.step_interval = self.cycle_duration / len(self.animation_images)
63
         self.step_interval = self.cycle_duration / len(self.animation_images)
64
+        self.set_need_to_reshape()
55
 
65
 
56
     def stop(self):
66
     def stop(self):
57
         self.target.update_image(self.target.get_inanimate_image())
67
         self.target.update_image(self.target.get_inanimate_image())
71
         self.target.update_image(new_image)
81
         self.target.update_image(new_image)
72
         self.last_step_elapsed = self._elapsed
82
         self.last_step_elapsed = self._elapsed
73
 
83
 
84
+        if self.reshape:
85
+            self.target.need_update_cshape = True
86
+
74
     def is_time_for_new_image(self) -> bool:
87
     def is_time_for_new_image(self) -> bool:
75
         return self._elapsed - self.last_step_elapsed >= self.step_interval
88
         return self._elapsed - self.last_step_elapsed >= self.step_interval

+ 19 - 0
synergine2_cocos2d/gui.py 查看文件

15
 from synergine2.log import SynergineLogger
15
 from synergine2.log import SynergineLogger
16
 from synergine2.terminals import Terminal
16
 from synergine2.terminals import Terminal
17
 from synergine2.terminals import TerminalPackage
17
 from synergine2.terminals import TerminalPackage
18
+from synergine2_cocos2d.actor import Actor
18
 from synergine2_cocos2d.layer import LayerManager
19
 from synergine2_cocos2d.layer import LayerManager
19
 from synergine2_cocos2d.middleware import TMXMiddleware
20
 from synergine2_cocos2d.middleware import TMXMiddleware
20
 
21
 
199
         )
200
         )
200
 
201
 
201
         self.schedule(self.update)
202
         self.schedule(self.update)
203
+        self.selectable_actors = []
204
+
205
+    def set_selectable(self, actor: Actor) -> None:
206
+        self.selectable_actors.append(actor)
207
+        self.collision_manager.add(actor)
208
+
209
+    def unset_selectable(self, actor: Actor) -> None:
210
+        self.selectable_actors.remove(actor)
211
+        self.collision_manager.remove_tricky(actor)
212
+
213
+    def draw(self, *args, **kwargs) -> None:
214
+        for actor in self.selectable_actors:
215
+            if actor.need_update_cshape:
216
+                if self.collision_manager.knows(actor):
217
+                    self.collision_manager.remove_tricky(actor)
218
+                    actor.update_cshape()
219
+                    self.collision_manager.add(actor)
220
+                    actor.need_update_cshape = False
202
 
221
 
203
     def on_enter(self):
222
     def on_enter(self):
204
         super(EditLayer, self).on_enter()
223
         super(EditLayer, self).on_enter()

+ 2 - 2
synergine2_cocos2d/layer.py 查看文件

101
         self.subject_layer.remove(subject)
101
         self.subject_layer.remove(subject)
102
 
102
 
103
     def set_selectable(self, subject: 'Actor') -> None:
103
     def set_selectable(self, subject: 'Actor') -> None:
104
-        self.edit_layer.collision_manager.add(subject)
104
+        self.edit_layer.set_selectable(subject)
105
 
105
 
106
     def unset_selectable(self, subject: 'Actor') -> None:
106
     def unset_selectable(self, subject: 'Actor') -> None:
107
-        self.edit_layer.collision_manager.remove_tricky(subject)
107
+        self.edit_layer.unset_selectable(subject)