Browse Source

implement crawl

Bastien Sevajol 7 years ago
parent
commit
3622cfde45

+ 1 - 0
sandbox/tile/config.yaml View File

7
     move:
7
     move:
8
         walk_ref_time: 3
8
         walk_ref_time: 3
9
         run_ref_time: 1
9
         run_ref_time: 1
10
+        crawl_ref_time: 10

+ 7 - 6
sandbox/tile/gui/actor.py View File

4
 from synergine2.simulation import Subject
4
 from synergine2.simulation import Subject
5
 from synergine2_cocos2d.actor import Actor
5
 from synergine2_cocos2d.actor import Actor
6
 from synergine2_cocos2d.animation import ANIMATION_WALK
6
 from synergine2_cocos2d.animation import ANIMATION_WALK
7
+from synergine2_cocos2d.animation import ANIMATION_CRAWL
7
 
8
 
8
 
9
 
9
 class Man(Actor):
10
 class Man(Actor):
18
             'actors/man_w6.png',
19
             'actors/man_w6.png',
19
             'actors/man_w7.png',
20
             'actors/man_w7.png',
20
         ],
21
         ],
21
-        # ANIMATION_CRAWL: [
22
-        #     'actors/man_c1.png',
23
-        #     'actors/man_c2.png',
24
-        #     'actors/man_c3.png',
25
-        #     'actors/man_c4.png',
26
-        # ]
22
+        ANIMATION_CRAWL: [
23
+            'actors/man_c1.png',
24
+            'actors/man_c2.png',
25
+            'actors/man_c3.png',
26
+            'actors/man_c4.png',
27
+        ]
27
     }
28
     }
28
 
29
 
29
     def __init__(self, subject: Subject) -> None:
30
     def __init__(self, subject: Subject) -> None:

+ 2 - 0
sandbox/tile/gui/base.py View File

2
 from synergine2_cocos2d.gui import TMXGui
2
 from synergine2_cocos2d.gui import TMXGui
3
 from synergine2_cocos2d.interaction import MoveActorInteraction
3
 from synergine2_cocos2d.interaction import MoveActorInteraction
4
 from synergine2_cocos2d.interaction import MoveFastActorInteraction
4
 from synergine2_cocos2d.interaction import MoveFastActorInteraction
5
+from synergine2_cocos2d.interaction import MoveCrawlActorInteraction
5
 
6
 
6
 
7
 
7
 class Game(TMXGui):
8
 class Game(TMXGui):
8
     def before_run(self) -> None:
9
     def before_run(self) -> None:
9
         self.layer_manager.interaction_manager.register(MoveActorInteraction, self.layer_manager)
10
         self.layer_manager.interaction_manager.register(MoveActorInteraction, self.layer_manager)
10
         self.layer_manager.interaction_manager.register(MoveFastActorInteraction, self.layer_manager)
11
         self.layer_manager.interaction_manager.register(MoveFastActorInteraction, self.layer_manager)
12
+        self.layer_manager.interaction_manager.register(MoveCrawlActorInteraction, self.layer_manager)
11
 
13
 
12
         # Test
14
         # Test
13
         # from sandbox.tile.gui.actor import Man
15
         # from sandbox.tile.gui.actor import Man

+ 8 - 1
synergine2_cocos2d/gui.py View File

18
 from synergine2.terminals import TerminalPackage
18
 from synergine2.terminals import TerminalPackage
19
 from synergine2_cocos2d.actions import MoveTo
19
 from synergine2_cocos2d.actions import MoveTo
20
 from synergine2_cocos2d.actor import Actor
20
 from synergine2_cocos2d.actor import Actor
21
-from synergine2_cocos2d.animation import Animate
21
+from synergine2_cocos2d.animation import Animate, ANIMATION_CRAWL
22
 from synergine2_cocos2d.animation import ANIMATION_WALK
22
 from synergine2_cocos2d.animation import ANIMATION_WALK
23
 from synergine2_cocos2d.exception import InteractionNotFound
23
 from synergine2_cocos2d.exception import InteractionNotFound
24
 from synergine2_cocos2d.exception import OuterWorldPosition
24
 from synergine2_cocos2d.exception import OuterWorldPosition
400
                 self.user_action_pending = UserAction.ORDER_MOVE
400
                 self.user_action_pending = UserAction.ORDER_MOVE
401
             if k == key.R:
401
             if k == key.R:
402
                 self.user_action_pending = UserAction.ORDER_MOVE_FAST
402
                 self.user_action_pending = UserAction.ORDER_MOVE_FAST
403
+            if k == key.C:
404
+                self.user_action_pending = UserAction.ORDER_MOVE_CRAWL
403
 
405
 
404
         if k in binds:
406
         if k in binds:
405
             self.buttons[binds[k]] = 1
407
             self.buttons[binds[k]] = 1
761
         # configs
763
         # configs
762
         self.move_duration_ref = float(self.config.resolve('game.move.walk_ref_time'))
764
         self.move_duration_ref = float(self.config.resolve('game.move.walk_ref_time'))
763
         self.move_fast_duration_ref = float(self.config.resolve('game.move.run_ref_time'))
765
         self.move_fast_duration_ref = float(self.config.resolve('game.move.run_ref_time'))
766
+        self.move_crawl_duration_ref = float(self.config.resolve('game.move.crawl_ref_time'))
764
 
767
 
765
     def get_layer_middleware(self) -> MapMiddleware:
768
     def get_layer_middleware(self) -> MapMiddleware:
766
         return TMXMiddleware(
769
         return TMXMiddleware(
801
             animation = ANIMATION_WALK
804
             animation = ANIMATION_WALK
802
             cycle_duration = 0.5
805
             cycle_duration = 0.5
803
             move_duration = self.move_fast_duration_ref
806
             move_duration = self.move_fast_duration_ref
807
+        elif event.gui_action == UserAction.ORDER_MOVE_CRAWL:
808
+            animation = ANIMATION_CRAWL
809
+            cycle_duration = 2
810
+            move_duration = self.move_crawl_duration_ref
804
         else:
811
         else:
805
             raise NotImplementedError()
812
             raise NotImplementedError()
806
 
813
 

+ 5 - 0
synergine2_cocos2d/interaction.py View File

117
 class MoveFastActorInteraction(BaseMoveActorInteraction):
117
 class MoveFastActorInteraction(BaseMoveActorInteraction):
118
     gui_action = UserAction.ORDER_MOVE_FAST
118
     gui_action = UserAction.ORDER_MOVE_FAST
119
     color = (72, 244, 66)
119
     color = (72, 244, 66)
120
+
121
+
122
+class MoveCrawlActorInteraction(BaseMoveActorInteraction):
123
+    gui_action = UserAction.ORDER_MOVE_CRAWL
124
+    color = (235, 244, 66)

+ 1 - 0
synergine2_cocos2d/user_action.py View File

5
 class UserAction(Enum):
5
 class UserAction(Enum):
6
     ORDER_MOVE = 'ORDER_MOVE'
6
     ORDER_MOVE = 'ORDER_MOVE'
7
     ORDER_MOVE_FAST = 'ORDER_MOVE_FAST'
7
     ORDER_MOVE_FAST = 'ORDER_MOVE_FAST'
8
+    ORDER_MOVE_CRAWL = 'ORDER_MOVE_CRAWL'

+ 3 - 0
synergine2_xyz/move.py View File

181
         super().__init__(config, simulation, subject)
181
         super().__init__(config, simulation, subject)
182
         self._walk_duration = float(self.config.resolve('game.move.walk_ref_time'))
182
         self._walk_duration = float(self.config.resolve('game.move.walk_ref_time'))
183
         self._run_duration = float(self.config.resolve('game.move.run_ref_time'))
183
         self._run_duration = float(self.config.resolve('game.move.run_ref_time'))
184
+        self._crawl_duration = float(self.config.resolve('game.move.crawl_ref_time'))
184
 
185
 
185
     def run(self, data):
186
     def run(self, data):
186
         move_to_data = data[self.move_to_mechanism]
187
         move_to_data = data[self.move_to_mechanism]
202
             return time.time() - move_to_data['last_intention_time'] >= self._walk_duration
203
             return time.time() - move_to_data['last_intention_time'] >= self._walk_duration
203
         if move_to_data['gui_action'] == UserAction.ORDER_MOVE_FAST:
204
         if move_to_data['gui_action'] == UserAction.ORDER_MOVE_FAST:
204
             return time.time() - move_to_data['last_intention_time'] >= self._run_duration
205
             return time.time() - move_to_data['last_intention_time'] >= self._run_duration
206
+        if move_to_data['gui_action'] == UserAction.ORDER_MOVE_CRAWL:
207
+            return time.time() - move_to_data['last_intention_time'] >= self._crawl_duration
205
 
208
 
206
     def _is_fresh_new_step(self, move_to_data: dict) -> bool:
209
     def _is_fresh_new_step(self, move_to_data: dict) -> bool:
207
         return move_to_data['just_reach'] or move_to_data['initial']
210
         return move_to_data['just_reach'] or move_to_data['initial']